[Top][All Lists]

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

Re: Action as a prerequisite

From: Paul D. Smith
Subject: Re: Action as a prerequisite
Date: Tue, 9 Aug 2005 20:59:47 -0400

%% lists <address@hidden> writes:

  l> I have a number of sources that I wish to compile into executables. 
  l> They can all be processed as:

  l> file1: file1.o
  l>    $(CXX) -o $@ $(STUFF) $<

  l> I tried to automate this for files 1-9 by:

  l> EXEC_SRCS := ...
  l> EXECS := $(

  l> $(EXECS): $(addsuffix .o,$@)
  l>    $(CXX) -o $@ $(STUFF) $<

You can't use $@ in the prerequisite list.  The target and prerequisites
are expanded immediately as the file is read, but the automatic
variables like $@, $<, etc. are not available until later, when the
command script is being invoked.

See the GNU make manual section on how expansion works.

  l> Why doesn't this work?  Is there a way to automate a list of files like 
  l> this?  I understand I could probably give all the executable files an 
  l> extension like .t and then use a pattern substitution to process them 
  l> all.  Any way to do this without a special extension?

Why would you need an extension?  If there's no extension, just use:

    % : %.o

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "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]