help-make
[Top][All Lists]
Advanced

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

Re: is this a feature or a bug?


From: Paul Smith
Subject: Re: is this a feature or a bug?
Date: Tue, 23 Nov 2010 16:23:20 -0500

On Tue, 2010-11-23 at 13:02 -0800, James Sarrett wrote:
> What is surprising is that it seems to be inconsistent with my test
> cases when I was trying to figure out what was going on.  Give the
> Makefile I originally tried (the one without the wildcard function) it
> will do *some* expansion, somehow.  I'm attaching a tarball of a
> directory with 3 files, the Makefile and 2 xrc files.  If you run
> 'make' even with no _xrc.py files, it will generate the first one
> correctly, but no others.  I can't figure out how this happens if the
> wildcard expansion isn't supposed to take place until the rule, since
> as you correctly point out, no such files exist.

This happens because of the magic of the shell.

As with the shell, and as described in the GNU make manual, if a
wildcard pattern doesn't match any files then the result is NOT the
empty string; rather it's the wildcard itself.

So if you say "ls foo*bar" and you have no files that match "foo*bar",
you don't get a listing of your entire directory (because "foo*bar"
matched nothing and expanded to the empty string, so you ran "ls").
Instead you get an error "foo*bar: no such file or directory" or
similar, because "foo*bar" matched nothing so the shell left it alone
and passed "foo*bar" to "ls".

Similarly, in make if the wildcard doesn't match anything then it is
used verbatim.

So, in your case you have:

        all: *_xrc.py

The wildcard doesn't match anything, so now make wants to build a file
literally named "*_xrc.py".

Well, make knows how to do that!  Using the pattern:

%_xrc.py: %.xrc
      pywxrc -pv $<

make knows it can build "*_xrc.py" from "*.xrc".  To do this it will run
the rule: "pywxrc -pv $<" which expands to "pywxrc -pv *.xrc".  So make
runs that in the shell.  If you look at the output line make prints it
should be clear: you'll see that command with the wildcard rather than a
filename.

And, the shell helpfully notices that *.xrc is a wildcard and the SHELL
expands that, and then invokes the pywxrc program with the arguments
"-pv Console.xrc StarMeasure.xrc".

And that's how you get your results.




reply via email to

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