bin/61527: make -j2 changes $*
Ruslan Ermilov
ru at freebsd.org
Sun Jan 18 06:40:27 PST 2004
The following reply was made to PR bin/61527; it has been noted by GNATS.
From: Ruslan Ermilov <ru at freebsd.org>
To: Albert Hofkamp <a.t.hofkamp at tue.nl>
Cc: freebsd-gnats-submit at freebsd.org
Subject: Re: bin/61527: make -j2 changes $*
Date: Sun, 18 Jan 2004 16:35:15 +0200
On Sun, Jan 18, 2004 at 06:03:41AM -0800, Albert Hofkamp wrote:
>
> with a make rule like
>
> foo/bar.o: foo/bar.cc
> echo CC -o $*.o $<
>
> (and an existing foo/bar.cc
> 'make' ouputs 'CC -o foo/bar.o foo/bar.cc' while
> 'make -j2' outputs 'CC -o bar.o foo/bar.cc', ie the target misses the directory part in parallel make
>
The results will be even more surprising (at a glance) if you try
this with ``make -r'' and ``make -r -j2''. This is because you're
misusing the inference rules in sys.mk and ${.PREFIX} (aka $*) and
${.IMPSRC} (aka $<) macros which are defined only for inference rules.
The corrected makefile would look like this:
: foo/bar.o: foo/bar.cc
: @echo CC -o $@ $>
or better yet:
: foo/bar.o: foo/bar.cc
: @echo CC -o ${.TARGET} ${.ALLSRC}
which gives the same results in all four make(1) invocations.
But please be aware that ${.ALLSRC} is dangerous because once
you create a .depend file, there might be a dependency of the
form ``bar.o: bar.h'' in it, and bar.h will become part of
${.ALLSRC}. So the safe version would look like this:
: foo/bar.o: foo/bar.cc
: @echo CC -o ${.TARGET} foo/bar.cc
If you need lot of such rules, you may start using the inference rule:
: $ cat Makefile
: .SUFFIXES: .cc .o
: .cc.o:
: @echo CC -o ${.TARGET} ${.IMPSRC}
: $ make foo/bar.o
: CC -o foo/bar.o foo/bar.cc
: $ make -j2 foo/bar.o
: CC -o foo/bar.o foo/bar.cc
: $ make -r foo/bar.o
: CC -o foo/bar.o foo/bar.cc
: $ make -r -j2 foo/bar.o
: CC -o foo/bar.o foo/bar.cc
Cheers,
--
Ruslan Ermilov
FreeBSD committer
ru at FreeBSD.org
More information about the freebsd-bugs
mailing list