2 # Generate crunched binaries using crunchgen(1).
4 # Make variables used to generate the crunchgen(1) config file:
6 # CRUNCH_SRCDIRS Directories to search for included programs
7 # CRUNCH_PROGS Programs to be included
8 # CRUNCH_LIBS Libraries to be statically linked with
9 # CRUNCH_SHLIBS Libraries to be dynamically linked with
10 # CRUNCH_BUILDOPTS Build options to be added for every program
11 # CRUNCH_BUILDTOOLS Programs that need build tools built in the
14 # Special options can be specified for individual programs:
16 # CRUNCH_SRCDIR_${P} Base source directory for program ${P}
17 # CRUNCH_BUILDOPTS_${P} Additional build options for ${P}
18 # CRUNCH_ALIAS_${P} Additional names to be used for ${P}
20 # By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
21 # will be used to generate a hard link to the resulting binary.
22 # Specific links can be suppressed by setting
23 # CRUNCH_SUPPRESS_LINK_${NAME} to 1.
25 # If CRUNCH_GENERATE_LINKS is set to 'no', then no links will be generated.
28 # $FreeBSD: head/share/mk/bsd.crunchgen.mk 305257 2016-09-01 23:52:20Z bdrewery $
34 OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
35 CRUNCHOBJS= ${.OBJDIR}
36 CRUNCH_GENERATE_LINKS?= yes
38 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
40 # Set a default SRCDIR for each for simpler handling below.
41 .for D in ${CRUNCH_SRCDIRS}
42 .for P in ${CRUNCH_PROGS_${D}}
43 CRUNCH_SRCDIR_${P}?= ${.CURDIR}/../../${D}/${P}
47 # Program names and their aliases contribute hardlinks to 'rescue' executable,
48 # except for those that get suppressed.
49 .for D in ${CRUNCH_SRCDIRS}
50 .for P in ${CRUNCH_PROGS_${D}}
51 ${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile
52 .if ${CRUNCH_GENERATE_LINKS} == "yes"
53 .ifndef CRUNCH_SUPPRESS_LINK_${P}
54 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
56 .for A in ${CRUNCH_ALIAS_${P}}
57 .ifndef CRUNCH_SUPPRESS_LINK_${A}
58 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
65 .if !defined(_SKIP_BUILD)
71 echo "# Auto-generated, do not edit" >${.TARGET}
72 .ifdef CRUNCH_BUILDOPTS
73 echo "buildopts ${CRUNCH_BUILDOPTS}" >>${.TARGET}
76 echo "libs ${CRUNCH_LIBS}" >>${.TARGET}
79 echo "libs_so ${CRUNCH_SHLIBS}" >>${.TARGET}
81 .for D in ${CRUNCH_SRCDIRS}
82 .for P in ${CRUNCH_PROGS_${D}}
83 echo "progs ${P}" >>${.TARGET}
84 echo "special ${P} srcdir ${CRUNCH_SRCDIR_${P}}" >>${.TARGET}
85 .ifdef CRUNCH_BUILDOPTS_${P}
86 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS_${P}}" >>${.TARGET}
88 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/" >>${.TARGET}
90 .ifdef CRUNCH_KEEP_${P}
91 echo "special ${P} keep ${CRUNCH_KEEP_${P}}" >>${.TARGET}
93 .for A in ${CRUNCH_ALIAS_${P}}
94 echo "ln ${P} ${A}" >>${.TARGET}
101 .ORDER: ${OUTPUTS} objs
102 ${OUTPUTS:[1]}: .META
103 ${OUTPUTS:[2..-1]}: .NOMETA
105 MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
106 ${CRUNCHGEN} -fq -m ${OUTMK} -c ${OUTC} ${CONF}
107 # Avoid redundantly calling 'make objs' which we've done by our
109 sed -i '' -e "s/^\(${PROG}:.*\) \$$(SUBMAKE_TARGETS)/\1/" ${OUTMK}
111 # These 2 targets cannot use .MAKE since they depend on the generated
113 ${PROG}: ${OUTPUTS} objs .NOMETA .PHONY
114 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
115 ${MAKE} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \
116 .MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \
120 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
121 ${MAKE} -f ${OUTMK} objs
123 # <sigh> Someone should replace the bin/csh build-tools with
124 # shell scripts so we can remove this nonsense.
125 .for _tool in ${CRUNCH_BUILDTOOLS}
126 build-tools-${_tool}:
127 ${_+_}cd ${.CURDIR}/../../../${_tool}; \
128 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
129 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
130 build-tools: build-tools-${_tool}
133 # Use a separate build tree to hold files compiled for this crunchgen binary
134 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
135 # get that to cooperate with bsd.prog.mk. Besides, many of the standard
136 # targets should NOT be propagated into the components.
137 .for __target in clean cleandepend cleandir obj objlink
138 .for D in ${CRUNCH_SRCDIRS}
139 .for P in ${CRUNCH_PROGS_${D}}
140 ${__target}_crunchdir_${P}: .PHONY .MAKE
141 ${_+_}cd ${CRUNCH_SRCDIR_${P}} && \
142 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
143 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target}
144 ${__target}: ${__target}_crunchdir_${P}
151 ${_+_}if [ -e ${.OBJDIR}/${OUTMK} ]; then \
152 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
153 ${MAKE} -f ${OUTMK} clean; \