generating code to run multiple targets/configurations from single
Chris Torek
chris at mimsy.UUCP
Wed Apr 12 15:23:46 AEST 1989
4.3BSD-tahoe introduced a `#define' in <machine/machparam.h> called
MACHINE; on the VAX it is
#define MACHINE "vax"
and on the Tahoe it is
#define MACHINE "tahoe"
The program /bin/machine is made from the source (slightly trimmed)
#include <sys/machine.h>
main()
{
puts(MACHINE);
exit(0);
}
and thus produces `vax', `tahoe', or whatever.
make(1) has a built-in macro ${MACHINE} which expands to whatever
make's source got out of <machine/machparam.h>, so Makefiles can
read
# Makefile for /usr/src/etc
...
SUBDIR= ... etc.${MACHINE}
all: ${PROGS} ${SUBDIR} ...
${SUBDIR}: FRC
cd $@; make ${MFLAGS}
In addition, make reads the file `.depend' as well as the file
`Makefile' (or `makefile'), so that automatic dependency genration need
not rewrite makefiles. This is much nicer (and clearly the way it
should have been done originally).
Existing `make's can be made to do the same thing by superimposing a
front-end shell script. Here is /usr/local/bin/make from our Suns.
(`machine' is found in /usr/local/bin and says `echo sun'. This points
up a problem: `sun' is not always specific enough; some sources might
be Sun-2 specific and some might be Sun-3 specific. A simple fix would
be to make it produce `sun2' or `sun3' and make bin.sun2 and bin.sun3
symlinks to bin.sun in /usr/src/local/bin; but it might be better to
have two levels, or perhaps more.)
#! /bin/sh
if [ -f .depend ]; then
if [ -f makefile ]; then
f="-f makefile -f .depend"
else
f="-f Makefile -f .depend"
fi
for i do
case "$i" in -f*) f=;; esac
done
else
f=
fi
exec /bin/make $f ${1+"$@"} MACHINE=${MACHINE-`machine`}
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.wizards
mailing list