help-make
[Top][All Lists]
Advanced

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

Re: unexpected behaviour with match anything rule


From: Britton Kerin
Subject: Re: unexpected behaviour with match anything rule
Date: Thu, 15 Nov 2012 11:08:06 -0900

 On Wed, Nov 14, 2012 at 10:37 PM, Warlich, Christof
 <address@hidden> wrote:
>> I think this is correct behavior.  Why do you think the rules for the 'all'
>> target should not be executed?  The else part states that all targets 
>> matching
>> % depend on all, so its rules get run first.
>
> I'm just puzzled because of the _different_ behaviour in ifeq- and else 
> clause:
> They only differ in that the match anything rule of the ifeq clause has no
> dependency, while the match anything rule in the else clause depends on "all".
> And due to that difference, only the recipe for the specific rule for target
> t1 is executed in the ifeq clause (ok! :-)), while both the recipes for the 
> specific
> _and_ the match anything rules are executed for the else clause (why? :-().

The match-anything clause is being executed for the 'all' target, because all
matches it.  The match-anything clause is not being executed for t1 or t2.
So this behavior is as expected, its the Makefile that is pathological.

> The following, slightly modified example makes my point even clearer.
> Furthermore, it shows that something is going wrong with putting the right
> target into $@:
>
> t1: ; @echo 'specific rule for target $@'
> ifeq (,$(UNEXPECTED))
>    %: ; @echo 'expected match anything rule for target $@'
> else
>    %: all ; @echo 'unexpected match anything rule target address@hidden - $$@ 
> should contain $(MAKECMDGOALS)!'
> endif
> all: ; @echo 'rule for target $@'

This is actually quite a different case: here you have a specific target
for all, so the match-everything patter rule won't match it.  Unfortunately,
according to section 3.5 of the manual:

     Sometimes makefiles can be remade from other files, such as RCS or SCCS
     files. If a makefile can be remade from other files, you probably want
     make to get an up-to-date version of the makefile to read in.

     To this end, after reading in all makefiles, make will consider each as
     a goal target and attempt to update it. If a makefile has a rule which
     says how to update it (found either in that very makefile or in another
     one) or if an implicit rule applies to it (see Using Implicit Rules),
     it will be updated if necessary

Match-everything rules are really prone to problems of this sort.  The -d
flag will give you a big pile of output that will tell you whats going on
if you can stand wading though it.

Really its better to just not use implicit rules.  Compute the set of targets
you want your rules to apply to with $(patsubst %.c,%.o,$(wildcard *.c))
or so and use a static pattern rule.  It makes it easier to get the correct set
of files, and make is more likely to give you a useful error message when
things go wrong.

Britton



reply via email to

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