Help with setting up makefile & program libraries
USENET News
news at oberon.USC.EDU
Fri Feb 3 08:25:40 AEST 1989
I'm having quite a bit of trouble setting up a makefile. I guess I'm
just not understanding its operation that well. Anyway here is my tale:
I want to create a program library and have my programs link to it each
time. Let's say the library file name is proglib, and proglib contains
2 files lib1.o lib2.o. The dependencies are as follows:
foobar: foobar.c proglib
proglib: lib1.c lib2.c header.h
lib1.o: lib1.c header.h
lib2.o: lib2.c header.h
The reason why I don't have the line
proglib: lib1.o lib2.o
(Those 2 files are what proglib consists of) is because I would like the
lib1.o, lib2.o files to be deleted after they've been gathered into the
library, to save disk space). Thus, the only time that proglib should
be recompiled occurs when changes have been made to any of it's dependent
files lib1.c,lib2.c and header.h (since lib1.c & lib2.c depend on that).
Now, in Sys V UNIX, I've seen makefiles accomplish everything that I've
specified with the simple line:
library: proglib(lib1.o) proglib(lib2.o)
So the resulting makefile is a short and sweet
foobar: $$@ library
$(CC) $@.c proglib -o $@
library: proglib(lib1.o) proglib(lib2.o)
lib1.o lib2.o: header.h
Indeed, I would be satisfied doing it that way were it not for the fact
that I'm working in BSD flavored SUN UNIX, so after creating a library
via
ar rv proglib lib1.o lib2.o
I have to run
ranlib proglib
One quick and dirty fix I thought of (which doesn't work) is to try
foobar: $$@ dummylibrary
$(CC) $@.c proglib -o $@
dummylibrary: lib1.c lib2.c header.h
sh -c "make library;\
ranlib proglib"
library: proglib(lib1.o) proglib(lib2.o)
lib1.o lib2.o: header.h
(As you can see, I also don't really understand how the shell interacts
with make. I believe that if I had simple left the entry as
dummylibrary: lib1.c lib2.c header.h
make library
ranlib proglib
make complains about "Unexpected End of File" or something.)
Anyway, rather than keep peddling my ignorance, can someone please set me
straight, and show me how to set up the makefile properly? Also, if you
would, please explain to me why my clumsy attempts are unsuccessful.
Daniel
dwu at nunki.usc.edu
More information about the Comp.unix.questions
mailing list