[Top][All Lists]

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

Re: Why isn't $@ expanded to the target?

From: Paul Smith
Subject: Re: Why isn't $@ expanded to the target?
Date: Thu, 16 Oct 2008 00:31:06 -0400

On Thu, 2008-10-16 at 11:49 +0800, Pan ruochen wrote:
> subdir = $(subdir_z)
> TARGET = /home/reach/proj/$(subdir)
> $(TARGET):
>         @echo $(TARGET) $@
> define get_dir
> $1 = release
> endef
> $(eval $(call get_dir,subdir_z))

> $make
>  /home/reach/proj/release  /home/reach/proj

> The variable $@ and TARGET are not expanded to the same string. How
> does this happen?

Look up the section "How make reads a makefile" in the GNU make manual.

The $(TARGET) in the target list is expanded immediately as the makefile
is read in, and in that situation "subdir_z" has not been set yet, so
$(TARGET) expands to /home/reach/proj and so the value of $@ will
be /home/reach/proj.

The $(TARGET) in the recipe is not expanded until after the entire
makefile is read in, and make starts to run rules--by that time subdir_z
has been set to the value "release" so $(TARGET) here
is /home/reach/proj/release.

 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]