# Generic makefile for a library # Last edited on 2007-02-06 23:23:52 by stolfi ###################################################################### # To be included by the top-level Makefile in the library's directory. # The caller must define ${LIBNAME} ifneq "/${LIBNAME}" "/" # Where to install the library: INSTPUB := ../PUB INSTINC := ${INSTPUB}/include INSTLIB := ${INSTPUB}/lib # Location of Rumiko's headers: RUPUB := ../PUB RUINC := ${RUPUB}/include # Get list of sources: HFILES := ${wildcard *.h} CFILES := ${wildcard *.c} # Derived object files: HOFILES := ${subst .h,.ho,${HFILES}} OFILES := ${subst .c,.o,${CFILES}} # Library file name: LIBFILE = ${LIBNAME}.a # Make targets: .PHONY: \ depend \ all \ uninstall \ build build-lib check \ install \ clean # all: uninstall clean build install all: uninstall build install # all: build # File with dependencies between sources: DEPFILE := Deps.make # This file must be present to run "make"; # create an empty one if necessary. # Directories to search for #include files: IFLAGS := -I. -I${RUINC} #--------------------------------------------------------------------- # "make depend" recreates the source dependency file ${DEPFILE}. depend: /bin/rm -f ${DEPFILE} extract-ho-deps ${IFLAGS} -I/usr/include \ ${HFILES} ${CFILES} \ | egrep -v ': /usr/include' \ > ${DEPFILE} #--------------------------------------------------------------------- # "make build" assumes that the dependencies in ${DEPFILE} # are up-to-date. build: build-lib build-lib: ${HOFILES} ${LIBFILE} CC := /usr/bin/gcc CFLAGS := \ -ggdb -O \ -Wall -Wpointer-arith -Wmissing-prototypes \ -fpcc-struct-return %.o: %.c ${CC} -c ${CFLAGS} ${IFLAGS} ${IFLAGS} $*.c %.ho: %.h ${CC} -o $*.ho -c ${CFLAGS} ${IFLAGS} ${IFLAGS} -x c $*.h \ || /bin/rm -f $*.ho ${LIBFILE}: ${OFILES} -rm -f $*.a ar crv $*.a ${OFILES} ranlib $*.a # Include specific dependencies extracted by "make depend" include ${DEPFILE} #--------------------------------------------------------------------- # "make install" copies program and makefile to the public dir. install: ${HFILES} ${HOFILES} ${LIBFILE} cp -p ${HFILES} ${INSTINC} cp ${HOFILES} ${INSTINC} cp -p ${LIBFILE} ${INSTLIB} #--------------------------------------------------------------------- # "make uninstall" deletes the exported program and makefile: uninstall: ( cd ${INSTINC} && rm -f ${HFILES} ${HOFILES} ) ( cd ${INSTLIB} && rm -f ${LIBFILE} ) #--------------------------------------------------------------------- # "make archive" creates a tarball of sources and library: TARGZ := ${LIBNAME}.tgz archive: tar -cvzf ${TARGZ} \ 00-README Makefile \ ${LIBFILE} \ ${HFILES} ${CFILES} #--------------------------------------------------------------------- # "make check" runs the tests in the "tests" subdirectory. TESTDIR := tests check: cd ${TESTDIR} && ${MAKE} all #--------------------------------------------------------------------- # "make clean" deletes all derived files. clean: -/bin/rm -f *.o *.ho *.a core endif # End of ${LIBNAME} section. ######################################################################