DEV: makefile: fix POSIX compatibility for "range" target
make "range" which was introduced with 06d34d4 ("DEV: makefile: add a
new "range" target to iteratively build all commits") does not work with
POSIX shells (namely: bourne shell), and will fail with this kind of
errors:
|/bin/sh: 6: Syntax error: "(" unexpected (expecting ")")
|make: *** [Makefile:1226: range] Error 2
This is because arrays and arithmetic expressions which are used for the
"range" target are not supported by sh (unlike bash and other "modern"
interpreters).
However the make "all" target already complies with POSIX, so in this
commit we try to make "range" target POSIX compliant to ensure that the
makefile works as expected on systems where make uses /bin/sh as default
intepreter and where /bin/sh points to POSIX shell.
(cherry picked from commit 3b4d2b797534779c8e77a30d48d02984c37a18d6)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 1e3dacb538026fe5341e1a60ba21998ba1481ca2)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 72f6423fff2e0cc2b7b2b9635d2faf26e258d281)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit dd56f16f37473eaabe537aa440ef6d6932642817)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/Makefile b/Makefile
index 1e065ac..f8fb2d2 100644
--- a/Makefile
+++ b/Makefile
@@ -1172,17 +1172,17 @@
BRANCH=$$(git branch --show-current HEAD 2>/dev/null); \
[ -n "$$BRANCH" ] || { echo "Fatal: \"make $@\" may only be used inside a checked out branch."; exit 1; }; \
[ -z "$${RANGE##*..*}" ] || RANGE="master..$${RANGE}"; \
- COMMITS=( $$(git rev-list --abbrev-commit --reverse "$${RANGE}") ); \
- index=1; count=$${#COMMITS[@]}; \
+ COMMITS=$$(git rev-list --abbrev-commit --reverse "$${RANGE}"); \
+ index=1; count=$$(echo $$COMMITS | wc -w); \
[ "$${count}" -gt 0 ] || { echo "## Fatal: no commit(s) found in range $${RANGE}."; exit 1; }; \
echo "Found $${count} commit(s) in range $${RANGE}." ; \
echo "Current branch is $$BRANCH"; \
echo "Starting to building now..."; \
- for commit in $${COMMITS[@]}; do \
+ for commit in $$COMMITS; do \
echo "[ $$index/$$count ] $$commit #############################"; \
git checkout -q $$commit || die 1; \
$(MAKE) all || die 1; \
- ((index++)); \
+ index=$$((index + 1)); \
done; \
echo;echo "Done! $${count} commit(s) built successfully for RANGE $${RANGE}" ; \
git checkout -q "$$BRANCH"; \