Skip to content

Commit dacb3f5

Browse files
mnenciaNiccoloFei
andauthored
chore: improve Makefile (#12)
When the shell used for `sh` is `dash`, which is common on Debian and its derivatives, the output of the Makefile is incorrect. This patch resolves the issue by using `bash` as the shell when it's available. Additionally, I refactored the `push` target to reuse the code that executes the push command for a specific directory. Lastly, the default action when you run `make` without any arguments is now to build all the extensions. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com> Co-authored-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent 2a798f7 commit dacb3f5

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Makefile

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
.SUFFIXES:
22

3+
# Use bash if available, otherwise fall back to default shell
4+
SHELL := $(shell which bash 2>/dev/null || echo /bin/sh)
5+
36
# Find all directories containing metadata.hcl
47
FILES := $(shell find . -type f -name metadata.hcl)
58
DIRS := $(patsubst %/,%,$(patsubst ./%,%,$(dir $(FILES))))
69

7-
.PHONY: all clean check prereqs $(DIRS)
10+
ifeq ($(DIRS),)
11+
$(error No subdirectories with metadata.hcl files found)
12+
endif
13+
14+
# Create push targets for each directory
15+
PUSH_TARGETS := $(addprefix push-,$(DIRS))
16+
17+
.PHONY: all check prereqs push $(DIRS) $(PUSH_TARGETS)
818

919
# Colours
1020
GREEN := \033[0;32m
@@ -15,6 +25,8 @@ NC := \033[0m
1525
# Dry run flag
1626
DRY_RUN ?= false
1727

28+
default: all
29+
1830
# --------------------------
1931
# Prerequisite checks
2032
# --------------------------
@@ -32,29 +44,23 @@ prereqs:
3244
check: prereqs
3345
@echo -e "$(BLUE)Performing bake --check for all projects...$(NC)"
3446
@$(foreach dir,$(DIRS), \
35-
echo -e "$(BLUE)[CHECK] $dir$(NC)"; \
47+
echo -e "$(BLUE)[CHECK] $(dir) $(NC)"; \
3648
docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --check; \
3749
)
3850

3951
# --------------------------
4052
# Push all images
4153
# --------------------------
42-
push: all
43-
@echo -e "$(BLUE)Performing bake --push for all projects...$(NC)"
44-
@$(foreach dir,$(DIRS), \
45-
echo -e "$(BLUE)[PUSH] $dir$(NC)"; \
46-
if [ "$(DRY_RUN)" = "true" ]; then \
47-
echo -e "$(GREEN)[DRY RUN] docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --push$(NC)"; \
48-
else \
49-
docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --push; \
50-
fi; \
51-
)
54+
push: prereqs $(PUSH_TARGETS)
55+
@echo -e "$(GREEN)======================================================$(NC)"
56+
@echo -e "$(GREEN)Push successful for all projects: $(DIRS)$(NC)"
57+
@echo -e "$(GREEN)======================================================$(NC)"
5258

5359
# --------------------------
5460
# Generic per-project push
5561
# Usage: make push-<project>
5662
# --------------------------
57-
push-%: prereqs
63+
$(PUSH_TARGETS): push-%: prereqs
5864
@echo -e "$(BLUE)Performing bake --push for $*...$(NC)"
5965
ifeq ($(DRY_RUN),true)
6066
@echo -e "$(GREEN)[DRY RUN] docker buildx bake -f $*/metadata.hcl -f docker-bake.hcl --push$(NC)"

0 commit comments

Comments
 (0)