# Last edited on 2009-01-09 04:30:38 by stolfi # Auxiliary programs: PROGS := imgcompress # Set to 1 while developing, to 0 before exporting: DEVELOPING := 0 # Public WWW directory for export: EXPORT_DIR = ${STOLFIHOME}/public_html/urna/BufferOverflow # Name of package for export: PACKAGE_NAME := ovf-demo # Exported stages of debugging: EXPORT_STAGES := 1 2 3 # Name of exported demo program (do not list in ${PROGS}): DEMO_PROG := demo # The master source file for all versions of the demo program: DEMO_MASTER_CFILE := ${DEMO_PROG}-master.c .PHONY:: \ compress-images \ export \ export-build-single \ export-build-single-data export-build-single-sources \ export-build-single-test export-build-single-diff \ export-release # The master file for all versions cannot be compiled: IGNORE := ${DEMO_MASTER_CFILE} all: build OTHER_C_FLAGS := -ansi -Wtraditional include ${STOLFIHOME}/programs/c/GENERIC-PROGS.make clean:: rm -f *.zz rm -rf ${PACKAGE_NAME}-20[0-9][0-9]-[01][0-9]-[01][0-9]-?????? install: @echo "*** Package was NOT installed." @echo "*** Run \"make export\" To generate the public" @echo "*** versions and ship them to public_html." # ---------------------------------------------------------------------- # The input `images' are actually ASCII art. # The /name/ and contents of "garotinho.img" is important # for the demo. PLAIN_IMAGES := \ ciro.img \ garotinh.img \ garotinho.img \ lula.img \ serra.img \ # The ${ZZ_IMAGES} are versions of ${PLAIN_IMAGES} compressed # with {imgcompress}: ZZ_IMAGES := ${addsuffix .zz, ${PLAIN_IMAGES}} compressed-images: ${ZZ_IMAGES} %.img.zz: %.img imgcompress < $< > $@ # ---------------------------------------------------------------------- # "make export" creates a tarfile and a zipfile of the external-view demo, # and exports it to a public WWW directory. # ###################################################################### # For top-level "make export" -- The caller must leave the # ${RELEASE} macro undefined. ifeq "/${RELEASE}" "/" # Set the ${RELEASE} variable to the current date and time: RELEASE := ${shell date +%Y-%m-%d-%H%M%S} export: ${PROG} ${PLAIN_IMAGES} ${ZZ_IMAGES} ${MAKE} RELEASE=${RELEASE} STAGE=0 export-build-single ${MAKE} RELEASE=${RELEASE} STAGE=2 export-build-single ${MAKE} RELEASE=${RELEASE} STAGE=1 export-build-single ${MAKE} RELEASE=${RELEASE} STAGE=3 export-build-single ${MAKE} RELEASE=${RELEASE} export-release endif # End of top-level "make export" section # ###################################################################### # ###################################################################### # For "make export-release", a sub-make of "make export". The caller must # define macros ${RELEASE}. It copies selected debugging stages to the # public directory, and moves the tarfile and zipfile there too. ifneq "/${RELEASE}" "/" RELEASE_DIR = ${PACKAGE_NAME}-${RELEASE} ifeq "/${DEVELOPING}" "/1" export-release: @echo "*** Cannot export reelase with DEVELOPING = ${DEVELOPING}" endif ifeq "/${DEVELOPING}" "/0" EXPORT_STAGE_DIRS := ${addprefix ${RELEASE_DIR}/,${EXPORT_STAGES}} EXPORT_DEMOS := ${addsuffix /${DEMO_PROG}.c,${EXPORT_STAGE_DIRS}} export-release: \ ${EXPORT_STAGE_DIRS} \ ${RELEASE_DIR}.tgz \ ${RELEASE_DIR}.zip rm -f ${RELEASE_DIR}/*/{${DEMO_PROG},*.o} mkdir -p ${EXPORT_DIR}/${RELEASE_DIR} cp -av ${EXPORT_STAGE_DIRS} ${EXPORT_DIR}/${RELEASE_DIR}/ mv -v ${RELEASE_DIR}.tgz ${RELEASE_DIR}.zip ${EXPORT_DIR}/ ${RELEASE_DIR}.tgz: ${EXPORT_DEMOS} rm -f ${RELEASE_DIR}/*/{${DEMO_PROG},*.o} tar -cvzhf ${RELEASE_DIR}.tgz ${EXPORT_STAGE_DIRS} ${RELEASE_DIR}.zip: ${EXPORT_DEMOS} rm -f ${RELEASE_DIR}/*/{${DEMO_PROG},*.o} zip ${RELEASE_DIR}.zip ${EXPORT_STAGE_DIRS} endif # ###################################################################### # For "make export-build-single", sub-make of "make export-release". The # caller must define ${RELEASE}, and also ${STAGE} -- the stage of "debugging" # a digit in 0..4. It creates a single version of the demo, in a particular # stage of debugging, in the directory ${STAGE_DIR}: ifneq "/${STAGE}" "/" STAGE_DIR = ${RELEASE_DIR}/${STAGE} DEMO_STAGE_CFILE := ${STAGE_DIR}/${DEMO_PROG}.c DEMO_STAGE_MAKEFILE := ${STAGE_DIR}/Makefile export-build-single: ${STAGE_DIR} \ export-build-single-data \ export-build-single-sources \ export-build-single-test \ export-build-single-diff @echo "Done with directory ${STAGE_DIR}" @echo "====================================================================" ${STAGE_DIR}: @echo "====================================================================" @echo "Creating directory ${STAGE_DIR}" mkdir -p ${STAGE_DIR} # Build the compressed image files for the stage: export-build-single-data: cp -av ${PLAIN_IMAGES} ${ZZ_IMAGES} ${STAGE_DIR} # Build the source C files for the stage: export-build-single-sources: ${DEMO_STAGE_CFILE} ${DEMO_STAGE_MAKEFILE} ${DEMO_STAGE_MAKEFILE}: ${DEMO_PROG}.make Makefile cp -p ${DEMO_PROG}.make ${DEMO_STAGE_MAKEFILE} # ###################################################################### # Private pseudo-export version (${STAGE} = 0). # Will be used as a reference for "make export-build-single-diff" ifeq "/${STAGE}" "/0" # ---------------------------------------------------------------------- # When ${STAGE} == 0, the source ${DEMO_STAGE_CFILE} is just # a copy of ${DEMO_MASTER_CFILE}: ${DEMO_STAGE_CFILE}: ${DEMO_MASTER_CFILE} Makefile cp -av ${DEMO_MASTER_CFILE} ${DEMO_STAGE_CFILE} export-build-single-test: @echo "The version with STAGE == ${STAGE} is not meant to be compiled." export-build-single-diff: @echo "The version with STAGE == ${STAGE} has nothing to \"diff\" it from." endif # End of private "make-export-build-single" version # ###################################################################### # ###################################################################### # Public version (${STAGE} 1 and up) # To be exported to the {public_html} directory. ifneq "/${STAGE}" "/0" # ---------------------------------------------------------------------- # For stages 1, 2, ..., the source ${DEMO_STAGE_CFILE} is obtained # from ${DEMO_MASTER_CFILE} by excluding some lines: # # * any line with a comment /*!{S}!*/ where {S} is a # digit string that does /not/ contain the digit ${STAGE}. # # * Any line with a comment /*?{D}?*/ where {D} is a # digit string that does /not/ contain ${DEVELOPING}. # # In any case, all surviving /*!{S}!*/ comments are deleted from # the output file. ${DEMO_STAGE_CFILE}: ${DEMO_MASTER_CFILE} Makefile cat ${DEMO_MASTER_CFILE} \ | sed \ -e '/[*][!][0-9]*[!][*]/!s:$$: /*!1234!*/:' \ -e '/[*][?][0-9]*[?][*]/!s:$$: /*?01?*/:' \ -e '/[*][!][0-9]*['"${STAGE}"'][0-9]*[!][*]/!d' \ -e '/[*][?][0-9]*['"${DEVELOPING}"'][0-9]*[?][*]/!d' \ -e 's:[ ]*[/][*][!][0-9]*[!][*][/][ ]*: :g' \ -e 's:[ ]*[/][*][?]01[?][*][/][ ]*: :g' \ -e 's:[ ][ ]*$$::g' \ | cat -s \ > ${DEMO_STAGE_CFILE} chmod a-w ${DEMO_STAGE_CFILE} # The public versions (${STAGE} > 0) can be compiled and executed, # although they may bomb out: export-build-single-test: \ ${DEMO_STAGE_CFILE} \ ${DEMO_STAGE_MAKEFILE} \ ${addprefix ${STAGE_DIR}/, ${PLAIN_IMAGES}} \ ${addprefix ${STAGE_DIR}/, ${ZZ_IMAGES}} @echo "Testing version STAGE = ${STAGE}:" -( cd ${STAGE_DIR} && make ) # Compare each public version (${STAGE} > 0) with the private one # ($STAGE} == 0): REF_STAGE_DIR := ${RELEASE_DIR}/0 export-build-single-diff: @echo "Differences from the reference version:" -diff -r ${REF_STAGE_DIR} ${STAGE_DIR} endif # End of the public part of the "make-export-build-single" section # ###################################################################### endif # End of "make export-build-single" section. # ###################################################################### endif # End of "make export-release" section. # ######################################################################