[mot.general] Gnu Make Question

turner@smart.sps.mot.com (Robert Turner) (11/13/90)

I have a gnu make question.  Environment:  Apollo running BSD4.3, SR10.2.
The sources are maintained in RCS.  The question is how to get gnu make to
check out an include file from RCS, perform the compile and then delete
the include file.

Sample makefile contains but a single line, below.
pgm: pgm.o pgm.h

With pgm.c and pgm.h checked into RCS, gnu make checks out pgm.c
and pgm.h.  Make compiles and links pgm.c to form pgm.  Make then
deletes pgm.c, but not pgm.h.

I have been told that make views pgm.c as a temporary file as make
had to "invent" it.  Pgm.h on the other hand is explicitly stated 
so make did not "invent" it, therefore make does not delete it.  Is it
possible to get make to delete those objects that it checks out instead
of deleting only "invented" objects?

The above example has all of the files having the same root, "pgm".  In
the real world, there are several objects and several include files.

Robert
-- 
Robert Turner (602) 897-5441 Semiconductor Systems Design Technology, Motorola
turner@dover.sps.mot.com   OR   ...!uunet!dover!turner
"Most Americans do not know or appreciate the fact that citizenship is the
primary political office under a constitutional government."  Mortimer Adler

donh@victory.oakhill.uucp (Don Horr) (11/13/90)

I have found the same thing happening with gnumake.  I.e., if it
checks a file out, the file is not erased.  I just add an "rcsclean"
to the make action to clean things up.  It removes any files which
have been checked out but not modified and leaves the modified files
alone.
--
Don Horr
SSDT
Motorola, Inc., Austin TX
(donh@victory.sps.mot.com)

donh@cs.utexas.edu (Don Horr) (11/13/90)

--text follows this line--
I have found the same thing happening with gnumake.  I.e., if it
checks a file out, the file is not erased.  I just add an "rcsclean"
to the make action to clean things up.  It removes any files which
have been checked out but not modified and leaves the modified files
alone.
--
Don Horr
SSDT
Motorola, Inc., Austin TX
(donh@victory.sps.mot.com)

abair@turbinia.sps.mot.com (Alan Bair) (11/14/90)

With any Make program, if you use the default rules, like Robert is in his
example, you have to except what the builtin action does.  One fix is what
Don suggested, add to the actions performed for the target.  A more general 
fix, is to define your own actions to perform for a rule. Here is what I 
believe the default rules to be (the make man page tells how to get the 
whole list):

.c~.o:
	$(GET) $(GFLAGS) -p $< > $*.c
	$(CC) $(CFLAGS) -c $*.c
	-rm -f $*.c

Which when make finds a file needs to be checked out (thats what the ~ means),
it does a get, compiles it, then erases the checked out file.

.h~.h:
	$(GET) $(GFLAGS) -p $< > $*.h

This is what make uses to checkout the required .h file.  There is also a
similar one for .c files.

Now, if we were to assume that you want to erase any files that are checked
out, which means they are younger than the target, the following new rule
for building .o files from .c files may work.

.c.o:
	cc $(CFLAGS) -c $<
	rm $?

This says that .o files depend on .c files and the dependent .c file, $<,
is compiled and then any dependent files younger than the target, $?, are
to be erased.  This will use the default rules to checkout .c and .h files.
I haven't tested this, just wrote it from memory and a peek at the man page,
so it could be wrong.  However, I think it will provide some ideas to try.

--
Alan Bair                 SSDT (formerly SPS CAD)
Motorola, Inc.            Logic Simulation & Test
Austin, Texas             abair@turbinia.sps.mot.com

abair@turbinia.sps.mot.com (Alan Bair) (11/14/90)

--text follows this line--
With any Make program, if you use the default rules, like Robert is in his
example, you have to except what the builtin action does.  One fix is what
Don suggested, add to the actions performed for the target.  A more general 
fix, is to define your own actions to perform for a rule. Here is what I 
believe the default rules to be (the make man page tells how to get the 
whole list):

.c~.o:
	$(GET) $(GFLAGS) -p $< > $*.c
	$(CC) $(CFLAGS) -c $*.c
	-rm -f $*.c

Which when make finds a file needs to be checked out (thats what the ~ means),
it does a get, compiles it, then erases the checked out file.

.h~.h:
	$(GET) $(GFLAGS) -p $< > $*.h

This is what make uses to checkout the required .h file.  There is also a
similar one for .c files.

Now, if we were to assume that you want to erase any files that are checked
out, which means they are younger than the target, the following new rule
for building .o files from .c files may work.

.c.o:
	cc $(CFLAGS) -c $<
	rm $?

This says that .o files depend on .c files and the dependent .c file, $<,
is compiled and then any dependent files younger than the target, $?, are
to be erased.  This will use the default rules to checkout .c and .h files.
I haven't tested this, just wrote it from memory and a peek at the man page,
so it could be wrong.  However, I think it will provide some ideas to try.

--
Alan Bair                 SSDT (formerly SPS CAD)
Motorola, Inc.            Logic Simulation & Test
Austin, Texas             abair@turbinia.sps.mot.com