Reputation: 24778
Consider this very simple makefile:
foo: bar/
Running GNU Make 3.81 on this makefile results in:
make: *** No rule to make target `bar', needed by `foo'. Stop.
As we can see, the trailing /
is removed from bar/
.
Alternatively, using the --print-data-base
or -p
option to print the rules resulting from processing this makefile:
$ make -p 2>/dev/null | grep foo:
foo: bar
We can see that the trailing slash is removed from the original bar/
. This issue, however, is not present in newer versions of GNU Make (e.g., 4.2.1).
How can I preserve the trailing slash in the name of a rule's prerequisites in GNU Make 3.81?
Upvotes: 2
Views: 148
Reputation: 5962
Plain trailing /
doesn't seem to be possible, but maybe bar/.
will help you? It would require to rewrite all directory targets to include the trailing /.
_empty :=
_space := $(_empty) $(_empty)
.PHONY: bar bar/.
bar bar/.:
@echo "$@ -> $(dir $@)"
foo: bar/
foo_quoted: "bar/ "
foo_space: bar/$(_space)
foo_space_quoted: "bar/$(_space)"
BAR = "bar/ "
foo_var: $(BAR)
BAR_DIR = bar/
foo_dir: $(dir $(BAR_DIR))
BAR_SPACE = bar/$(_space)
foo_var_space: $(BAR_SPACE)
foo_dot: bar/.
foo_double: bar//
All other attempts will look for bar
, i.e. GNU make strips the trailing /
when processing the dependencies either during parsing or execution. The foo_dot
example on the other hand results in
$ ./make --version
GNU Make 3.81
...
$ ./make foo_dot
bar/. -> bar/
$ make --version
GNU Make 4.2.1
...
$ make foo_dot
bar/. -> bar/
Upvotes: 3