make questions

Ross Cartlidge rossc at metro.oz
Wed Feb 19 16:15:18 AEST 1986


In article <14900040 at uiucdcsb> mcdaniel at uiucdcsb.CS.UIUC.EDU writes:
>(2) A friend would like to perform the following task
>
>	for each *.c file younger than gen.a
>		cc -c -g that file
>	ar ruv gen.a *.o
>	ranlib gen.a
>	rm *.o
>
>He has a shell script of about 15 lines; I'd like to see if it can be
>done in make (BSD 4.2).  Is it possible, easy and efficient, or is it
>better to use the shell script?  (Notes:  there are about 500 .c files,
>and more may be added later:  the makefile should not have to be edited
>just for more source files, and make variable storage may overflow.
>Only .o files for newly-edited .c files will exist, and then only for a
>few moments.)
The makefile below will maintain a directory of .c files used to create
a archive. I can only see it failing if $(OBJS) is larger than 5120
characters. So as long as average namelength is less than 10 you should
be ok. Also the algorithm described above will not compile .c's which
are older than gen.a but newer than gen.a(~.c)

PS.	This was tested on Sys V.2 - whats the 'u' option on ar?

LIB=gen.a
CFLAGS=-g
all:
	@$(MAKE) OBJS="`ls *.c | sed 's/\(.*\).c/$(LIB)(\1.o)/'`" $(LIB)
$(LIB):	$(OBJS)
	ranlib $(LIB)



More information about the Comp.unix.wizards mailing list