# Last edited on 2008-02-04 12:54:23 by stolfi .PHONY: all what split join pick-files list-all-files compile-joint # all: pick-files # all: join all: compile-joint what: @echo "** make what?" # Date and time the "make" was run: DATE_TIME := ${shell date '+%Y-%m-%d-%H%M%S'} # Top-level directory of split version: SPLIT_TOP := cur # Sub-directories of ${SPLIT_TOP} that can be compiled: GOOD_DIRS := \ ${SPLIT_TOP}/liboct \ ${SPLIT_TOP}/progs-main \ ${SPLIT_TOP}/libenergy \ ${SPLIT_TOP}/libmore \ ${SPLIT_TOP}/progs-more JUNK_DIRS := \ ${SPLIT_TOP}/JUNK \ ${addsuffix /JUNK,${GOOD_DIRS}} SPLIT_DIRS := ${GOOD_DIRS} ${JUNK_DIRS} # Scratch directory TMPDIR := /tmp # Files with all sources concatenated: GOOD_JOINT_FILE := all.c JUNK_JOINT_FILE := all-junk.c # ---------------------------------------------------------------------- # Enumerate all source files under the ${SPLIT_TOP} directory. # Computed file with names of all source files in the ${SPLIT_TOP} directory: ALL_FILES_LIST := files-all.dir list-all-files: ${ALL_FILES_LIST} # Enumerating files: ${ALL_FILES_LIST}: ${SPLIT_TOP} find ${SPLIT_TOP} \ -type f \ \( \! \( -name '*~' -o -name '.*' \) \) \ -print \ | sort | uniq \ > ${ALL_FILES_LIST} # ---------------------------------------------------------------------- # Rebuilding the lists (good and junk) of files that are to be joined. # User-given file with names of source files in preferred join order USER_PRIORITY_LIST := priority-good.dir # Computed file with names of all "new" source files: FILES_NEW_LIST := files-new.dir # Those are all files under the ${SPLIT_TOP} directory that are # not mentioned in the ${USER_PRIORITY_LIST} # Computed file with names of files to join in ${GOOD_JOINT_FILE}, in join order: FILES_GOOD_LIST := files-good.dir # This list has all the "new" files that are not called '*/JUNK/*', # followed by those names in ${USER_PRIORITY_LIST}. # Computed file with names of files to join in ${JOINT_JOINT_FILE}, in join order FILES_JUNK_LIST := files-junk.dir # This list has all the new files caled '*/JUNK/*'. pick-files: ${FILES_GOOD_LIST} ${FILES_JUNK_LIST} ${FILES_NEW_LIST}: ${SPLIT_TOP} ${ALL_FILES_LIST} ${USER_PRIORITY_LIST} cat ${USER_PRIORITY_LIST} \ | sort | uniq \ > ${TMPDIR}/.known bool 1-2 ${ALL_FILES_LIST} ${TMPDIR}/.known \ > ${FILES_NEW_LIST} ${FILES_GOOD_LIST}: ${FILES_NEW_LIST} ${USER_PRIORITY_LIST} cat ${USER_PRIORITY_LIST} \ | sort | uniq \ > ${TMPDIR}/.known echo 'timestamp.txt' > ${FILES_GOOD_LIST} -bool 1-2 ${FILES_NEW_LIST} ${TMPDIR}/.known \ | sort -t. -k2,2 -k1,1 \ | egrep -v -e '/JUNK/' \ | egrep -v -e '^timestamp.txt$$' \ >> ${FILES_GOOD_LIST} cat ${USER_PRIORITY_LIST} \ >> ${FILES_GOOD_LIST} ${FILES_JUNK_LIST}: ${FILES_NEW_LIST} cat ${FILES_NEW_LIST} \ | grep -e '/JUNK/' \ > ${FILES_JUNK_LIST} # ---------------------------------------------------------------------- # Joining all source files into two bigfiles (good and junk) GOOD_TEMP_FILE := tmp.c JUNK_TEMP_FILE := tmp-junk.c join: clean ${SPLIT_DIRS} ${FILES_GOOD_LIST} ${FILES_JUNK_LIST} tar -cvzf ${DATE_TIME}-cur.tgz ${SPLIT_TOP} join-sources-for-editing `cat ${FILES_GOOD_LIST}` > ${GOOD_TEMP_FILE} mv --backup=numbered -v ${GOOD_TEMP_FILE} ${GOOD_JOINT_FILE} join-sources-for-editing `cat ${FILES_JUNK_LIST}` > ${JUNK_TEMP_FILE} mv --backup=numbered -v ${JUNK_TEMP_FILE} ${JUNK_JOINT_FILE} # ---------------------------------------------------------------------- # Splitting the good and junk bigfiles into separate source files OLD_TOP := old DIFF_FILE := ${DATE_TIME}.diff split: clean ${GOOD_JOINT_FILE} tar -cvzf ${DATE_TIME}-cur.tgz ${SPLIT_TOP} rm -rf ${OLD_TOP} && mv ${SPLIT_TOP} ${OLD_TOP} mkdir -p ${SPLIT_DIRS} split-joined-sources ${GOOD_JOINT_FILE} split-joined-sources ${JUNK_JOINT_FILE} touch ${addsuffix /Deps.make,${GOOD_DIRS}} prdiff -Bbs -r ${OLD_TOP} ${SPLIT_TOP} > ${DIFF_FILE} grep 'Only in ${OLD_TOP}' ${DIFF_FILE} @echo "recreating ${USER_PRIORITY_LIST} ..." list-joined-sources ${GOOD_JOINT_FILE} \ | egrep -v '^timestamp.txt$$' \ > ${USER_PRIORITY_LIST} # ---------------------------------------------------------------------- # Compiling the split directories compile-split: ${GOOD_DIRS} for dir in ${GOOD_DIRS} ; do \ ( cd $$dir && && ${MAKE} build ) ; \ done INCLUDES := \ -I ${STOLFIHOME}/include \ -I ${STOLFIHOME}/include # ---------------------------------------------------------------------- # Compiling the joint file compile-joint: all.c gcc \ -fsyntax-only \ -Wall -Wmissing-prototypes \ ${INCLUDES} \ -c all.c # ---------------------------------------------------------------------- # Delete derived files: clean: ${GOOD_DIRS} rm -f ${FILES_NEW_LIST} ${FILES_GOOD_LIST} ${FILES_JUNK_LIST} for dir in ${GOOD_DIRS} ; do \ ( cd $$dir && make clean ) ; \ done # ---------------------------------------------------------------------- # Find dependencies: depend: ${GOOD_DIRS} for dir in ${GOOD_DIRS} ; do \ ( cd $$dir && make depend ) ; \ done # ---------------------------------------------------------------------- # Debugging the makefile debug: @echo "DATE_TIME = ${DATE_TIME}" @echo "GOOD_DIRS = ${GOOD_DIRS}" @echo "JUNK_DIRS = ${JUNK_DIRS}" @echo "FILES_GOOD = ${FILES_GOOD}" @echo "FILES_JUNK = ${FILES_JUNK}" @echo "{wildcard *.c} = ${wildcard *.c}" @echo "{wildcard *.{c,h}} = ${wildcard *.{c,h}}"