Tue 22 Sep 2009 03:08:01 PM UTC, original submission:
I have a collection of files, %.a and %.b, and I want to generate %.c from them. If %.b exists, I want %.c to depend on %.a and %.b, and otherwise I want %.c to depend on only %.a. I do this:
all : foo.c
%.c :: %.a %.b
echo %.a %.b > $@
touch $@
%.c :: %.a
echo %.a > $@
This works fine (except that if %.b is deleted, %.c isn't rebuilt):
$ touch foo.a
$ make
echo %.a > foo.c
$ touch foo.b
$ make
echo %.a %.b > foo.c
$
However, if I reverse the order of the rules:
all : foo.c
%.c :: %.a
echo %.a > $@
%.c :: %.a %.b
echo %.a %.b > $@
touch $@
Then it no longer works:
$ touch foo.a
$ make
echo %.a > foo.c
$ touch foo.b
$ make
make: Nothing to be done for `all'.
$
Now, the first rule hasn't fired and updated foo.c, and the second rule says foo.c is not up-to-date, so the second rule's actions should be run, but they aren't.
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-redhat-linux-gnu
|