help-make
[Top][All Lists]
Advanced

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

Can I defer make-var expansion until a command is executed


From: Chen Jun (陈军)
Subject: Can I defer make-var expansion until a command is executed
Date: Mon, 04 Aug 2008 11:10:49 +0800
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)


Look at this makefile.

====

IsFileExist = $(shell if [ -f $1 ]; then echo 1; fi )

outfile = out.txt

$(outfile):
        @echo "STRT: $@ $(if $(call IsFileExist,$@),exist,absent)"
        @touch $@
        @echo "DONE: $@ $(if $(call IsFileExist,$@),exist,absent)"

====

When outfile does not exist and we make it, make outputs

------

STRT: out.txt absent
DONE: out.txt absent

------

So we know all make-vars are expanded for all commands in a rule before the first command of that rule is really executed. But if I really like the example makefile to output

-------

STRT: out.txt absent
DONE: out.txt exist

-------

How can I do it? I know I can add another rule to accomplish that, e.g.

==========

IsFileExist = $(shell if [ -f $1 ]; then echo 1; fi )

outfile = out.txt

all: $(outfile)
        @echo "DONE: $(outfile) $(if $(call 
IsFileExist,$(outfile)),exist,absent)"

$(outfile):
        @echo "STRT: $@ $(if $(call IsFileExist,$@),exist,absent)"
        @touch $@


==========

But that complicates the makefile. Is there a way that I can do it with only one rule?

Thank you in advance.

Attachment: chenjun.vcf
Description: Vcard


reply via email to

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