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 <psm...@gnu.org>          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


_______________________________________________
Help-make mailing list
Help-make@gnu.org
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to