# Generic Makefile for a single executable program # Last edited on 2008-01-14 17:13:41 by stolfi ###################################################################### # To be included by the top-level Makefile in the program's directory. # The caller must define ${PROG} and possibly also ${AGLIBS} ifneq "/${PROG}" "/" SHELL := /bin/sh # Where to install the program: INSTPUB := ${HOME} INSTINC := ${INSTPUB}/include INSTLIB := ${INSTPUB}/${PLATFORM}/lib INSTBIN := ${INSTPUB}/${PLATFORM}/bin INSTMAN := ${INSTPUB}/${PLATFORM}/man INSTCAT := ${INSTPUB}/${PLATFORM}/cat # Location of the GL libraries GLLIB := /usr/lib # Location of X11 libraries (including ICE): X11INC := /usr/X11R6/include X11LIB := /usr/X11R6/lib # 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 # all: uninstall clean build check install all: uninstall build install IFLAGS := -I. -I${AGINC} # 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 OpenGL libraries is requested: ifeq "/${USE_GL}" "/YES" GL_LIBRARIES := \ ${GLLIB}/libglut.so \ ${GLLIB}/libGLU.so \ ${GLLIB}/libGL.so else GL_LIBRARIES := endif # Get X11 libraries if requested: ifeq "/${USE_X11}" "/YES" X11_LIBRARIES := \ ${X11LIB}/libX11.so \ ${X11LIB}/libXext.so \ ${X11LIB}/libXmu.so \ ${X11LIB}/libXt.so \ ${X11LIB}/libXi.so \ ${X11LIB}/libSM.so \ ${X11LIB}/libICE.so else X11_LIBRARIES := endif LIBRARIES := \ ${addprefix ${AGLIB}/, ${AGLIBS}} \ ${GL_LIBRARIES} \ ${X11_LIBRARIES} \ ${OTHERLIBS} CC := /usr/bin/gcc CFLAGS := \ -ggdb -O -ffloat-store -frounding-math \ -Wall -Wpointer-arith -Wmissing-prototypes \ -fpcc-struct-return 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} ${INSTBIN}/ install-man: @if [ -r ${MANPAGE} ]; then \ cp -p ${MANPAGE} ${INSTMAN}/man${MANSECT}/ ;\ else \ echo "file ${PROG}.${MANSECT} not found - ignored" ;\ fi #--------------------------------------------------------------------- # "make uninstall" deletes the exported program and makefile: uninstall: uninstall-man ( cd ${INSTBIN} && rm -f ${PROG} ) uninstall-man: ( cd ${INSTMAN} && rm -f man${MANSECT}/${MANPAGE} ) ( cd ${INSTCAT} && 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. ######################################################################