[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

additional prerequisites change behaviour unexpectedly

From: Christoph Schulz
Subject: additional prerequisites change behaviour unexpectedly
Date: Wed, 11 Feb 2004 09:43:29 +0100


I have a problem with using implicit rules and additional
prerequisites. Consider following makefile:


test: test.o
   $(CC) -o test test.o

%.o: %.c
 $(CC) -c -o $@ $<

make knows how to build test.o due to given implicit rule.
If there is no (implicit) rule to be chosen, make generates
an error message like "no rule to make target 'test.o',
needed by 'test'". E.g. this can be the case if test.c
does not exist. So far, so good.

Now consider you have a header file which test.c depends on.
Normally, you put the prerequisites into rules without
commands. If we insert the rule

test.o: test.h

in the example above, however, there is a problem whenever
no rule for building test.o is appropriate: If, for instance,
test.c does not exist, make considers test.o *to be successfully
built* and starts to execute the first test rule, leading
to an error message of gcc ("test.o: No such file or directory").
Note that make does not generate an error message like the above
one, because the manual states:

  If a rule has no prerequisites or commands, and the target
  of the rule is a nonexistent file, then make imagines this
  target to have been updated whenever its rule is run.

Because this is disturbing and leads to different behaviour,
dependent on the fact whether targets have additional
prerequisites or not, here my question: Is there any
possibility to add prerequisites to a target *without*
allowing rules to be executed whose prerequisites do
not exist?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]