[Top][All Lists]

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

Re: define variable in rule

From: John Graham-Cumming
Subject: Re: define variable in rule
Date: Wed, 08 Jun 2005 13:42:18 -0400

On Wed, 2005-06-08 at 23:54 +0800, address@hidden wrote:
> Can the variable be defined in rule ? Like this:
> 1 target :  $(OBJ_FILE)
> 2     TMP_LIB := $(shell cat $(OBJ_FILES))
> 3     $(LD) $(OPT_LD_STD) $(LDFLAGS) -o $@   $(TMP_LIB)
> The OBJ_FILE is a text file with .o file list, and I want to translate
> it to .o list used as the argument of link, so the variable TMP_LIB is
> defined. 
> But when do Make, syntax error found in line 3. So I doubt the variable
> can not be defined within a fule.

Not like that it can't, but you could do this:

target: TMP_LIB := $(shell cat $(OBJ_FILES))
        $(LD) $(OPT_LD_STD) $(LDFLAGS) -o $@   $(TMP_LIB) \

(This has the side effect of defining TMP_LIB for any of target's

OTOH I don't see any real need for that TMP_LIB variable here (unless
it's being referenced in one of the other variables on the $(LD)
command-line) and so you could simplify your life greatly and just do:

        $(LD) $(OPT_LD_STD) $(LDFLAGS) -o $@ $(shell cat $(OBJ_FILES)) \

If you do that then you don't even need to bother with the $(shell)
because you could just use backticks and do

        $(LD) $(OPT_LD_STD) $(LDFLAGS) -o $@ `cat $(OBJ_FILES)` \

John Graham-Cumming

GNU Make Standard Library:

reply via email to

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