Bug with SCCS Suffix Rules

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug with SCCS Suffix Rules

Jerome Reybert
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

Reply | Threaded
Open this post in threaded view
|

Re: Bug with SCCS Suffix Rules

Paul Smith-20
On Wed, 2020-02-19 at 17:56 +0100, Jerome Reybert wrote:
> 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.

I'm not sure why your subject mentions SCCS suffix rules, but there is a
built-in rule that knows how to convert from a foo.sh to foo, like this
(from "make -p -f/dev/null"):

  %: %.sh
  #  recipe to execute (built-in):
          cat $< >$@
           chmod a+x $@

that's what you're seeing.  As far as I remember this has nothing to do
with SCCS though.  If you don't want this rule, you can delete it via:

  %: %.sh

(no recipe).  See
https://www.gnu.org/software/make/manual/html_node/Canceling-Rules.html

Or of course you can use "-r" to remove ALL implicit rules, if you prefer.