[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $< won't work
From: |
Paul D. Smith |
Subject: |
Re: $< won't work |
Date: |
Sat, 27 Jul 2002 01:38:28 -0400 |
%% Dave <address@hidden> writes:
d> # "touch foo.c bar.c baz.c" before testing
d> OBJ = foo.o bar.o baz.o
d> all: $(OBJ)
d> $(OBJ):
d> @echo $@ $<
d> Under NetBSD's make(1), the above Makefile prints the following:
d> foo.o foo.c
d> bar.o bar.c
d> baz.o baz.c
d> But with GNU make(1), I get this:
d> foo.o
d> bar.o
d> baz.o
d> Xmame (http://x.mame.net) requires GNU make(1) to compile and uses
d> $< in various places. $< works just fine there. What am I doing
d> wrong?
You're relying (or rather, the Xmame makefiles are relying) on
non-portable make features.
See the GNU make manual section on "Missing Features and
Incompatibilities", specifically this section:
* In some Unix `make's, implicit rule search (*note Using Implicit
Rules: Implicit Rules.) is apparently done for _all_ targets, not
just those without commands. This means you can do:
foo.o:
cc -c foo.c
and Unix `make' will intuit that `foo.o' depends on `foo.c'.
We feel that such usage is broken. The prerequisite properties of
`make' are well-defined (for GNU `make', at least), and doing such
a thing simply does not fit the model.
In short, the Xmame makefile is expecting make to perform implicit rule
searches _even if you give it an actual command script_, which is
bizarre and not portable.
Since you gave it a command script, GNU make does not perform implicit
rule searches, so it never finds an implicit rule saying that .o is
built from .c, and thus there is no prerequisites for the .o files
except those that you explicitly provide, and since you don't provide
any the value of $< (and $^, etc.) will be empty.
d> Sidenote: How about implementing local variables like .ALLSRC,
d> .TARGET, and so on? (see *BSD make(1) manpage).
I don't have a copy of this manpage. Is it available on the web?
d> Someone posted a while ago about pursuading the FreeBSD people to
d> implement $> (a form which is implemented in NetBSD's make(1) but
d> not recommended).
This is trivial to work around in GNU make; if your makefiles require it
just add a:
> = ^
to your makefile, or in some "portability" makefile you include with the
MAKEFILES environment variable or something.
--
-------------------------------------------------------------------------------
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
- $< won't work, Dave, 2002/07/23
- Re: $< won't work,
Paul D. Smith <=