help-make
[Top][All Lists]
Advanced

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

Re: Automatically generate rules from a list variable


From: Mike Shal
Subject: Re: Automatically generate rules from a list variable
Date: Fri, 24 Oct 2008 12:51:03 -0400

On 10/24/08, Greg Chicares <address@hidden> wrote:
> On 2008-10-24 16:13Z, Andrei Deftu wrote:
>  > On Fri, Oct 24, 2008 at 6:51 PM, Paul Smith <address@hidden> wrote:
>  >> Why can't youjust use a normal pattern rule?  Something like:
>  >>
>  >>        %.cpp_o : %.cpp
>  >>                # bla bla
>  >>
>  >> ?
>  >
>  > Thanks but this rule matches every .cpp_o files and I want it to match
>  > only the files from LIST.
>  > e.g.:
>  >
>  > LIST1 := file1.cpp file2.cpp file3.cpp
>  > LIST2 := file4.cpp file5.cpp file6.cpp
>  >
>  > and I want the files from LIST1 to be built using one rule and the
>  > ones from LIST2 using other rule. Then, your solution does not work.
>
>
> How does the rule vary--can you parameterize it?
>
>  For example, if it varies only by $(CXXFLAGS):
>
>  $(LIST1): CXXFLAGS := flags1
>  $(LIST2): CXXFLAGS := flags2
>
>  %.cpp_o : %.cpp
>         $(CXX) $(CXXFLAGS) $< -o$@
>

Or you could use static patterns:
LIST1 := file1.cpp file2.cpp file3.cpp
LIST2 := file4.cpp file5.cpp file6.cpp

LIST1_o := $(LIST1:.cpp=.o)
LIST2_o := $(LIST2:.cpp=.o)

all: $(LIST1_o) $(LIST2_o)

$(LIST1_o): %.o: %.cpp
        @echo "From list 1: gcc $< -o $@"
$(LIST2_o): %.o: %.cpp
        @echo "From list 2: gcc $< -o $@"

$ make
>From list 1: gcc file1.cpp -o file1.o
>From list 1: gcc file2.cpp -o file2.o
>From list 1: gcc file3.cpp -o file3.o
>From list 2: gcc file4.cpp -o file4.o
>From list 2: gcc file5.cpp -o file5.o
>From list 2: gcc file6.cpp -o file6.o

-Mike




reply via email to

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