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_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
16 # 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_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}
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.
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
37 # $FreeBSD: head/share/mk/bsd.crunchgen.mk 305257 2016-09-01 23:52:20Z bdrewery $
43 OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
44 CRUNCHOBJS= ${.OBJDIR}
45 CRUNCH_GENERATE_LINKS?= yes
46 CRUNCH_LINKTYPE?= hard
47 .if defined(CRUNCH_USE_SYMLINKS)
51 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
53 # Set a default SRCDIR for each for simpler handling below.
54 .for D in ${CRUNCH_SRCDIRS}
55 .for P in ${CRUNCH_PROGS_${D}}
56 CRUNCH_SRCDIR_${P}?= ${CRUNCH_PATH_${D}}/${D}/${P}
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"
68 SYMLINKS+= ${PROG} ${BINDIR}/${P}
70 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
72 .endif # !CRUNCH_SUPPRESS_LINK_${P}
73 .for A in ${CRUNCH_ALIAS_${P}}
74 .ifndef CRUNCH_SUPPRESS_LINK_${A}
75 .if ${CRUNCH_LINKTYPE} == "soft"
76 SYMLINKS+= ${PROG} ${BINDIR}/${A}
78 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
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
86 .if !defined(_SKIP_BUILD)
92 echo "# Auto-generated, do not edit" >${.TARGET}
93 .ifdef CRUNCH_BUILDOPTS
94 echo "buildopts ${CRUNCH_BUILDOPTS}" >>${.TARGET}
97 echo "buildopts CRUNCH_CFLAGS=\"${CRUNCH_CFLAGS}\"" >>${.TARGET}
99 .ifdef CRUNCH_LINKOPTS
100 echo "linkopts ${CRUNCH_LINKOPTS}" >>${.TARGET}
103 echo "libs ${CRUNCH_LIBS}" >>${.TARGET}
106 echo "libs_so ${CRUNCH_SHLIBS}" >>${.TARGET}
108 .ifdef CRUNCH_INTLIBS
109 echo "libs_int ${CRUNCH_INTLIBS}" >>${.TARGET}
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}
121 echo "special ${P} buildopts \
122 DIRPRFX=${DIRPRFX}${P}/ \
123 ${CRUNCH_BUILDOPTS_${P}}" >>${.TARGET}
125 .ifdef CRUNCH_LIB_${P}
126 echo "special ${P} lib ${CRUNCH_LIB_${P}}" >>${.TARGET}
128 .ifdef CRUNCH_INTLIB_${P}
129 echo "special ${P} lib_int ${CRUNCH_INTLIB_${P}}" >>${.TARGET}
131 .ifdef CRUNCH_KEEP_${P}
132 echo "special ${P} keep ${CRUNCH_KEEP_${P}}" >>${.TARGET}
134 .for A in ${CRUNCH_ALIAS_${P}}
135 echo "ln ${P} ${A}" >>${.TARGET}
137 .endfor # CRUNCH_PROGS_${D}
138 .endfor # CRUNCH_SRCDIRS
140 CRUNCHGEN?= crunchgen
142 .ORDER: ${OUTPUTS} objs
143 ${OUTPUTS:[1]}: .META
144 ${OUTPUTS:[2..-1]}: .NOMETA
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
150 sed -i '' -e "/^${PROG}:/s/\$$[({]SUBMAKE_TARGETS[})]//" ${OUTMK}
152 # These 2 targets cannot use .MAKE since they depend on the generated
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}" \
161 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
162 ${MAKE} -f ${OUTMK} objs
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}
182 _CRUNCH_INTLIBS= ${CRUNCH_INTLIBS}
183 .for D in ${CRUNCH_SRCDIRS}
184 .for P in ${CRUNCH_PROGS_${D}}
185 _CRUNCH_INTLIBS+= ${CRUNCH_INTLIB_${P}}
188 _CRUNCH_INTLIBS:= ${_CRUNCH_INTLIBS:O:u} # remove duplicates
190 .for __target in ${__targets}
191 .for L in ${_CRUNCH_INTLIBS}
192 ${__target}_crunchdir_${L:T}: .PHONY .MAKE
194 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
195 DIRPRFX=${DIRPRFX}${L:T}/ ${CRUNCH_BUILDOPTS} ${__target})
196 ${__target}: ${__target}_crunchdir_${L:T}
202 if [ -e ${.OBJDIR}/${OUTMK} ]; then \
203 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
204 ${MAKE} -f ${OUTMK} clean; \
207 .ORDER: ${__targets} all install