[comp.unix.questions] Defining macros as the "method" for updating a file using Make.

sbanner1@uvicctr.UUCP (S. John Banner) (08/04/87)

   Hello,

   I am trying to get make to do some updating of about 20 different
programs, using the same makefile.  All of the files are updated in
exactly the same way, except that 3 of the files are different,
depending on which program I want to make.  What I have done is
something like this:

OBJS	=	first.o second.o third.o ... last.o
XFILE	=	defx.o
YFILE	=	defy.o
ZFILE	=	defz.o
TARGET	=	def.out

link:	${OBJS} ${XFILE} ${YFILE} ${ZFILE}
	cp ${XFILE} x.o
	cp ${YFILE} y.o
	cp ${ZFILE} z.o
	ld -ldflags ${OBJS} ${XFILE} ${YFILE} ${ZFILE} -o ${TARGET}
	rm -f x.o
	rm -f y.o
	rm -f z.o

file1:	xxxfile1 link
xxxfile1:
	XFILE	=	xfile1.o
	YFILE	=	yfile1.o
	ZFILE	=	zfile1.o
	TARGET	=	file1

file2:	xxxfile2 link
xxxfile2:
	XFILE	=	xfile2.o
	YFILE	=	yfile2.o
	ZFILE	=	zfile2.o
	TARGET	=	file2

# and a whole bunch more...

I know that macros have to start in col 1, and that the lines to 
execute after a dependancy have to start with a tab.  I would just
use a command line macro, but that is not so easy, as the actual
filenames are kind of bizzare, and hard to remember.

    Does anyone out there have any suggestions?  Can this even be
done like this, or do I have to arrange it so that make will get
invoked with the appropriate macros defined as command line arguments?

On a similar note, a question I have always wondered about, that I
haven't seen an answer for in the manuals, if I have a command line
macro, and a the same macro defined in the make file, which takes
precidence?  And finally, while I am here, can I depend on the lines
like:  "file2:	xxxfile link" to always be dealt with in the order
given on the dependancy line?  I know that it works on all the machines
that I have tried it on (Sun 3/280, Pyr 90x, Vax 780 (all with
BSD 4.2/4.3, or thier equivalents), and NDMAKE on the PC), but can I
depend on this behaviour; I don't recall seeing mention of it in
the manual either.

	    Thanks In Advance,

                      S. John Banner

...!uw-beaver!uvicctr!sol!sbanner1
...!ubc-vision!uvicctr!sol!sbanner1
ccsjb@uvvm
sbanner1@sol.UVIC.CDN