help-make
[Top][All Lists]
Advanced

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

Re: trouble with $(wildcard)


From: Paul D. Smith
Subject: Re: trouble with $(wildcard)
Date: Mon, 8 Oct 2001 18:03:49 -0400

%% Steve James <address@hidden> writes:

  sj> Given this makefile:

  sj> all: setup
  sj>         @echo wildcard value is $(wildcard xxx)
  sj> setup:
  sj>         @mkdir -p xxx

  sj> I find that the $(wildcard xxx) evals to nothing if directory
  sj> "xxx" does not exist before invoking make.  This surprises me.
  sj> When are the variables in a target's rules expanded, before making
  sj> prerequisites or after?  I would have assumed after.

This is because GNU make caches the contents of directories, for speed
purposes.

When you have a rule that builds something other than what it says it
builds (here, the "setup" rule builds the directory "xxx", which make
doesn't know about) then the cache is not updated correctly and things
like $(wildcard ...) return the wrong values.


This is not a good way to make directories anyway; it's very error
prone.

If you want to be sure that a directory exists you should do it like
this:

  __dummy := $(shell [ -d xxx ] || mkdir -p xxx)

This will be invoked every time the makefile is parsed, regardless of
what arguments you give to make.

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