help-make
[Top][All Lists]
Advanced

[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: Paul Smith
Subject: Re: Refer to basename of current target (like with $* in MS NMake)
Date: Sat, 14 Jan 2012 09:15:57 -0500

On Sat, 2012-01-14 at 13:58 +0100, Michael Ludwig wrote:
> How can you refer to the current target't basename and path in GNU Make?
> 
> EmployeeTest.exe: EmployeeTest.o Employee.o
>       $(LINK.cc) $^ -o $@
> DatabaseTest.exe: DatabaseTest.o Employee.o Database.o
>       $(LINK.cc) $^ -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
                $(LINK.cc) $^ -o $@
        EmployeeTest.exe: Employee.o
        DatabaseTest.exe: Employee.o Database.o

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