Make variables and shell variables

Joe Beckenbach joe at cit-vax.Caltech.Edu
Thu Nov 3 08:56:52 AEST 1988


Okay, all you make wizards out there, a rather silly question:
	How can I use shell variables to affect make variables?

	The intended use is to allow multiple selections of multiple
compilers in one makefile. Eg, I've got program1, program2, and program3,
with compiler1, compiler2; the behavior wanted is:
	make program1 compiler2 program2 compiler1 program3
where the makefile is:
------------
#	Hypothetical makefile for multiple compiler usage
#	Different compilers (1 is default for makes)
compiler1:
	CC=cc
compiler2:
	CC=mycc
#	Different programs to be made
program1: $(includes1) $(sources1)

program2: $(includes2) $(sources2)

program3: $(includes3) $(sources3)

------------

	Alas, it appears that make not only imposes its aliases before passing
the line onward to the execution shell [thus making make variables effectively
read-only, overlaid, environment variables invisible to the shell], but also
make appears to spawn off a new execution shell for each line [thus making
additions to the environment impossible]! Try this:
-------------
#	Intent: print "ping\nping"
pong:
	eval PUNG=ping ; echo $$PUNG
	echo $$PUNG
-------------
this-vax% make pong
eval PUNG=ping ; echo $PUNG
ping
echo $PUNG

this-vax% _
---------------

	Several alternatives present themselves that would allow for the same
overall effect. Firstly, maintain parallel make files. Secondly, have the
makefile adjust itself by using sed, then doing another make. Thirdly, have
the makefile adjust a copy of itself and make using the copy. There are others,
but none seem as elegant as letting the make variables and environment 
variables interact....
	.... which can be done by making new defaults which ignore make's
predefined aliases. But this is even more work than maintaining parallel
copies.

	Any good ideas, aside from changes to make?
	And commentary on extending make to carry on environment variables,
conditional changing of make aliases, and such? [We've already been through 
the $SHELL/$MAKESHELL discussions.]

-- 
Joe Beckenbach	joe at csvax.caltech.edu	Caltech 256-80, Pasadena CA 91125
	... or have I not seen enough code yet to throw stones? 1/2 :-)



More information about the Comp.unix.wizards mailing list