# Generic Makefile for a single executable program # Last edited on 2008-01-12 11:13:04 by stolfi ###################################################################### # To be included by the top-level Makefile in the program's directory. # The caller must define ${PROG} and possibly also ${JS_LIBS} ifneq "/${PROG}" "/" 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 INST_MAN_DIR = ${INST_PUB_DIR}/man # Location of X11 libraries (including ICE): X11_INC_DIR := /usr/include/X11 X11_LIB_DIR := /usr/lib # Location of Stolfi's headers and libraries: JS_PUB_DIR := ${HOME}/PUB JS_LIB_DIR := ${JS_PUB_DIR}/${PLATFORM}/lib JS_INC_DIR := ${JS_PUB_DIR}/include # Get list of source files (excluding ${PROG}.c): HFILES := ${shell shopt -s nullglob; ls *.h Makefile | egrep -v '^(junk[.]h|Makefile)$$'} CFILES := ${shell shopt -s nullglob; ls *.c Makefile | egrep -v '^(junk[.]c|${PROG}[.]c|Makefile)$$'} # Derived object files (excluding ${PROG}.o): HOFILES := ${subst .h,.ho,${HFILES}} OFILES := ${subst .c,.o,${CFILES}} # Make targets: .PHONY: \ depend \ all \ uninstall uninstall-man \ build build-prog check \ install install-man \ clean # Default target: # all: uninstall clean build check install all: uninstall build install # Directories to search for #include files: IFLAGS := -I. -I${JS_INC_DIR} # File with dependencies between sources: DEPFILE := Deps.make # This file must be present to run "make"; # create an empty one if necessary. #--------------------------------------------------------------------- # "make depend" recreates the source dependency file ${DEPFILE}. depend: /bin/rm -f ${DEPFILE} extract-ho-deps ${IFLAGS} -I/usr/include \ ${HFILES} ${CFILES} ${PROG}.c \ | egrep -v ': /usr/include' \ > ${DEPFILE} #--------------------------------------------------------------------- # "make build" assumes that the dependencies in ${DEPFILE} # are up-to-date. build: build-prog build-prog: ${PROG} # Get X11 libraries if requested: ifeq "/${USE_X11}" "/YES" X11_LIBRARIES := \ ${X11_LIB_DIR}/libX11.so \ ${X11_LIB_DIR}/libXext.so \ ${X11_LIB_DIR}/libXmu.so \ ${X11_LIB_DIR}/libXt.so \ ${X11_LIB_DIR}/libXi.so \ ${X11_LIB_DIR}/libSM.so \ ${X11_LIB_DIR}/libICE.so else X11_LIBRARIES := endif LIBRARIES := \ ${addprefix ${JS_LIB_DIR}/, ${JS_LIBS}} \ ${X11_LIBRARIES} \ ${OTHER_LIBS} CC := /usr/bin/gcc CFLAGS := \ -ggdb -O -ffloat-store -frounding-math \ -ansi \ -Wall -Wpointer-arith -Wmissing-prototypes 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 ${PROG}: ${PROG}.o ${OFILES} ${LIBRARIES} -rm -f ${PROG} ${CC} -o ${PROG} ${LDFLAGS} ${PROG}.o \ ${OFILES} \ ${LIBRARIES} -lm -lrt # Include specific dependencies extracted by "make depend" include ${DEPFILE} #--------------------------------------------------------------------- # "make install" copies program and makefile to the public dir. MANSECT := 1 MANPAGE := ${PROG}.${MANSECT} install: ${PROG} install-man cp -p ${PROG} ${INST_BIN_DIR}/ install-man: @if [ -r ${MANPAGE} ]; then \ cp -p ${MANPAGE} ${INST_MAN_DIR}/man${MANSECT}/ ;\ else \ echo "file ${PROG}.${MANSECT} not found - assuming that it is not needed" ;\ fi #--------------------------------------------------------------------- # "make uninstall" deletes the exported program and makefile: uninstall: uninstall-man ( cd ${INST_BIN_DIR} && rm -f ${PROG} ) uninstall-man: ( cd ${INST_MAN_DIR} && rm -f man${MANSECT}/${MANPAGE} ) ( cd ${INST_CAT_DIR} && rm -f cat${MANSECT}/${MANPAGE} ) #--------------------------------------------------------------------- # "make archive" creates a tarball of sources, manpage, and executable. TARGZ := ${PROG}.tgz archive: tar -cvzf ${TARGZ} \ 00-README Makefile \ ${PROG} ${PROGS} \ ${HFILES} ${CFILES} ${PROG}.c \ ${MANPAGE} #--------------------------------------------------------------------- # "make check" runs the tests in the "tests" subdirectory. TESTDIR := tests check: ${PROG} ( cd ${TESTDIR} && ${MAKE} all ) #--------------------------------------------------------------------- # "make clean" deletes all derived files. clean: -/bin/rm -f *.o *.ho *.a core ${PROG} ( cd ${TESTDIR} && ${MAKE} clean ) endif # End of ${PROG} section. ######################################################################