# Generic Makefile for a single executable program # Last edited on 2008-07-30 14:40:30 by stolfi ###################################################################### # To be included by the top-level Makefile in the program's directory. # The caller must define ${PROG} ifneq "/${PROG}" "/" SHELL := /bin/sh # Where to install the program: INSTPUB := ${HOME}/programs/c/THESES/douglas INSTINC := ${INSTPUB}/include INSTLIB := ${INSTPUB}/lib INSTBIN := ${INSTPUB}/bin # 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: \ all \ uninstall \ build build-prog check \ install \ clean # all: uninstall clean build check install all: uninstall build install # Directories to search for #include files: IFLAGS := -I. -I${INSTINC} #--------------------------------------------------------------------- # "make build" assumes that the dependencies are listed in the Makefile. build: ${HOFILES} build-prog build-prog: ${PROG} # Get OpenGL libraries is requested: ifeq "/${USEGL}" "/YES" GL_LIBRARIES := \ ${GLLIB}/libglut.so \ ${GLLIB}/libGLU.so \ ${GLLIB}/libGL.so else GL_LIBRARIES := endif # Get X11 libraries if requested: ifeq "/${USEX11}" "/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 := \ ${GL_LIBRARIES} \ ${X11_LIBRARIES} \ ${OTHERLIBS} CC := /usr/bin/gcc CFLAGS := \ -ggdb -O \ -Wall -Wpointer-arith -Wmissing-prototypes \ -fpcc-struct-return LDFLAGS := \ -ggdb %.o: %.c ${HOFILES} ${INSTINC} ${CC} -c ${CFLAGS} ${EXTRACFLAGS} ${IFLAGS} $*.c %.ho: %.h ${HFILES} ${INSTINC} ${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 #--------------------------------------------------------------------- # "make install" copies program and makefile to the public dir. install: ${PROG} cp -p ${PROG} ${INSTBIN}/ #--------------------------------------------------------------------- # "make uninstall" deletes the exported program and makefile: uninstall: ( cd ${INSTBIN} && rm -f ${PROG} ) #--------------------------------------------------------------------- # "make archive" creates a tarball of sources, and executable. TARGZ := ${PROG}.tgz archive: tar -cvzf ${TARGZ} \ 00-README Makefile \ ${PROG} ${PROGS} \ ${HFILES} ${CFILES} ${PROG}.c #--------------------------------------------------------------------- # "make check" runs the tests in the "tests" subdirectory. TESTDIR := tests check: ${PROG} 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 ${PROG} if [[ -d ${TESTDIR} ]]; then ( cd ${TESTDIR} && ${MAKE} clean ) fi endif # End of ${PROG} section. ######################################################################