1# 2# Generate crunched binaries using crunchgen(1). 3# 4# Make variables used to generate the crunchgen(1) config file: 5# 6# CRUNCH_SRCDIRS Directories to search for included programs 7# CRUNCH_PATH_${D} Path to the source directory ${D} 8# CRUNCH_PROGS_${D} Programs to be included inside directory ${D} 9# CRUNCH_LIBS Libraries to be statically linked with 10# CRUNCH_SHLIBS Libraries to be dynamically linked with 11# CRUNCH_BUILDOPTS Build options to be added for every program 12# 13# Special options can be specified for individual programs: 14# 15# CRUNCH_SRCDIR_${P} Base source directory for program ${P} 16# CRUNCH_BUILDOPTS_${P} Additional build options for ${P} 17# CRUNCH_ALIAS_${P} Additional names to be used for ${P} 18# 19# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P} 20# will be used to generate a hard/soft link to the resulting binary. 21# Specific links can be suppressed by setting 22# CRUNCH_SUPPRESS_LINK_${NAME} to 1. 23# 24# If CRUNCH_GENERATE_LINKS is set to 'no', then no links will be generated. 25# If CRUNCH_USE_SYMLINKS is defined, then soft links will be used instead 26# of hard links. 27# 28 29# $FreeBSD: head/share/mk/bsd.crunchgen.mk 305257 2016-09-01 23:52:20Z bdrewery $ 30 31 32CONF= ${PROG}.conf 33OUTMK= ${PROG}.mk 34OUTC= ${PROG}.c 35OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache 36CRUNCHOBJS= ${.OBJDIR} 37CRUNCH_GENERATE_LINKS?= yes 38CRUNCH_LINKTYPE?= hard 39.if defined(CRUNCH_USE_SYMLINKS) 40CRUNCH_LINKTYPE= soft 41.endif 42 43CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h 44 45# Set a default SRCDIR for each for simpler handling below. 46.for D in ${CRUNCH_SRCDIRS} 47.for P in ${CRUNCH_PROGS_${D}} 48CRUNCH_SRCDIR_${P}?= ${CRUNCH_PATH_${D}}/${D}/${P} 49.endfor 50.endfor 51 52# Program names and their aliases that contribute links to crunched 53# executable, except for the suppressed ones. 54.for D in ${CRUNCH_SRCDIRS} 55.for P in ${CRUNCH_PROGS_${D}} 56${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile 57.if ${CRUNCH_GENERATE_LINKS} == "yes" 58.ifndef CRUNCH_SUPPRESS_LINK_${P} 59.if ${CRUNCH_LINKTYPE} == "soft" 60SYMLINKS+= ${PROG} ${BINDIR}/${P} 61.else 62LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P} 63.endif 64.endif # !CRUNCH_SUPPRESS_LINK_${P} 65.for A in ${CRUNCH_ALIAS_${P}} 66.ifndef CRUNCH_SUPPRESS_LINK_${A} 67.if ${CRUNCH_LINKTYPE} == "soft" 68SYMLINKS+= ${PROG} ${BINDIR}/${A} 69.else 70LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A} 71.endif 72.endif # !CRUNCH_SUPPRESS_LINK_${A} 73.endfor # CRUNCH_ALIAS_${P} 74.endif # CRUNCH_GENERATE_LINKS 75.endfor # CRUNCH_PROGS_${D} 76.endfor # CRUNCH_SRCDIRS 77 78.if !defined(_SKIP_BUILD) 79all: ${PROG} 80.endif 81exe: ${PROG} 82 83${CONF}: Makefile 84 echo "# Auto-generated, do not edit" >${.TARGET} 85.ifdef CRUNCH_BUILDOPTS 86 echo "buildopts ${CRUNCH_BUILDOPTS}" >>${.TARGET} 87.endif 88.ifdef CRUNCH_LIBS 89 echo "libs ${CRUNCH_LIBS}" >>${.TARGET} 90.endif 91.ifdef CRUNCH_SHLIBS 92 echo "libs_so ${CRUNCH_SHLIBS}" >>${.TARGET} 93.endif 94.for D in ${CRUNCH_SRCDIRS} 95.for P in ${CRUNCH_PROGS_${D}} 96 echo "progs ${P}" >>${.TARGET} 97 echo "special ${P} srcdir ${CRUNCH_SRCDIR_${P}}" >>${.TARGET} 98.ifdef CRUNCH_BUILDOPTS_${P} 99 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS_${P}}" >>${.TARGET} 100.else 101 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/" >>${.TARGET} 102.endif 103.ifdef CRUNCH_KEEP_${P} 104 echo "special ${P} keep ${CRUNCH_KEEP_${P}}" >>${.TARGET} 105.endif 106.for A in ${CRUNCH_ALIAS_${P}} 107 echo "ln ${P} ${A}" >>${.TARGET} 108.endfor 109.endfor 110.endfor 111 112CRUNCHGEN?= crunchgen 113CRUNCHENV?= # empty 114.ORDER: ${OUTPUTS} objs 115${OUTPUTS:[1]}: .META 116${OUTPUTS:[2..-1]}: .NOMETA 117${OUTPUTS}: ${CONF} 118 MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 119 ${CRUNCHGEN} -fq -m ${OUTMK} -c ${OUTC} ${CONF} 120 # Avoid redundantly calling 'make objs' which we've done by our 121 # own dependencies. 122 sed -i '' -e "s/^\(${PROG}:.*\) \$$(SUBMAKE_TARGETS)/\1/" ${OUTMK} 123 124# These 2 targets cannot use .MAKE since they depend on the generated 125# ${OUTMK} above. 126${PROG}: ${OUTPUTS} objs .NOMETA .PHONY 127 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 128 ${MAKE} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \ 129 .MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \ 130 -f ${OUTMK} exe 131 132objs: ${OUTMK} .META 133 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 134 ${MAKE} -f ${OUTMK} objs 135 136# Use a separate build tree to hold files compiled for this crunchgen binary 137# Yes, this does seem to partly duplicate <bsd.subdir.mk>, but I can't 138# get that to cooperate with <bsd.prog.mk>. Besides, many of the standard 139# targets should NOT be propagated into the components. 140__targets= clean cleandepend cleandir obj objlink depend 141.for __target in ${__targets} 142.for D in ${CRUNCH_SRCDIRS} 143.for P in ${CRUNCH_PROGS_${D}} 144${__target}_crunchdir_${P}: .PHONY .MAKE 145 (cd ${CRUNCH_SRCDIR_${P}} && \ 146 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 147 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target}) 148${__target}: ${__target}_crunchdir_${P} 149.endfor 150.endfor 151.endfor 152 153clean: 154 rm -f ${CLEANFILES} 155 if [ -e ${.OBJDIR}/${OUTMK} ]; then \ 156 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 157 ${MAKE} -f ${OUTMK} clean; \ 158 fi 159 160.ORDER: ${__targets} all install 161