help with make needed

Root Boy Jim rbj at dsys.icst.nbs.gov
Tue May 2 03:43:06 AEST 1989


? From: Svante Lindahl <zap at front.se>

? I have a makefile in a directory were I keep the source files for a
? library. The makefile compiles a source file if it is newer than the
? corresponding archive member, replaces the archive member and deletes
? the newly compiled object file. In make notation:

? TARGET  = libfoo.a
? OBJECTS = $(TARGET)(a0.o) $(TARGET)(a1.o)

?  .c.a:
? 	$(CC) $(CFLAGS) -c $<
? 	ar rv $@ $*.o
? 	rm -f $*.o

? $(TARGET):	$(OBJECTS)
? 		ranlib $@

? (The .c.a rule is default in the make I use, but I am showing it here
? for clarity).
? This works fine, but there is one more thing I'd like to do; If the
? makefile is newer than the library, the library should be deleted and
? rebuilt from scratch. I can do this, by changing the last part of the
? makefile like this:

? $(TARGET):	Makefile $(OBJECTS)
? 		ranlib $@

? Makefile:	FRC
? 		- at if newer Makefile $(TARGET) ; then rm -f $(TARGET); fi

? FRC:

How about a double colon rule?

$(TARGET)::	Makefile
		rm -f $@

$(TARGET)::	$(OBJECTS)
		ranlib $@

Note: I have not tested this. I also don't believe in using the
construct "foo.a(bar.o)", but I suppose that's a personal aversion.

? Thanks,
? Svante.Lindahl at front.se	    (!-net: ...!uunet!front.se!svante)
? 			    (non-mx: Svante.Lindahl%front.se at uunet.uu.net)

	Root Boy Jim is what I am
	Are you what you are or what?



More information about the Comp.unix.questions mailing list