Make and RCS
Brent W. Baccala
baccala at eng.umd.edu
Sun May 5 15:35:37 AEST 1991
First, I don't read these newsgroups, so don't followup if you want me
to see it. Second, I'm posting an answer to my own question and don't
really expect any replys. Somebody's probably done this before, but
I've never heard of it, and I'm posting in the hope that you might
find this useful.
Basically, I wanted Make and RCS (you could use SCCS just as easily)
to co-exist nicely. I also wanted to define "nicely" in my own terms.
RCS files should stay in an RCS subdirectory; I only check out the
ones I'm changing. I'm the only person working on the project, so I
don't need to worry about unlocked files being altered. When I run
make, I don't want it to clutter up my directory with all the source
files; I just want it to re-compile those that I've changed and link
with stored objects from other files to build the executable.
A normal .c -> .o -> exec chain won't work because make will end up
either complaining about non-existant .c files or using a default rule
to check 'em all out from RCS. I've broken the chain with an archive.
The exec depends on it like this:
mst: mst.a
$(CC) -o mst $(CFLAGS) mst.a $(LIBS)
The trick is to only rebuild the parts of mst.a that you need, leave
the unchanged members alone, then compile from the archive. Building
the archive isn't trivial, but let me know if you find a simpler way
than mine:
mst.a: $(CFILES)
@for file in $? ; do \
make `basename $$file .c`.o ; \
echo ar r mst.a `basename $$file .c`.o ; \
ar r mst.a `basename $$file .c`.o ; \
rm `basename $$file .c`.o ; \
done
ranlib mst.a
CFILES is a make variable that must be set to the source files
existing in the directory at the time of the make. You can't just use
"*.c", because if none exist, Bourne shell leave the wildcard alone
and make tries to build a file called "*.c". "test" isn't quite
powerful enough to overcome thing. Fortunately, we've got a fairly
rich environment here that includes Sun make and perl, so CFILES is:
CFILES:sh = perl -e '$,=" "; print <*.c>,"\n"'
This sets CFILES to a list of all .c files, or nothing if none exist.
If you only want certain .c files considered, it shouldn't be too
hard. Of course, I have a default rule to do a check-out, in case
include files are needed for the source I do change.
An enhancement I don't have now, but plan to add as soon as I need it
is a check in the mst.a rule for existance of the mst.a file. If it
isn't there, check out all the source files you don't have, recompile
everything, then delete the source code checked out (leaving the files
that were already there). This lets you quickly switch to a different
development track by deleting mst.a, switching the default RCS branch
to whatever, and running make.
As always, suggestions and comments and (expecially) improvements are
welcome.
--
-bwb
Brent W. Baccala
baccala at eng.umd.edu
More information about the Comp.unix.wizards
mailing list