I am facing what to seem to be a bug in Gnu make, since at least make
3.82, and still present in 4.2.1.
Consider the following Makefile
--
FILES := cat cat.sh
prefix := /foo
INSTALLED_FILES := $(patsubst %,$(prefix)/%,$(FILES))
all: $(INSTALLED_FILES)
$(INSTALLED_FILES): $(prefix)/% : %
@echo $@
--
Both cat and cat.shfiles exist, and cat.sh is newer than cat (if not,
the issue does not appear).
$ make -C test
make: Entering directory `/work1/jreybert/tmp/make_bug/test'
cat cat.sh >cat
chmod a+x cat
/foo/cat
/foo/cat.sh
make: Leaving directory `/work1/jreybert/tmp/make_bug/test'
======== Golden =========
golden/cat: GIF image data, version 89a, 350 x 204
golden/cat.sh: a /usr/bin/env bash script, ASCII text executable
======== Test =========
test/cat: a /usr/bin/env bash script, ASCII text executable
test/cat.sh: a /usr/bin/env bash script, ASCII text executable
I can see that make overwrites cat
> cat cat.sh >cat
> chmod a+x cat
I also noticed that the bug appears only if cat.sh is newer that cat.
I believe that my Makefile is well written, but I may be wrong.
Adding .SUFFIXES: or calling make -r fixes my issue.
You can easily clone and test the test case here:
https://gitlab.com/jreybert/make_sccs_bug
Regards
Jérôme Reybert