[net.unix-wizards] make questions

mcdaniel@uiucdcsb.CS.UIUC.EDU (02/15/86)

(1) Is "The Fourth Generation Make" publicly available?  If not, will
it be soon?

(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.)

------------------

Tim McDaniel; CSRD at the Silicon Prairie
(Center for Supercomputing Research and Development at the University
of Illinois at Urbana-Champaign)

Internet: mcdaniel@uicsrd.csrd.uiuc.edu
(Or try: mcdaniel%uicsrd.csrd@uiuc.edu)
Arpa, for old mailers: mcdaniel@Uiuc.arpa
Usenet: ...{pur-ee|ihnp4|convex}!uiucdcs!mcdaniel

jmc@ptsfa.UUCP (Jerry Carlin) (02/19/86)

In article <14900040@uiucdcsb> mcdaniel@uiucdcsb.CS.UIUC.EDU writes:
>(1) Is "The Fourth Generation Make" publicly available?  If not, will
>it be soon?
>
It is available thru the AT&T Toolchest (201) 522-6900 login as guest
for further info.
-- 
voice= 415 823-2441
uucp={ihnp4,dual,qantel}!ptsfa!jmc

rossc@metro.oz (Ross Cartlidge) (02/19/86)

In article <14900040@uiucdcsb> mcdaniel@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)

jph@houxf.UUCP (J.HARKINS) (02/20/86)

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