Date: Mon, 23 Sep 2002 17:35:16 +0200 From: Roman Neuhauser <neuhauser@bellavista.cz> To: Bruce M Simpson <bms@spc.org>, freebsd-hackers@FreeBSD.ORG Subject: Re: two make questions Message-ID: <20020923153516.GC30361@freepuppy.bellavista.cz> In-Reply-To: <20020923150811.GI23343@spc.org> References: <20020923133431.GZ30361@freepuppy.bellavista.cz> <20020923095217.O332-100000@april.chuckr.org> <20020923143523.GA30361@freepuppy.bellavista.cz> <20020923150811.GI23343@spc.org>
next in thread | previous in thread | raw e-mail | index | archive | help
# bms@spc.org / 2002-09-23 16:08:11 +0100: > On Mon, Sep 23, 2002 at 04:35:23PM +0200, Roman Neuhauser wrote: > > thanks a lot for your reply. You're right: I'm viewing Makefiles > > as sequential programs, which obviously (even to me) is not quite > > true, but I'm having difficulty getting rid of this. > > Yeah, it takes a bit of getting used to. Make lets you define a dependency > graph, and various transformations/instructions that can be applied to > each node in that graph. In that respect it's more like a Caesar salad, > the dependencies are the lettuce and the variables are croutons. Making it > work is the dressing; you have to add it yourself ;-) :) > "Managing Projects with Make" from O'Reilly is a good introduction but it's > a tad dated. yeah, i'll be ordering it shortly. > Also, make has a habit of being different from one platform to the > next. I particularly like the BSD pmake, but Solaris make is different > still, and GNU make is a law unto itself. i know. i'm limiting myself to pmake atm, so other implementations are out of the scope of my questions. > > Now, saying "don't do it" is nice, but I'd like to know why. Why > > doesn't this work? Also, what documentation (besides the source) is > > there that covers variable scopes? See the second message for the > > problem description. > > The scope of a Makefile macro (variable) seems to be limited to the current > invocation, ? see below > unless you explicitly export things as environment variables, > or set them on a command line when re-invoking Make. i'm not sure what to take of this. consider this makefile: DESTDIR= SOURCES= foo bar baz TARGETS:= ${SOURCES:C;^;${DESTDIR}/;} SRCFILE= ${.TARGET:C,^${DESTDIR}/,,} .BEGIN: @echo "\$${DESTDIR}: ${DESTDIR}" @echo "\$${TARGETS}: ${TARGETS}" all: ${TARGETS} ${TARGETS}: ${SRCFILE} @echo "SRC: ${SRCFILE} -> TGT: ${.TARGET}" .PHONY: all ${TARGETS} roman@freepuppy ~/tmp 1133:0 > make all DESTDIR=/tmp/maketest ${DESTDIR}: /tmp/maketest ${TARGETS}: /foo /bar /baz Graph cycles through /foo Graph cycles through /bar Graph cycles through /baz `all' not remade because of errors. roman@freepuppy ~/tmp 1133:0 > in the invocation above, the commandline assignment overrode the Makefile value of DESTDIR in the .BEGIN target, but not outside it (or presumably any target), in the ${TARGETS} and ${SRCFILE} macros. So: what exactly do you mean by "the current invocation"? > Depending on what you want to do this can get quite complicated. Have > a look at /usr/src/Makefile which actually reinvokes itself quite a > bit (and includes things from Makefile.inc which may *also* do that!). I've had more than a few looks in /usr/ports/Mk/bsd.port.mk, but getting the "building block" principles from something that complicated is not easy. > Nik Clayton mentioned a tool to automatically diagram makefile dependency > graphs by target at the last FreeBSD UKUG meeting, using graphviz, but I > can't recall its name. I'll google, thanks. > > I can fix the behavior with conditional assignment to DESTDIR (?=) > > in the Makefile, but still would like to understand what's causing > > make to behave the way it does. > > If you're including any standard makefile templates you may wish to > review those; as well as /etc/make.conf and /etc/defaults/make.conf. nothing like that. my Makefiles break withoug the need for this stuff. :) > You probably also want to look at the MAKEOBJDIRPREFIX behaviour in > the make(1) man page. will do so. thanks! -- begin 666 nonexistent.vbs FreeBSD 4.7-RC 5:23PM up 6 days, 38 mins, 22 users, load averages: 0.11, 0.07, 0.04 end To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020923153516.GC30361>