# Generic makefile for a library # Last edited on 2024-11-30 06:42:25 by stolfi ###################################################################### # To be included by the top-level Makefile in the library's directory. # The caller must define # # ${STOLFIHOME} directory with stolfi's bin, lib, include, etc. # ${LIBNAME} name of library (WITHOUT the directory or the ".a") # # and may also define # # ${IGNORE} a list of ".h" or ".c" files that should not be compiled or installed. # ${OTHER_I_FLAGS} additional -I flags for C compilation and dependency checks. # ${OTHER_C_FLAGS} additional flags to compile C source files. # Back-compatibility hack: OTHER_C_FLAGS := ${OTHER_C_FLAGS} ${EXTRA_C_FLAGS} include ${STOLFIHOME}/programs/c/GENERIC.make ifneq "/${LIBNAME}" "/" # ---------------------------------------------------------------------- # Package components and directories # Library file name: LIBFILE = ${LIBNAME}.a # Get list of sources: HFILES := ${filter-out ${IGNORE}, ${wildcard *.h}} CFILES := ${filter-out ${IGNORE}, ${wildcard *.c}} # Derived object files: HOFILES := ${subst .h,.ho,${HFILES}} OFILES := ${subst .c,.o,${CFILES}} # Directory with test programs and runs thereof: TEST_DIR := tests # ---------------------------------------------------------------------- # Installation directories # Where to install the library: INST_PUB_DIR := ${STOLFIHOME} INST_INC_DIR := ${INST_PUB_DIR}/include INST_LIB_DIR := ${INST_LIB_DIR}/${PLATFORM} # ---------------------------------------------------------------------- # Locations of imported packages # Location of Stolfi's headers: JS_PUB_DIR := ${STOLFIHOME} JS_INC_DIR := ${JS_PUB_DIR}/include # Location of X11 headers and libraries (including ICE): X11_INC_DIR := /usr/include/X11 # ---------------------------------------------------------------------- # Optional include directories # Get OpenGL libraries is requested: ifeq "/${USE_GL}" "/YES" GL_I_FLAGS := \ -I ${JS_INC_DIR}/GL \ -I /usr/include/GL else GL_I_FLAGS := endif # Get X11 libraries and headers if requested: ifeq "/${USE_X11}" "/YES" X11_I_FLAGS := -I${X11_INC_DIR} else X11_I_FLAGS := endif #--------------------------------------------------------------------- # Default target for "make" with no target: all: debug-make uninstall build-lib install build-tests #--------------------------------------------------------------------- # "make actions" performs the ${ACTIONS} locally: actions: @echo "make actions" 1>&2 ifeq "/${ACTIONS}" "/" @echo '$${ACTIONS} is empty' else ${MAKE} ${ACTIONS} endif #--------------------------------------------------------------------- # Directories to search for #include files: I_FLAGS := \ -I. \ -I${JS_INC_DIR} \ ${GL_I_FLAGS} \ ${X11_I_FLAGS} \ ${OTHER_I_FLAGS} #--------------------------------------------------------------------- # "make depend" recreates the source dependency file ${DEPFILE}. DEPFILE := Deps.make depend: ${DEPFILE} ${DEPFILE}: ${HFILES} ${CFILES} @echo "GENERIC-LIB.make: make ${DEPFILE}" 1>&2 @/bin/rm -f ${DEPFILE} @extract_ho_deps ${I_FLAGS} -I/usr/include \ ${HFILES} ${CFILES} \ | egrep -v ': /usr/include' \ > ${DEPFILE} # ---------------------------------------------------------------------- # Create a local symlink for {extract_ho_deps}, for {tar-export}'s sake extract_ho_deps: ${STOLFIHOME}/bin/extract_ho_deps @echo "GENERIC-LIB.make: make extract_ho_deps" 1>&2 ln -s ${STOLFIHOME}/bin/extract_ho_deps #--------------------------------------------------------------------- # "make build" and "make build-lib" make sure that the ${DEPFILE} # is up to date, and then recreate the object files from the source files # as necessary. "make build" and "make build-tests" also rebuild # the test programs. build: build-lib build-tests build-libs: build-lib build-lib: ${DEPFILE} @echo "GENERIC-LIB.make: doing build-lib" 1>&2 ${MAKE} do-build-lib do-build-lib: ${LIBFILE} debug-make: @echo "GENERIC-LIB.make: doing debug-make" 1>&2 @echo "HFILES = ${HFILES}" 1>&2 @echo "CFILES = ${CFILES}" 1>&2 %.o: %.c ${CC} -c ${C_FLAGS} ${OTHER_C_FLAGS} ${I_FLAGS} $*.c %.ho: %.h ${CC} -o $*.ho -c ${C_FLAGS} ${OTHER_C_FLAGS} ${I_FLAGS} -x c $*.h \ || /bin/rm -f $*.ho ${LIBFILE}: ${HOFILES} ${OFILES} @echo "GENERIC-LIB.make: doing make ${LIBFILE}" 1>&2 -rm -f $*.a ar crv $*.a ${OFILES} ranlib $*.a build-tests: ${LIBFILE} @echo "GENERIC-LIB.make: doing make bild-tests" 1>&2 if [[ -d ${TEST_DIR} ]]; then ( cd ${TEST_DIR} && ${MAKE} build ) fi ifneq "/${wildcard ${DEPFILE}}" "/" # Include specific dependencies extracted by "make depend" include ${DEPFILE} endif #--------------------------------------------------------------------- # "make install" copies program and makefile to the public dir. install: install-lib install-libs: install-lib install-lib: ${HFILES} ${HOFILES} ${LIBFILE} @echo "GENERIC-LIB.make: doing make install-lib" 1>&2 @for hho in ${HFILES} ${HOFILES} ; do \ compdir="$${PWD}" ; \ ( cd ${INST_INC_DIR}/ && rm -f $${hho} ; ln -s $${compdir}/$${hho} ; ls -ld $${hho} ) ; \ done @compdir="$${PWD}" ; ( cd ${INST_LIB_DIR}/ && rm -f ${LIBFILE} ; ln -s $${compdir}/${LIBFILE} ; ls -ld ${LIBFILE} ) #--------------------------------------------------------------------- # "make uninstall" deletes the exported program and makefile: uninstall: uninstall-lib uninstall-libs: uninstall-lib uninstall-lib: @echo "GENERIC-LIB.make: doing make uninstall-lib" 1>&2 ( cd ${INST_INC_DIR}/. && rm -f ${HFILES} ${HOFILES} ) ( cd ${INST_LIB_DIR}/. && 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! NOW := ${shell date '+%Y-%m-%d-%H%M%S'} TARBALL_FILE := ${LIBNAME}-${NOW}.tgz tar-export: ${LIBFILE} extract_ho_deps @echo "GENERIC-LIB.make: doing make tar-export" 1>&2 @echo "archiving to ${TARBALL_FILE} ..." tar -cvzf ${TARBALL_FILE} \ 00-README Makefile \ extract_ho_deps \ ${HFILES} ${CFILES} \ ${LIBFILE} \ `find ${TEST_DIR} \( -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}-${NOW}-save.tgz tar-save: clean @echo "GENERIC-LIB.make: doing make tar-save" 1>&2 tar -cvzf ${SAVEDIR}/${SAVETARFILE} \ `find ./ -type f -print | egrep -v -e '[~]$'` #--------------------------------------------------------------------- # "make check" runs the tests in the ${TEST_DIR} subdirectory. check: @echo "GENERIC-LIB.make: doing make check" 1>&2 if [[ -d ${TEST_DIR} ]]; then ( cd ${TEST_DIR} && ${MAKE} all ) fi #--------------------------------------------------------------------- # "make clean" deletes all derived files. clean: clean-lib clean-tests clean-lib: clean-tests @echo "GENERIC-LIB.make: doing make clean-lib" 1>&2 -/bin/rm -f *.o *.ho *.a core clean-tests: @echo "GENERIC-LIB.make: doing make clean-tests" 1>&2 if [[ -d ${TEST_DIR} ]]; then ( cd ${TEST_DIR} && ${MAKE} clean ) fi endif # End of ${LIBNAME} section. ###################################################################### #--------------------------------------------------------------------- # "make debug" prints some debugging info: debug: @echo "GENERIC-LIB.make: doing make debug" 1>&2 @echo "LIBNAME = ${LIBNAME}"