# Generic Makefile for one or more self-contained scripts (awk, bask, etc.) # Last edited on 2024-03-29 02:02:29 by stolfi SHELL := /bin/bash ###################################################################### # To be included by the top-level Makefile in the program's directory. # The caller must define # # ${STOLFIHOME} directory with stolfi's bin, lib, include, etc. # ${PROG} or ${PROGS} user-executable scripts. # ${LIB} or ${LIBS} auxiliary script files used by the above (WITH extensions). include ${STOLFIHOME}/programs/GENERIC.make ifeq "/${PROGS}" "/" PROGS := ${PROG} endif ifeq "/${LIBS}" "/" LIBS := ${LIB} endif ifneq "/${PROGS}${LIBS}" "/" #--------------------------------------------------------------------- # Default action for "make" with no arguments: # # all: uninstall clean build check install all: uninstall build install #--------------------------------------------------------------------- # "make actions" performs the actions listed in ${ACTIONS}, if any actions: ifeq "/${ACTIONS}" "/" @echo '$${ACTIONS} is empty' else ${MAKE} ${ACTIONS} endif #--------------------------------------------------------------------- # "make depend" does nothing depend: #--------------------------------------------------------------------- # "make build" does nothing (for now): build: ${PROGS} ${LIBS} build-libs: ${LIBS} build-progs: ${PROGS} ${LIBS} build-tests: ${PROGS} ${LIBS} if [[ -d ${TEST_DIR} ]]; then ( cd ${TEST_DIR} && ${MAKE} build ) fi #--------------------------------------------------------------------- # "make install" copies scripts and libs to the public dir. install: install-progs install-libs install-progs: ${PROGS} ifneq "/${PROGS}" "/" sdir=`pwd`; \ sdir="../$${sdir/*programs/programs}"; \ echo "sdir = $${sdir}" 1>&2; \ ( cd ${INST_BIN_DIR}/ && \ for p in ${PROGS} ; do \ rm -fv $${p}; \ ln -sv $${sdir}/$${p} ; \ ext="$${p##*.}" ; \ if [[ "/$${ext}" != "/" ]] ; then \ q=$${p/.$${ext}/}; \ rm -fv $${q}; \ ln -sv $${p} $${q} ; \ fi ; \ done \ ) endif install-libs: ${LIBS} ifneq "/${LIBS}" "/" sdir=`pwd`; \ sdir="../$${sdir/*programs/programs}"; \ echo "sdir = $${sdir}" 1>&2; \ ( cd ${INST_LIB_DIR}/ && \ rm -fv ${LIBS} && \ for p in ${LIBS} ; do \ ln -sv $${sdir}/$${p}; \ done \ ) endif #--------------------------------------------------------------------- # "make uninstall" deletes the exported scripts and libs: uninstall: uninstall-progs uninstall-libs uninstall-progs: ifneq "/${PROGS}" "/" ( cd ${INST_BIN_DIR}/ && \ for p in ${PROGS} ; do \ rm -fv $${p}; \ ext="$${p##*.}"; \ if [[ ( "/$${ext}" == "/sh" ) || ( "/$${ext}" == "/gawk" ) || ( "/$${ext}" == "/py" ) ]] ; then \ q=$${p/.$${ext}/}; \ rm -fv $${q} ; \ fi ; \ done \ ) endif uninstall-libs: ifneq "/${LIBS}" "/" ( cd ${INST_LIB_DIR}/ && \ for p in ${LIBS} ; do \ rm -fv $${p} ; \ ext="$${p##*.}"; \ if [[ ( "/$${ext}" == "/sh" ) || ( "/$${ext}" == "/gawk" ) || ( "/$${ext}" == "/py" ) ]] ; then \ q=$${p/.$${ext}/}; \ rm -fv $${q} ; \ fi ; \ done \ ) endif #--------------------------------------------------------------------- # "make archive" creates a tarball of scripts, libs, and Makefile. NOW = ${shell date '+%Y-%m-%d-%H%M%S'} TARBALL_NAME := ${NOW}.tgz archive: ;\ tar -cvzf ${TARBALL_NAME} \ 00-README Makefile \ ${PROGS} \ ${LIBS} #--------------------------------------------------------------------- # "make check" runs the tests in the "tests" subdirectory. TEST_DIR := tests check: ${PROG} if [[ -d ${TEST_DIR} ]]; then ( cd ${TEST_DIR} && ${MAKE} all ) fi #--------------------------------------------------------------------- # "make clean" deletes all derived files. clean: -/bin/rm -f core if [[ -d ${TEST_DIR} ]]; then ( cd ${TEST_DIR} && ${MAKE} clean ) fi endif # End of ${PROGS}/${LIBS} section. ###################################################################### #--------------------------------------------------------------------- # "make debug" prints some debugging info: debug: @echo "PROGS = ${PROGS}" @echo "LIBS = ${LIBS}"