help-make
[Top][All Lists]
Advanced

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

Re: define variable in rule


From: Paul D. Smith
Subject: Re: define variable in rule
Date: Wed, 8 Jun 2005 12:08:24 -0400

%% <address@hidden> writes:

  n> Can the variable be defined in rule ? Like this:

  n> 1 target :  $(OBJ_FILE)
  n> 2  TMP_LIB := $(shell cat $(OBJ_FILES))
  n> 3  $(LD) $(OPT_LD_STD) $(LDFLAGS) -o $@ $(TMP_LIB) $(EXTERNAL_LIBS) 
$(SYSTEM_LIBS) 

  n> The OBJ_FILE is a text file with .o file list, and I want to translate
  n> it to .o list used as the argument of link, so the variable TMP_LIB is
  n> defined. 

Why don't you just use:

  target :  $(OBJ_FILE)
        $(LD) $(OPT_LD_STD) $(LDFLAGS) -o $@ `cat $(OBJ_FILES)` 
$(EXTERNAL_LIBS) $(SYSTEM_LIBS)

?

  n> But when do Make, syntax error found in line 3. So I doubt the
  n> variable can not be defined within a fule.

You cannot, generally, define variables within rules, no.  The entire
content of the line after the TAB character is variable-expanded, then
passed to the shell.  So, these lines must be shell commands not make
commands.


If you have a sufficiently recent version of GNU make and are willing to
require that, you can use the $(eval ...) function inside a rule to
define a variable.

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