# Generic makefile for a library # Last edited on 2007-04-16 21:19:56 by stolfi ###################################################################### # To be included by the top-level Makefile in the library's directory. # The caller must define ${LIBNAME}. # The caller may defined ${IGNORE} as a list of source files # that should not be compiled or installed. ifneq "/${LIBNAME}" "/" # Where to install the library: INSTPUB := ${HOME}/PUB INSTINC := ${INSTPUB}/include INSTLIB := ${INSTPUB}/${PLATFORM}/lib # Location of Stolfi's headers: JSPUB := ${HOME}/PUB JSINC := ${JSPUB}/include # Get list of sources: HFILES := ${filter-out Makefile ${IGNORE}, ${shell shopt -s nullglob; ls *.h Makefile}} CFILES := ${filter-out Makefile ${IGNORE}, ${shell shopt -s nullglob; ls *.c Makefile}} # 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-hos build-lib check \ install \ export-archive \ clean # Default target: # 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. ${addprefix -I,${OTHERINCS}} -I${JSINC} #--------------------------------------------------------------------- # "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. We list ${HOFILES} as an explicit target # to force (hopefully) compilation of all {.h}s before all {.c}s. build: build-hos build-lib build-hos: ${HOFILES} build-lib: ${LIBFILE} CC := /usr/bin/gcc CFLAGS := \ -ggdb -ffloat-store -frounding-math \ -Wall -Wpointer-arith -Wmissing-prototypes \ -fpcc-struct-return %.o: %.c ${CC} -c ${CFLAGS} ${IFLAGS} $*.c %.ho: %.h ${CC} -o $*.ho -c ${CFLAGS} ${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 tar-export" creates a date-stamped tarball of sources and library. # Test Makefiles and sources are included, as well as any files # named '*-in.*'. Beware that scripts and other test data files # are NOT included! DATETIME = ${shell date '+%Y-%m-%d-%H%M%S'} EXTARFILE := ${LIBNAME}-${DATETIME}.tgz tar-export: ${LIBFILE} tar -cvzf ${EXTARFILE} \ 00-README Makefile \ ${HFILES} ${CFILES} \ ${LIBFILE} \ `find tests \( -name 'Makefile' -o -name '*.[hcf]' -o -name '*-in.*' \) -print` #--------------------------------------------------------------------- # "make tar-save" creates a date-stamped tarball of all files except # edit backups and derived files. SAVEDIR := SAVE SAVETARFILE := ${LIBNAME}-${DATETIME}-save.tgz tar-save: clean tar -cvzf ${SAVEDIR}/${SAVETARFILE} \ `find ./ -type f -print | egrep -v -e '[~]$'` #--------------------------------------------------------------------- # "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. ######################################################################