1################################################################# 2# 3# Generate crunched binaries using crunchgen(1). 4# 5# General notes: 6# 7# A number of Make variables are used to generate the crunchgen config file. 8# 9# CRUNCH_SRCDIRS: lists directories to search for included programs 10# CRUNCH_PROGS: lists programs to be included 11# CRUNCH_LIBS: libraries to statically link with 12# CRUNCH_SHLIBS: libraries to dynamically link with 13# CRUNCH_BUILDOPTS: generic build options to be added to every program 14# CRUNCH_BUILDTOOLS: lists programs that need build tools built in the 15# local architecture. 16# 17# Special options can be specified for individual programs 18# CRUNCH_SRCDIR_${P}: base source directory for program ${P} 19# CRUNCH_BUILDOPTS_${P}: additional build options for ${P} 20# CRUNCH_ALIAS_${P}: additional names to be used for ${P} 21# 22# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P} 23# will be used to generate a hard link to the resulting binary. 24# Specific links can be suppressed by setting 25# CRUNCH_SUPPRESS_LINK_${NAME} to 1. 26# 27# If CRUNCH_GENERATE_LINKS is set to no, no links will be generated. 28# 29 30# $FreeBSD$ 31 32################################################################## 33# The following is pretty nearly a generic crunchgen-handling makefile 34# 35 36CONF= ${PROG}.conf 37OUTMK= ${PROG}.mk 38OUTC= ${PROG}.c 39OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache 40CRUNCHOBJS= ${.OBJDIR} 41CRUNCH_GENERATE_LINKS?= yes 42 43CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h 44 45# Don't try to extract debug info from ${PROG}. 46MK_DEBUG_FILES= no 47 48# Set a default SRCDIR for each for simpler handling below. 49.for D in ${CRUNCH_SRCDIRS} 50.for P in ${CRUNCH_PROGS_${D}} 51CRUNCH_SRCDIR_${P}?= ${.CURDIR}/../../${D}/${P} 52.endfor 53.endfor 54 55# Program names and their aliases contribute hardlinks to 'rescue' executable, 56# except for those that get suppressed. 57.for D in ${CRUNCH_SRCDIRS} 58.for P in ${CRUNCH_PROGS_${D}} 59${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile 60.if ${CRUNCH_GENERATE_LINKS} == "yes" 61.ifndef CRUNCH_SUPPRESS_LINK_${P} 62LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P} 63.endif 64.for A in ${CRUNCH_ALIAS_${P}} 65.ifndef CRUNCH_SUPPRESS_LINK_${A} 66LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A} 67.endif 68.endfor 69.endif 70.endfor 71.endfor 72 73all: ${PROG} 74exe: ${PROG} 75 76${CONF}: Makefile 77 echo \# Auto-generated, do not edit >${.TARGET} 78.ifdef CRUNCH_BUILDOPTS 79 echo buildopts ${CRUNCH_BUILDOPTS} >>${.TARGET} 80.endif 81.ifdef CRUNCH_LIBS 82 echo libs ${CRUNCH_LIBS} >>${.TARGET} 83.endif 84.ifdef CRUNCH_SHLIBS 85 echo libs_so ${CRUNCH_SHLIBS} >>${.TARGET} 86.endif 87.for D in ${CRUNCH_SRCDIRS} 88.for P in ${CRUNCH_PROGS_${D}} 89 echo progs ${P} >>${.TARGET} 90 echo special ${P} srcdir ${CRUNCH_SRCDIR_${P}} >>${.TARGET} 91.ifdef CRUNCH_BUILDOPTS_${P} 92 echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ \ 93 ${CRUNCH_BUILDOPTS_${P}} >>${.TARGET} 94.else 95 echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ >>${.TARGET} 96.endif 97.for A in ${CRUNCH_ALIAS_${P}} 98 echo ln ${P} ${A} >>${.TARGET} 99.endfor 100.endfor 101.endfor 102 103CRUNCHGEN?= crunchgen 104CRUNCHENV?= MK_TESTS=no 105.ORDER: ${OUTPUTS} objs 106${OUTPUTS}: ${CONF} .META 107 MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${CRUNCHGEN} -fq \ 108 -m ${OUTMK} -c ${OUTC} ${CONF} 109 110# These 2 targets cannot use .MAKE since they depend on the generated 111# ${OUTMK} above. 112${PROG}: ${OUTPUTS} objs 113 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f ${OUTMK} exe 114 115objs: ${OUTMK} 116 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f ${OUTMK} objs 117 118# <sigh> Someone should replace the bin/csh and bin/sh build-tools with 119# shell scripts so we can remove this nonsense. 120.for _tool in ${CRUNCH_BUILDTOOLS} 121build-tools-${_tool}: 122 ${_+_}cd ${.CURDIR}/../../${_tool}; \ 123 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \ 124 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools 125build-tools: build-tools-${_tool} 126.endfor 127 128# Use a separate build tree to hold files compiled for this crunchgen binary 129# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't 130# get that to cooperate with bsd.prog.mk. Besides, many of the standard 131# targets should NOT be propagated into the components. 132.for __target in clean cleandepend cleandir obj objlink 133.for D in ${CRUNCH_SRCDIRS} 134.for P in ${CRUNCH_PROGS_${D}} 135${__target}_crunchdir_${P}: .PHONY .MAKE 136 ${_+_}cd ${CRUNCH_SRCDIR_${P}} && \ 137 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 138 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target} 139${__target}: ${__target}_crunchdir_${P} 140.endfor 141.endfor 142.endfor 143 144clean: 145 rm -f ${CLEANFILES} 146 ${_+_}if [ -e ${.OBJDIR}/${OUTMK} ]; then \ 147 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} \ 148 -f ${OUTMK} clean; \ 149 fi 150