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_BUILDOPTS Build options to be added for every program
12 # CRUNCH_CFLAGS Compiler flags to be added for every program
13 # CRUNCH_LINKOPTS Options to be added for linking the final binary
15 # Special options can be specified for individual programs:
17 # CRUNCH_SRCDIR_${P} Base source directory for program ${P}
18 # CRUNCH_BUILDOPTS_${P} Additional build options for ${P}
19 # CRUNCH_CFLAGS_${P} Additional compiler flags 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/soft 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', then no links will be generated.
28 # If CRUNCH_USE_SYMLINKS is defined, then soft links will be used instead
32 # $FreeBSD: head/share/mk/bsd.crunchgen.mk 305257 2016-09-01 23:52:20Z bdrewery $
38 OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
39 CRUNCHOBJS= ${.OBJDIR}
40 CRUNCH_GENERATE_LINKS?= yes
41 CRUNCH_LINKTYPE?= hard
42 .if defined(CRUNCH_USE_SYMLINKS)
46 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
48 # Set a default SRCDIR for each for simpler handling below.
49 .for D in ${CRUNCH_SRCDIRS}
50 .for P in ${CRUNCH_PROGS_${D}}
51 CRUNCH_SRCDIR_${P}?= ${CRUNCH_PATH_${D}}/${D}/${P}
55 # Program names and their aliases that contribute links to crunched
56 # executable, except for the suppressed ones.
57 .for D in ${CRUNCH_SRCDIRS}
58 .for P in ${CRUNCH_PROGS_${D}}
59 ${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile
60 .if ${CRUNCH_GENERATE_LINKS} == "yes"
61 .ifndef CRUNCH_SUPPRESS_LINK_${P}
62 .if ${CRUNCH_LINKTYPE} == "soft"
63 SYMLINKS+= ${PROG} ${BINDIR}/${P}
65 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
67 .endif # !CRUNCH_SUPPRESS_LINK_${P}
68 .for A in ${CRUNCH_ALIAS_${P}}
69 .ifndef CRUNCH_SUPPRESS_LINK_${A}
70 .if ${CRUNCH_LINKTYPE} == "soft"
71 SYMLINKS+= ${PROG} ${BINDIR}/${A}
73 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
75 .endif # !CRUNCH_SUPPRESS_LINK_${A}
76 .endfor # CRUNCH_ALIAS_${P}
77 .endif # CRUNCH_GENERATE_LINKS
78 .endfor # CRUNCH_PROGS_${D}
79 .endfor # CRUNCH_SRCDIRS
81 .if !defined(_SKIP_BUILD)
87 echo "# Auto-generated, do not edit" >${.TARGET}
88 .ifdef CRUNCH_BUILDOPTS
89 echo "buildopts ${CRUNCH_BUILDOPTS}" >>${.TARGET}
92 echo "buildopts CRUNCH_CFLAGS=\"${CRUNCH_CFLAGS}\"" >>${.TARGET}
94 .ifdef CRUNCH_LINKOPTS
95 echo "linkopts ${CRUNCH_LINKOPTS}" >>${.TARGET}
98 echo "libs ${CRUNCH_LIBS}" >>${.TARGET}
101 echo "libs_so ${CRUNCH_SHLIBS}" >>${.TARGET}
103 .for D in ${CRUNCH_SRCDIRS}
104 .for P in ${CRUNCH_PROGS_${D}}
105 echo "progs ${P}" >>${.TARGET}
106 echo "special ${P} srcdir ${CRUNCH_SRCDIR_${P}}" >>${.TARGET}
107 .ifdef CRUNCH_CFLAGS_${P}
108 echo "special ${P} buildopts \
109 DIRPRFX=${DIRPRFX}${P}/ \
110 ${CRUNCH_BUILDOPTS_${P}} \
111 CRUNCH_CFLAGS=\"${CRUNCH_CFLAGS_${P}}\"" >>${.TARGET}
113 echo "special ${P} buildopts \
114 DIRPRFX=${DIRPRFX}${P}/ \
115 ${CRUNCH_BUILDOPTS_${P}}" >>${.TARGET}
117 .ifdef CRUNCH_KEEP_${P}
118 echo "special ${P} keep ${CRUNCH_KEEP_${P}}" >>${.TARGET}
120 .for A in ${CRUNCH_ALIAS_${P}}
121 echo "ln ${P} ${A}" >>${.TARGET}
126 CRUNCHGEN?= crunchgen
128 .ORDER: ${OUTPUTS} objs
129 ${OUTPUTS:[1]}: .META
130 ${OUTPUTS:[2..-1]}: .NOMETA
132 MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
133 ${CRUNCHGEN} -fq -m ${OUTMK} -c ${OUTC} ${CONF}
134 # Avoid redundantly calling 'make objs' which we've done by our
136 sed -i '' -e "/^${PROG}:/s/\$$[({]SUBMAKE_TARGETS[})]//" ${OUTMK}
138 # These 2 targets cannot use .MAKE since they depend on the generated
140 ${PROG}: ${OUTPUTS} objs .NOMETA .PHONY
141 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
142 ${MAKE} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \
143 .MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \
147 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
148 ${MAKE} -f ${OUTMK} objs
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 __targets= clean cleandepend cleandir obj objlink depend
155 .for __target in ${__targets}
156 .for D in ${CRUNCH_SRCDIRS}
157 .for P in ${CRUNCH_PROGS_${D}}
158 ${__target}_crunchdir_${P}: .PHONY .MAKE
159 (cd ${CRUNCH_SRCDIR_${P}} && \
160 ${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} \
171 ${MAKE} -f ${OUTMK} clean; \
174 .ORDER: ${__targets} all install