Skip to content

Commit 923b072

Browse files
committed
Remove the leading > in recipe command
After introducing parameters <p1:v1,...>, doing $(VAR:>=) to remove the leaving > in a recipe command is only possible if we make sure that after the closing > there is no space (see the comments about "at the end of a word" in section 6.3.1 Substitution References of the GNU Make manual. This is very brittle. Furthermore, while starting the command line with > seems clear, it is a disaster waiting to happen because making the "wrong" echo might redirect to something important. This commit also removes a comment I made about RECIPE_COMMAND_LINE -- which was wrong (on som any levels).
1 parent 567ad61 commit 923b072

21 files changed

Lines changed: 34 additions & 28 deletions

Makefile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
SHELL := bash
22
TEST_DIR := test
3-
TEST_RECIPES := $(TEST_DIR)/recipes
3+
TEST_RECIPES_DIR := $(TEST_DIR)/recipes
44

5-
TESTS := $(notdir $(wildcard $(TEST_RECIPES)/*))
5+
TESTS := $(notdir $(wildcard $(TEST_RECIPES_DIR)/*))
66

77
## if set, debug info is generated in an org file
88
DEBUG :=
@@ -91,21 +91,26 @@ release:
9191

9292
## Recipes:
9393
## ---------
94-
$(TESTS): RECIPE_COMMAND_LINE = $(shell head -n 1 $(TEST_RECIPES)/$@)
95-
$(TESTS): CMD_RECIPE_EXPECTED = tail -n +2 $(TEST_RECIPES)/$@
96-
$(TESTS): CMD_RESULT = $< -f makefile-doc.awk $(RECIPE_COMMAND_LINE:>=)
94+
$(TESTS): RECIPE_COMMAND_LINE = $(shell head -n 1 $(TEST_RECIPES_DIR)/$@)
95+
$(TESTS): CMD_RECIPE_EXPECTED = tail -n +2 $(TEST_RECIPES_DIR)/$@
96+
$(TESTS): CMD_RESULT = $< -f makefile-doc.awk $(RECIPE_COMMAND_LINE)
9797
# --ignore-space-at-eol is needed as empty descriptions add OFFSET
9898
$(TESTS): CMD_DIFF = git diff --ignore-space-at-eol \
9999
<($(CMD_RECIPE_EXPECTED)) \
100100
<($(CMD_RESULT))
101101
$(TESTS): TMP_FILE = /tmp/$@_updated
102102
$(TESTS): $(AWK_BIN)/$(AWK)
103-
# I cannot use RECIPE_COMMAND_LINE here because it is a recursively expanded variable
104-
# and its value might contain e.g., $(TARGET) which Make will try to expand further
103+
# The reason for using echo "$(subst $,\$,$(RECIPE_COMMAND_LINE))" is that, the value of
104+
# RECIPE_COMMAND_LINE may contain e.g., $(TARGET) and we need to make sure that the
105+
# shell doesn't try to expand it. Unfortunately, we cannot simply use echo
106+
# '$(RECIPE_COMMAND_LINE)' because the value of RECIPE_COMMAND_LINE already contains
107+
# single quotes. While it doesn't contain doble-quotes, doing echo
108+
# "$(RECIPE_COMMAND_LINE)" is not possible because the single quotes around $(TARGET)
109+
# loose their "powers" when surrounded by double-quotes. So we have to escape the $.
105110
@$(if $(UPDATE_RECIPE),\
106-
head -n 1 $(TEST_RECIPES)/$@ > $(TMP_FILE);\
111+
echo "$(subst $,\$,$(RECIPE_COMMAND_LINE))" > $(TMP_FILE);\
107112
$(CMD_RESULT)\
108-
| tee -a $(TMP_FILE) && mv $(TMP_FILE) $(TEST_RECIPES)/$@,\
113+
| tee -a $(TMP_FILE) && mv $(TMP_FILE) $(TEST_RECIPES_DIR)/$@,\
109114
$(CMD_DIFF) || (echo "failed $@"; exit 1) && echo "[$(notdir $<)] passed $@")
110115

111116
# ----------------------------------------------------

makefile-doc.awk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ function print_help() {
640640
printf " DEPRECATED ([bool] show deprecated anchors): %s\n", DEPRECATED
641641
printf " OFFSET (offset of docs from anchors): %s\n", OFFSET
642642
printf " CONNECTED (ignore docs followed by an empty line): %s\n", CONNECTED
643+
printf " COLOR_ENCODING: %s\n", COLOR_ENCODING
643644
printf " COLOR_: "
644645
printf "%sDEFAULT%s, ", COLOR_DEFAULT_CODE, COLOR_RESET_CODE
645646
printf "%sATTENTION%s, ", COLOR_ATTENTION_CODE, COLOR_RESET_CODE

test/recipes/test-backticks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> -v COLOR_BACKTICKS=1 test/Makefile.inc
1+
-v COLOR_BACKTICKS=1 test/Makefile.inc
22
-----------------------
33
Available targets:
44
-----------------------

test/recipes/test-connected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> -v CONNECTED=0 test/Makefile.inc
1+
-v CONNECTED=0 test/Makefile.inc
22
-----------------------
33
Available targets:
44
-----------------------

test/recipes/test-default

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> test/Makefile test/Makefile.inc
1+
test/Makefile test/Makefile.inc
22
[test/Makefile] redefined docs of target: test-3
33
[test/Makefile] redefined docs of target: test-14
44
[test/Makefile.inc] redefined docs of target: test-10

test/recipes/test-deprecated

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> -v DEPRECATED=0 test/Makefile.inc
1+
-v DEPRECATED=0 test/Makefile.inc
22
-----------------------
33
Available targets:
44
-----------------------

test/recipes/test-double-colon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> test/Makefile.targets-2
1+
test/Makefile.targets-2
22
-----------------------
33
Available targets:
44
-----------------------

test/recipes/test-grouped

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> test/Makefile.targets-3
1+
test/Makefile.targets-3
22
-----------------------
33
Available targets:
44
-----------------------

test/recipes/test-html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> -v COLOR_ENCODING=html test/Makefile
1+
-v COLOR_ENCODING=html test/Makefile
22
<span class="ansi35">[test/Makefile] redefined docs of target: test-3</span>
33
<span class="ansi35">[test/Makefile] redefined docs of target: test-14</span>
44
<head>

test/recipes/test-no-anchors

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
> -v VARS=0 test/Makefile.vars-2
1+
-v VARS=0 test/Makefile.vars-2
22
There are no documented targets/variables in test/Makefile.vars-2

0 commit comments

Comments
 (0)