1 #################################################################
3 # Generate crunched binaries using crunchgen(1).
7 # A number of Make variables are used to generate the crunchgen config file.
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
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}
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.
27 # If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
32 ##################################################################
33 # The following is pretty nearly a generic crunchgen-handling makefile
39 OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
40 CRUNCHOBJS= ${.OBJDIR}
41 CRUNCH_GENERATE_LINKS?= yes
42 # Don't let the prog.mk use MK_AUTO_OBJ, but do let the component builds use
44 CRUNCHARGS+= MK_AUTO_OBJ=no
45 CRUNCH_BUILDOPTS+= MK_AUTO_OBJ=${MK_AUTO_OBJ}
47 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
49 # Don't try to extract debug info from ${PROG}.
52 # Set a default SRCDIR for each for simpler handling below.
53 .for D in ${CRUNCH_SRCDIRS}
54 .for P in ${CRUNCH_PROGS_${D}}
55 CRUNCH_SRCDIR_${P}?= ${.CURDIR}/../../${D}/${P}
59 # Program names and their aliases contribute hardlinks to 'rescue' executable,
60 # except for those that get suppressed.
61 .for D in ${CRUNCH_SRCDIRS}
62 .for P in ${CRUNCH_PROGS_${D}}
63 ${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile
64 .if ${CRUNCH_GENERATE_LINKS} == "yes"
65 .ifndef CRUNCH_SUPPRESS_LINK_${P}
66 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
68 .for A in ${CRUNCH_ALIAS_${P}}
69 .ifndef CRUNCH_SUPPRESS_LINK_${A}
70 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
77 .if !defined(_SKIP_BUILD)
83 echo \# Auto-generated, do not edit >${.TARGET}
84 .ifdef CRUNCH_BUILDOPTS
85 echo buildopts ${CRUNCH_BUILDOPTS} >>${.TARGET}
88 echo libs ${CRUNCH_LIBS} >>${.TARGET}
91 echo libs_so ${CRUNCH_SHLIBS} >>${.TARGET}
93 .for D in ${CRUNCH_SRCDIRS}
94 .for P in ${CRUNCH_PROGS_${D}}
95 echo progs ${P} >>${.TARGET}
96 echo special ${P} srcdir ${CRUNCH_SRCDIR_${P}} >>${.TARGET}
97 .ifdef CRUNCH_BUILDOPTS_${P}
98 echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ \
99 ${CRUNCH_BUILDOPTS_${P}} >>${.TARGET}
101 echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ >>${.TARGET}
103 .for A in ${CRUNCH_ALIAS_${P}}
104 echo ln ${P} ${A} >>${.TARGET}
109 CRUNCHGEN?= crunchgen
110 CRUNCHENV+= MK_TESTS=no \
111 UPDATE_DEPENDFILE=no \
113 .ORDER: ${OUTPUTS} objs
114 ${OUTPUTS:[1]}: .META
115 ${OUTPUTS:[2..-1]}: .NOMETA
117 MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
118 MK_AUTO_OBJ=${MK_AUTO_OBJ} \
119 ${CRUNCHGEN} -fq -m ${OUTMK} -c ${OUTC} ${CONF}
120 # Avoid redundantly calling 'make objs' which we've done by our
122 sed -i '' -e "s/^\(${PROG}:.*\) \$$(SUBMAKE_TARGETS)/\1/" ${OUTMK}
124 # These 2 targets cannot use .MAKE since they depend on the generated
126 ${PROG}: ${OUTPUTS} objs .NOMETA .PHONY
128 CC="${CC} ${CFLAGS} ${LDFLAGS}" \
129 CXX="${CXX} ${CXXFLAGS} ${LDFLAGS}" \
130 ${MAKE} ${CRUNCHARGS} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \
131 .MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \
135 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
136 ${MAKE} -f ${OUTMK} ${CRUNCHARGS} BUILD_TOOLS_META=.NOMETA objs
138 # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
139 # shell scripts so we can remove this nonsense.
140 .for _tool in ${CRUNCH_BUILDTOOLS}
141 build-tools-${_tool}:
142 ${_+_}cd ${.CURDIR}/../../${_tool}; \
143 if [ "${MK_AUTO_OBJ}" = "no" ]; then \
144 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
146 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
147 build-tools: build-tools-${_tool}
150 # Use a separate build tree to hold files compiled for this crunchgen binary
151 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
152 # get that to cooperate with bsd.prog.mk. Besides, many of the standard
153 # targets should NOT be propagated into the components.
154 .for __target in clean cleandepend cleandir obj objlink
155 .for D in ${CRUNCH_SRCDIRS}
156 .for P in ${CRUNCH_PROGS_${D}}
157 ${__target}_crunchdir_${P}: .PHONY .MAKE
158 ${_+_}cd ${CRUNCH_SRCDIR_${P}} && \
159 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
161 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target}
162 ${__target}: ${__target}_crunchdir_${P}
169 ${_+_}if [ -e ${.OBJDIR}/${OUTMK} ]; then \
170 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} \
174 META_XTRAS+= ${find ${CRUNCHOBJS}${SRCTOP} -name '*.meta' 2>/dev/null || true:L:sh}
175 META_XTRAS+= ${echo ${CRUNCHOBJS}/*.lo.meta 2>/dev/null || true:L:sh}
176 META_XTRAS+= ${PROG}.meta