# Generic Makefile for multiple executable programs # Last edited on 2008-01-12 11:07:43 by stolfi ###################################################################### # To be included by the top-level Makefile in the program's directory. # The caller must define ${PROG} or ${PROGS}, and possibly also # ${BAD_PROGS}, ${JS_LIBS} ifeq "/${PROGS}" "/" PROGS := ${PROG} endif ifneq "/${PROGS}" "/" SHELL := /bin/sh # Where to install the program INST_PUB_DIR := ${HOME}/PUB INST_INC_DIR := ${INST_PUB_DIR}/include INST_LIB_DIR := ${INST_PUB_DIR}/${PLATFORM}/lib INST_BIN_DIR := ${INST_PUB_DIR}/${PLATFORM}/bin # Location of Stolfi's libraries JS_PUB_DIR := /home/staff/stolfi/PUB JS_LIB_DIR := ${JS_PUB_DIR}/${PLATFORM}/lib JS_INC_DIR := ${JS_PUB_DIR}/include # Get list of sources: HFILES := ${shell shopt -s nullglob; ls *.h Makefile | egrep -v '^Makefile$$'} CFILES := ${shell shopt -s nullglob; ls *.c Makefile | egrep -v '^Makefile$$'} # Get list of main and non-main sources: PROG_CFILES := ${addsuffix .c,${PROGS}} BAD_PROG_CFILES := ${addsuffix .c,${BAD_PROGS}} LIB_CFILES := ${filter-out ${PROG_CFILES} ${BAD_PROG_CFILES}, ${CFILES}} # Derived objects: HOFILES := ${subst .h,.ho,${HFILES}} PROG_OFILES := ${subst .c,.o,${PROG_CFILES}} BAD_PROG_OFILES := ${subst .c,.o,${BAD_PROG_CFILES}} LIB_OFILES := ${subst .c,.o,${LIB_CFILES}} # Make targets: .PHONY: \ all depend \ uninstall \ build build-hos build-prog check \ install \ clean # all: uninstall clean build check install all: uninstall build install # File with dependencies between sources: DEPFILE := Deps.make # Directories to search for #include files: IFLAGS := -I. ${addprefix -I,${OTHER_INCS}} -I${JS_INC_DIR} #--------------------------------------------------------------------- # "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-hos build-prog build-hos: ${HOFILES} build-prog: ${PROGS} LIBRARIES := \ ${addprefix ${JS_LIB_DIR}/, ${JS_LIBS}} \ ${OTHER_LIBS} CC := /usr/bin/gcc CFLAGS := \ -ggdb -ffloat-store -frounding-math \ -ansi \ -Wall -Wpointer-arith -Wmissing-prototypes \ -fpcc-struct-return \ -frounding-math LDFLAGS := \ -ggdb %.o: %.c ;\ ${CC} -c ${CFLAGS} ${EXTRACFLAGS} ${IFLAGS} $*.c %.ho: %.h ;\ ${CC} -o $*.ho -c ${CFLAGS} ${IFLAGS} -x c $*.h \ || /bin/rm -f $*.ho ${PROGS}: ${PROG_OFILES} ${LIB_OFILES} ${LIBRARIES} @echo '= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =' @echo building $@ ... -rm -f $@ ${CC} -o $@ ${LDFLAGS} $@.o \ ${LIB_OFILES} \ ${LIBRARIES} -lm -lrt @echo '= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =' # Include specific dependencies extracted by "make depend" include ${DEPFILE} #--------------------------------------------------------------------- # "make install" copies program and makefile to the public dir. install: ${PROGS} cp -p ${PROGS} ${INST_BIN_DIR}/ #--------------------------------------------------------------------- # "make uninstall" deletes the exported program and makefile: uninstall: ( cd ${INST_BIN_DIR} && rm -f ${PROGS} ) #--------------------------------------------------------------------- # "make archive" creates a tarball of sources and executables. NOW = ${shell date '+%Y-%m-%d-%H%M%S'} TARBALL_NAME := ${NOW}.tgz archive: ;\ tar -cvzf ${TARBALL_NAME} \ 00-README Makefile \ ${PROGS} \ ${HFILES} ${CFILES} #--------------------------------------------------------------------- # "make check" runs the tests in the "tests" subdirectory. TESTDIR := tests check: ${PROGS} if [[ -d ${TESTDIR} ]] ; then \ ( cd ${TESTDIR} && ${MAKE} all ) ; \ else \ echo "directory ${TESTDIR} not found" ; \ fi #--------------------------------------------------------------------- # "make clean" deletes all derived files. clean: -/bin/rm -f *.o *.ho *.a core ${PROGS} if [[ -d ${TESTDIR} ]] ; then ( cd ${TESTDIR} && ${MAKE} clean ) ; fi endif # End of ${PROGS} section. ######################################################################