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_INTLIBS Internal libraries to be built and linked with 12# CRUNCH_BUILDOPTS Build options to be added for every program 13# CRUNCH_CFLAGS Compiler flags to be added for every program 14# CRUNCH_LINKOPTS Options to be added for linking the final binary 15# 16# Special options can be specified for individual programs: 17# 18# CRUNCH_SRCDIR_${P} Base source directory for program ${P} 19# CRUNCH_BUILDOPTS_${P} Additional build options for ${P} 20# CRUNCH_CFLAGS_${P} Additional compiler flags for ${P} 21# CRUNCH_ALIAS_${P} Additional names to be used for ${P} 22# CRUNCH_LIB_${P} Additional libraries to be statically linked for ${P} 23# CRUNCH_INTLIB_${P} Additional internal libraries to be built 24# and statically linked for ${P} 25# CRUNCH_KEEP_${P} Additional symbols to be kept for ${P} 26# 27# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P} 28# will be used to generate a hard/soft link to the resulting binary. 29# Specific links can be suppressed by setting 30# CRUNCH_SUPPRESS_LINK_${NAME} to 1. 31# 32# If CRUNCH_GENERATE_LINKS is set to 'no', then no links will be generated. 33# If CRUNCH_USE_SYMLINKS is defined, then soft links will be used instead 34# of hard links. 35# 36 37# $FreeBSD: head/share/mk/bsd.crunchgen.mk 305257 2016-09-01 23:52:20Z bdrewery $ 38 39 40CONF= ${PROG}.conf 41OUTMK= ${PROG}.mk 42OUTC= ${PROG}.c 43OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache 44CRUNCHOBJS= ${.OBJDIR} 45CRUNCH_GENERATE_LINKS?= yes 46CRUNCH_LINKTYPE?= hard 47.if defined(CRUNCH_USE_SYMLINKS) 48CRUNCH_LINKTYPE= soft 49.endif 50 51CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h 52 53# Set a default SRCDIR for each for simpler handling below. 54.for D in ${CRUNCH_SRCDIRS} 55.for P in ${CRUNCH_PROGS_${D}} 56CRUNCH_SRCDIR_${P}?= ${CRUNCH_PATH_${D}}/${D}/${P} 57.endfor 58.endfor 59 60# Program names and their aliases that contribute links to crunched 61# executable, except for the suppressed ones. 62.for D in ${CRUNCH_SRCDIRS} 63.for P in ${CRUNCH_PROGS_${D}} 64${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile 65.if ${CRUNCH_GENERATE_LINKS} == "yes" 66.ifndef CRUNCH_SUPPRESS_LINK_${P} 67.if ${CRUNCH_LINKTYPE} == "soft" 68SYMLINKS+= ${PROG} ${BINDIR}/${P} 69.else 70LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P} 71.endif 72.endif # !CRUNCH_SUPPRESS_LINK_${P} 73.for A in ${CRUNCH_ALIAS_${P}} 74.ifndef CRUNCH_SUPPRESS_LINK_${A} 75.if ${CRUNCH_LINKTYPE} == "soft" 76SYMLINKS+= ${PROG} ${BINDIR}/${A} 77.else 78LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A} 79.endif 80.endif # !CRUNCH_SUPPRESS_LINK_${A} 81.endfor # CRUNCH_ALIAS_${P} 82.endif # CRUNCH_GENERATE_LINKS 83.endfor # CRUNCH_PROGS_${D} 84.endfor # CRUNCH_SRCDIRS 85 86.if !defined(_SKIP_BUILD) 87all: ${PROG} 88.endif 89exe: ${PROG} 90 91${CONF}: Makefile 92 echo "# Auto-generated, do not edit" >${.TARGET} 93.ifdef CRUNCH_BUILDOPTS 94 echo "buildopts ${CRUNCH_BUILDOPTS}" >>${.TARGET} 95.endif 96.ifdef CRUNCH_CFLAGS 97 echo "buildopts CRUNCH_CFLAGS=\"${CRUNCH_CFLAGS}\"" >>${.TARGET} 98.endif 99.ifdef CRUNCH_LINKOPTS 100 echo "linkopts ${CRUNCH_LINKOPTS}" >>${.TARGET} 101.endif 102.ifdef CRUNCH_LIBS 103 echo "libs ${CRUNCH_LIBS}" >>${.TARGET} 104.endif 105.ifdef CRUNCH_SHLIBS 106 echo "libs_so ${CRUNCH_SHLIBS}" >>${.TARGET} 107.endif 108.ifdef CRUNCH_INTLIBS 109 echo "libs_int ${CRUNCH_INTLIBS}" >>${.TARGET} 110.endif 111.for D in ${CRUNCH_SRCDIRS} 112.for P in ${CRUNCH_PROGS_${D}} 113 echo "progs ${P}" >>${.TARGET} 114 echo "special ${P} srcdir ${CRUNCH_SRCDIR_${P}}" >>${.TARGET} 115.ifdef CRUNCH_CFLAGS_${P} 116 echo "special ${P} buildopts \ 117 DIRPRFX=${DIRPRFX}${P}/ \ 118 ${CRUNCH_BUILDOPTS_${P}} \ 119 CRUNCH_CFLAGS=\"${CRUNCH_CFLAGS_${P}}\"" >>${.TARGET} 120.else 121 echo "special ${P} buildopts \ 122 DIRPRFX=${DIRPRFX}${P}/ \ 123 ${CRUNCH_BUILDOPTS_${P}}" >>${.TARGET} 124.endif 125.ifdef CRUNCH_LIB_${P} 126 echo "special ${P} lib ${CRUNCH_LIB_${P}}" >>${.TARGET} 127.endif 128.ifdef CRUNCH_INTLIB_${P} 129 echo "special ${P} lib_int ${CRUNCH_INTLIB_${P}}" >>${.TARGET} 130.endif 131.ifdef CRUNCH_KEEP_${P} 132 echo "special ${P} keep ${CRUNCH_KEEP_${P}}" >>${.TARGET} 133.endif 134.for A in ${CRUNCH_ALIAS_${P}} 135 echo "ln ${P} ${A}" >>${.TARGET} 136.endfor 137.endfor # CRUNCH_PROGS_${D} 138.endfor # CRUNCH_SRCDIRS 139 140CRUNCHGEN?= crunchgen 141CRUNCHENV?= # empty 142.ORDER: ${OUTPUTS} objs 143${OUTPUTS:[1]}: .META 144${OUTPUTS:[2..-1]}: .NOMETA 145${OUTPUTS}: ${CONF} 146 MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 147 ${CRUNCHGEN} -fq -m ${OUTMK} -c ${OUTC} ${CONF} 148 # Avoid redundantly calling 'make objs' which we've done by our 149 # own dependencies. 150 sed -i '' -e "/^${PROG}:/s/\$$[({]SUBMAKE_TARGETS[})]//" ${OUTMK} 151 152# These 2 targets cannot use .MAKE since they depend on the generated 153# ${OUTMK} above. 154${PROG}: ${OUTPUTS} objs .NOMETA .PHONY 155 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 156 ${MAKE} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \ 157 .MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \ 158 -f ${OUTMK} exe 159 160objs: ${OUTMK} .META 161 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 162 ${MAKE} -f ${OUTMK} objs 163 164# Use a separate build tree to hold files compiled for this crunchgen binary 165# Yes, this does seem to partly duplicate <bsd.subdir.mk>, but I can't 166# get that to cooperate with <bsd.prog.mk>. Besides, many of the standard 167# targets should NOT be propagated into the components. 168__targets= clean cleandepend cleandir obj objlink depend 169.for __target in ${__targets} 170.for D in ${CRUNCH_SRCDIRS} 171.for P in ${CRUNCH_PROGS_${D}} 172${__target}_crunchdir_${P}: .PHONY .MAKE 173 (cd ${CRUNCH_SRCDIR_${P}} && \ 174 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 175 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target}) 176${__target}: ${__target}_crunchdir_${P} 177.endfor 178.endfor 179.endfor 180 181# Internal libraires 182_CRUNCH_INTLIBS= ${CRUNCH_INTLIBS} 183.for D in ${CRUNCH_SRCDIRS} 184.for P in ${CRUNCH_PROGS_${D}} 185_CRUNCH_INTLIBS+= ${CRUNCH_INTLIB_${P}} 186.endfor 187.endfor 188_CRUNCH_INTLIBS:= ${_CRUNCH_INTLIBS:O:u} # remove duplicates 189 190.for __target in ${__targets} 191.for L in ${_CRUNCH_INTLIBS} 192${__target}_crunchdir_${L:T}: .PHONY .MAKE 193 (cd ${L:H} && \ 194 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 195 DIRPRFX=${DIRPRFX}${L:T}/ ${CRUNCH_BUILDOPTS} ${__target}) 196${__target}: ${__target}_crunchdir_${L:T} 197.endfor 198.endfor 199 200clean: 201 rm -f ${CLEANFILES} 202 if [ -e ${.OBJDIR}/${OUTMK} ]; then \ 203 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \ 204 ${MAKE} -f ${OUTMK} clean; \ 205 fi 206 207.ORDER: ${__targets} all install 208