List Info

Thread: HELP! $(wildcard ) function failed very strangely




HELP! $(wildcard ) function failed very strangely
user name
2007-09-30 03:54:28
 

Hi, everyone,

    I encountered a strange situation recently, $(wildard ) function seems failing to work. See my code below:

========================================================
all: first_target
outfile = out.txt
$(outfile):
  ;  echo nnn > $
.PHONY: prj_count
prj_count:
 &nbsp; &nbsp;echo "[[$(outfile)]] <<$(wildcard $(outfile))>> "

.PHONY: first_target
first_target: $(outfile) prj_count
  ; &nbsp;echo "[DONE]"
========================================================
First, delete out.txt and run make on that makefile, the output is
 
[[out.txt]] <<&gt;>
[DONE]
  
then, run make again, the output is
 
[[out.txt]] <<out.txt>&gt;
[DONE]
Result of the first run is strange. When target prj_count is being made, out.txt should have been generated on my disk(because $(outfile) had been made before), then WHY $(wildcard out.txt) gives me null result ?
 
I've tested it on make 3.80 & 3.81 on Linux, both produce the same result.
 
Thanks in advance.
 
       &nbsp; &nbsp; &nbsp;   ; &nbsp;Chen Jun (陈军)
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   mail.nlscan.com">chenjunmail.nlscan.com
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; 2007-09-30
Re: HELP! $(wildcard ) function failed very strangely
user name
2007-09-30 05:01:20
On 2007-09-30 16:54:28 (+0800), Chen Jun (????)
<chenjunmail.nlscan.com> wrote:
> Result of the first run is strange. When target
prj_count is being made,
> out.txt should have been generated on my disk(because
$(outfile) had been made
> before), then WHY $(wildcard out.txt) gives me null
result ?
The $(wildcard ) is evaluated when the rule is parsed, not
when it's
executed. At that point the out.txt file doesn't exist yet
so it doesn't
match anything.

Try something like this:

MATCH = $(wildcard out.txt)
rule: out.txt
    echo $(MATCH)

out.txt:
    touch $ 


Also note that it's a bad idea to rely on the order or your
prerequisites, as you seem to do in first_target. If make is
executed
with -j it's possible the prj_count target will be executed
before the
$(outfile) target. If prj_count requires $(outfile) to be
built it
should be listed as a prerequisite.

Regards,
Kristof


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )