Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.wizards Subject: Re: generating code to run multiple targets/configurations from single Message-ID: <16877@mimsy.UUCP> Date: 12 Apr 89 05:23:46 GMT References: <3129@stpstn.UUCP> <18927@adm.BRL.MIL> <10445@bloom-beacon.MIT.EDU> <12741@swan.ulowell.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 67 4.3BSD-tahoe introduced a `#define' in 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 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 , 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@mimsy.umd.edu Path: uunet!mimsy!chris