[Top][All Lists]

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

Re: $(wildcard) not expanding generated files

From: Johan Bezem
Subject: Re: $(wildcard) not expanding generated files
Date: Tue, 21 Jan 2003 09:11:31 +0100


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

  OBJECTS = *.o

doesn't expand the list, whereas

  OBJECTS = $(wildcard *.o)

does. $(wildcard is expanded upon the first pass over the makefile, ie. when
no rules have been executed yet; so your 'testfile' doesn't yet exist, and
$(wildcard is replaced with an empty string.
I assume you'd like to check for the existence of a file in the course of
running make, so I'd suggest you'd use the shell for that:

  if [ -f testfile ];
    echo testfile;
    echo No testfile;

(Or similar when using a shell other than bash; no optimal solution
Further comments inlined.

DervishD wrote:
>     Hi all :))
>     Don't know if this is a bug, but anyway this doesn't work and it
> should (IMHO). The problem is the function $(wildcard) not working
> properly when the argument is a generated file. Let me explain it

Define "properly" ;-)

> with an example, better. We have this tiny Makefile:
> all:
>         @touch testfile
> install: all
>         @echo $(wildcard testfile)
> clean:
>         @rm testfile
>     If we do 'make install', 'testfile' is created when the 'all'
> target is run but $(wildcard) doesn't notice, so nothing is printed.
> But if we do 'make all ; make install', the file is created and,
> since $(wildcard) gets run in the second make, it noticed the newly
> created file. Is this a bug or a feature?


> Will this undesired
> behaviour (undesired by me, at least) be solved if I replace
> $(wildcard pattern) with $(shell echo pattern)?

No, you'd probably need 'ls', 'echo' just echoes the given characters, and
uses no wildcard expansion AFAIK, depending on your shell.


$(wildcard has not been designed for the use you want from it. Let us know
what it is that you want to achieve, and we can discuss possible solutions.


Johan Bezem
CSK Software AG

reply via email to

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