help-make
[Top][All Lists]
Advanced

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

Re: Help with multiple dependencies in pattern rules


From: Paul Smith
Subject: Re: Help with multiple dependencies in pattern rules
Date: Mon, 08 Feb 2010 09:03:14 -0500

On Mon, 2010-02-08 at 14:08 +0100, Noel David Torres Taño wrote:
> I want to express in a Makefile that all *.o files must be compiled
> from their *.F95 sources, and that all *_m.o files depend on the *.o
> file (without the '_m'). This is because foo_m.F95 includes foo.F95,
> and thus if either foo{,_m}.F95 changes, the foo_m.o must be rebuilt.
> 
> I tried using
> 
> %.o : %.F95
>         $(FC) $(FFLAGS) -o $@ -c $<
> 
> %_m.o : %.F95
> 
> but the second rule seems to be ignored.

There are a number of issues here.

First, note that GNU make matches pattern rules in the order they are
defined in the makefile, so the first pattern rule, which is a strict
superset of the second one, will always match and the second one will be
ignored.  You'd need to switch the order.

Second, every pattern rule MUST have a command with it.  If a pattern
rule has no command, then it actually deletes the pattern rule; so your
second line has no effect anyway (it's deleting that pattern rule).

Both of these behaviors are described in the GNU make manual.

Third, in your description you say that "if either foo{,_m}.F95 changes,
the foo_m.o must be rebuilt" but that's not what the above rule says
even if it worked.  It says that foo_m.o depends on foo.F95, and nothing
more.

One way to do what your description says is this, although I'm not sure
I understand what you really want based on that description:

        %_m.o : %_m.F95 %.F95
                $(FC) $(FFLAGS) -o $@ -c $<
        %.o : %.F95
                $(FC) $(FFLAGS) -o $@ -c $<

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist





reply via email to

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