help-make
[Top][All Lists]
Advanced

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

Re: "targetted" pattern rules


From: Paul D. Smith
Subject: Re: "targetted" pattern rules
Date: Sat, 18 Feb 2006 12:12:20 -0500

%% Helge Avlesen <address@hidden> writes:

  ha> clearly there is a thing or two I do not understand about pattern
  ha> rules, so I would be very grateful if anyone could give a hint on
  ha> how I can achieve my goal without explicitly specifying rules for
  ha> each file...

Static pattern rules, in spite of their name, are not pattern rules.
They are simply shorthand for writing lots of explicit rules.  Thus, a
definition like this:

    foo.o bar.o baz.o biz.o : %.o : %.c
                $(CC)

is identical in every way to writing:

    foo.o : foo.c
                $(CC)
    bar.o : bar.c
                $(CC)
    biz.o : biz.c
                $(CC)
    baz.o : baz.c
                $(CC)

Therefore, you cannot use the same object file in multiple static
pattern rules, as you will be redefining the command to build "foo.o"
and make wouldn't know which one to use.


It's too bad that your makefiles list the .o files and not the source
files.  I always recommend that makefiles list the source files, then
it's trivial to convert those into .o's or whatever else you want.  If
you had source files it would be simple to extract out the .F90 vs. .F
vs. .f90 vs. .f vs. .c files and handle them properly.  As it is you
could still do it, but you'd need to combine it with $(wildcard ...) to
get the right results.


However, you can easily do what you want using pattern rules along with
target-specific variables.  Instead of static pattern rules, just use
real pattern rules:

    %.o : %.F90 ; $(F95) -c $(PFREEFLAGS$(N))  -o $@ $<
    %.o : %.F   ; $(F95) -c $(PFIXEDFLAGS$(N)) -o $@ $<
    %.o : %.f90 ; $(F95) -c $(FREEFLAGS$(N))   -o $@ $<
    %.o : %.f   ; $(F95) -c $(FIXEDFLAGS$(N))  -o $@ $<
    %.o : %.c   ; $(CC)  -c $(CFLAGS$(N))      -o $@ $<

Now, use target-specific variables to set those variables differently
for each set of targets:

    $(OBJS1) : N = 1
    $(OBJS2) : N = 2
        ...

Note you need a relatively recent version of GNU make to use this
feature.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "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]