make questions

J.HARKINS jph at houxf.UUCP
Thu Feb 20 11:42:43 AEST 1986


I think I have what you need here.  Create a "Makefile" in the desired
directory that looks like this:

--------------------------------CUT HERE-------------------------------

CFLAGS=-g
LIB=gen.a

all		:
			@echo \\nLIBOBJLST= *.c | \
			sed "s, \([^.]*\)\.c,$$(LIB)(\1.o) ,g" > temp.mk
			@$(MAKE) -f temp.mk -f Makefile library
			@rm -f temp.mk

library	:	$(LIB)
		@echo $(LIB) is up to date.

$(LIB)	:	$(LIBOBJLST)
		ranlib $(LIB)
------------------------------CUT HERE---------------------------------

Make sure you call it "Makefile", 'cause the $(MAKE) command in the all 
target will be looking for it.  If you want to call it makefile or gen.mk
or something, make sure you change the name in this line to reflect this.

The way it works is that a temporary makefile, temp.mk, is created from
a list of all the current c source files in the directory.  It is formatted
in such a way, with sed, as to tell make that the object modules the .c files
would generate are members of the library.  Make then runs itself with the new
temporary makefile and the old permanent one("Makefile").  Thus make always
has access to the current list of .c files, without having to maintain them
in the Makefile.

All you need to do is type "make" or "make all" to compile all out of date
source files, load the .o files into the library, remove the object files,
and run ranlib ONCE on the library after all .o files have been added to it.

The only output you'll see is from the compiles, the ar's and the ranlib.
If you want to watch it all fly a couple times, remove the @ signs from
in front of the commands in the "all" target, or run make with the -n option.
This will just show you everything that would get done, instead of doing it.
If you want to see what temp.mk looks like, remove the line that removes 
temp.mk from the all target.

I've been using this type of scheme for several months now, and it really makes
maintence a dream.  Incedentally, if you want to you can forget the
temporary makefile, and just pipe the output of the sed directly into the
$(MAKE) command.  Just change the first filename in the -f option of make
from temp.mk to -.

Have fun.


-------
Disclaimer: I hereby disclaim all my debts.
------

Jack Harkins @ AT&T Bell Labs
Princeton Information
(201) 949-3618
(201) 561-3370
houxf!jph



More information about the Comp.unix.wizards mailing list