[Top][All Lists]

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

Re: $(wildcard) not expanding generated files

From: Paul D. Smith
Subject: Re: $(wildcard) not expanding generated files
Date: Tue, 21 Jan 2003 10:17:45 -0500

%% "Johan Bezem" <address@hidden> writes:

  jb> this seems to be by design, to overcome the fact that

  jb>   OBJECTS = *.o

  jb> doesn't expand the list, whereas

  jb>   OBJECTS = $(wildcard *.o)

  jb> does. $(wildcard is expanded upon the first pass over the
  jb> makefile, ie. when no rules have been executed yet;

This is not true... or at least not in the above case.

The $(wildcard ...) function is expanded using exactly the same rules as
make variables and the other functions: there are _no_ special cases.

In the above example, because the variable is recursive $(wildcard *) is
_not_ expanded when that line is read.

  >> all:
  >>        @touch testfile
  >> install: all
  >>        @echo $(wildcard testfile)
  >> clean:
  >>        @rm testfile

In this makefile the $(wildcard *) function is not expanded until the
rule is run (it is _not_ expanded when the makefile is read, just like
$@ in a command script is not expanded then, etc.)

So, on the face of it this seems like it should work.  Why doesn't it
work?  It doesn't work because GNU make actually caches the contents of
directories as it reads them, for performance reasons.

Because your makefile doesn't list "testfile" explicitly as a target to
be created, make doesn't know anything about it and it doesn't add it to
the cache of the directory.  So when $(wildcard *) looks up files the
cache, the new file is not there.

If you make that file an explicit target, rather than a side-effect,
_then_ it will work.

  >> Is this a bug or a feature?

  jb> Feature.

Maybe, maybe not.  But, not as straightforward as it seems at any rate :).

There have been other issues with the directory cache so at some point
I'll have to investigate whether (a) we can change it to work better
without gutting its entire purpose (caching to avoid filesystem
lookups), or (b) introduce some syntax to disable it for those who would
rather have the above behavior than the speed increase.

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