help-make
[Top][All Lists]
Advanced

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

Re: Makefile question


From: Paul Smith
Subject: Re: Makefile question
Date: Tue, 09 Mar 2010 08:26:45 -0500

On Tue, 2010-03-09 at 10:27 +0100, Ole Amund Søvde wrote:

> I have some directories with fortran files, say
> src/fil1.f
> src/fil2.f
> src2/fil2.f
> 
> where you can see fil2.f is in both directories.
> 
> I would like to list all files I want to compile in a variable:
> SRCFILES = src/fil1.f src2/fil2.f
> 
> and compile them to a separate object directory:
> OBJFILES = tmp/fil1.o tmp/fil2.o
> 
> Whether fil2.f is compiled from src/ or src2/ should therefore be
> defined by SRCFILES.

> Hopefully, something like this would be possible:
> $(OBJFILES): $(SRCFILES)
>       @echo "Compiling $< ... $@"

That in no way says what you want.  It means the same thing as:

        src/fil1.o : src/fil1.f src2/fil2.f
                ...
        src/fil2.o : src/fil1.f src2/fil2.f
                ...

It is actually pretty tricky to do what you're asking: most of the
normal methods one would use are invalid because of the duplicated
filenames, combined with the desire to combine all objects into a single
output directory.  Offhand I can't think of a way to do it that doesn't
involve using eval.  Something like:

        define OBJRULE
        $(patsubst %.f,%.o,$(notdir $1)): $1
                @echo "Compiling $$< ... $$@"
        endef

        $(foreach SRC,$(SRCFILES),$(eval $(call OBJRULE,$(SRC)))

Note, not tested in any way.  See the GNU make manual chapter on
functions for more details.  Note you need to double the "$" in the
command script in the variable value.

-- 
-------------------------------------------------------------------------------
 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]