[Top][All Lists]

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

Re: Refer to basename of current target (like with $* in MS NMake)

From: Michael Ludwig
Subject: Re: Refer to basename of current target (like with $* in MS NMake)
Date: Sat, 14 Jan 2012 17:03:56 +0100
User-agent: Mutt/1.5.20 (2009-12-10)

Paul Smith schrieb am 14.01.2012 um 09:15 (-0500):
> On Sat, 2012-01-14 at 13:58 +0100, Michael Ludwig wrote:

> > EmployeeTest.exe: EmployeeTest.o Employee.o
> >     $( $^ -o $@
> > DatabaseTest.exe: DatabaseTest.o Employee.o Database.o
> >     $( $^ -o $@
> > 
> > EmployeeTest and DatabaseTest are redundant here, how can you avoid
> > that redundancy in specifying the rule?
> You have these choices:
>      1. Use a pattern rule
>      2. Use a static pattern rule
>      3. Set .SECONDEXPANSION and use $$* (requires newer versions of
>         make)
> You can find discussions of these in the GNU make manual.  Personally
> I would use a pattern rule; this is what they were designed for:
>       %.exe: %.o
>               $( $^ -o $@
>       EmployeeTest.exe: Employee.o
>       DatabaseTest.exe: Employee.o Database.o

This works perfectly, thank you!

$(EXPF)%.exe: %.cpp
        $(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@

I got that line LINK.cpp from running "make -p" in a directory without
a Makefile. Guess it makes sense to look at what "make -p" (without
Makefile) would do. LOADLIBES and LDLIBS are empty so could be removed

$(EXPF)EmployeeTest.exe: $(EXPF)Employee.o
$(EXPF)DatabaseTest.exe: $(EXPF)Employee.o $(EXPF)Database.o

The last one needs an explicit link rule because there is no homonymous
source file. (I could of course rename the source file to be able to
drop that rule.)

$(EXPF)EmpUI.exe: $(EXPF)Employee.o $(EXPF)Database.o $(EXPF)UserInterface.o
        $(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@

It's nice to get a lot done without coding explicit rules, just by
letting the defaults do their work and go with the flow.
Michael Ludwig

reply via email to

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