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_LINKOPTS Options to be added for linking the final binary
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/soft 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.
26 # If CRUNCH_USE_SYMLINKS is defined, then soft links will be used instead
30 # $FreeBSD: head/share/mk/bsd.crunchgen.mk 305257 2016-09-01 23:52:20Z bdrewery $
36 OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
37 CRUNCHOBJS= ${.OBJDIR}
38 CRUNCH_GENERATE_LINKS?= yes
39 CRUNCH_LINKTYPE?= hard
40 .if defined(CRUNCH_USE_SYMLINKS)
44 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
46 # Set a default SRCDIR for each for simpler handling below.
47 .for D in ${CRUNCH_SRCDIRS}
48 .for P in ${CRUNCH_PROGS_${D}}
49 CRUNCH_SRCDIR_${P}?= ${CRUNCH_PATH_${D}}/${D}/${P}
53 # Program names and their aliases that contribute links to crunched
54 # executable, except for the suppressed ones.
55 .for D in ${CRUNCH_SRCDIRS}
56 .for P in ${CRUNCH_PROGS_${D}}
57 ${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile
58 .if ${CRUNCH_GENERATE_LINKS} == "yes"
59 .ifndef CRUNCH_SUPPRESS_LINK_${P}
60 .if ${CRUNCH_LINKTYPE} == "soft"
61 SYMLINKS+= ${PROG} ${BINDIR}/${P}
63 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
65 .endif # !CRUNCH_SUPPRESS_LINK_${P}
66 .for A in ${CRUNCH_ALIAS_${P}}
67 .ifndef CRUNCH_SUPPRESS_LINK_${A}
68 .if ${CRUNCH_LINKTYPE} == "soft"
69 SYMLINKS+= ${PROG} ${BINDIR}/${A}
71 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
73 .endif # !CRUNCH_SUPPRESS_LINK_${A}
74 .endfor # CRUNCH_ALIAS_${P}
75 .endif # CRUNCH_GENERATE_LINKS
76 .endfor # CRUNCH_PROGS_${D}
77 .endfor # CRUNCH_SRCDIRS
79 .if !defined(_SKIP_BUILD)
85 echo "# Auto-generated, do not edit" >${.TARGET}
86 .ifdef CRUNCH_BUILDOPTS
87 echo "buildopts ${CRUNCH_BUILDOPTS}" >>${.TARGET}
89 .ifdef CRUNCH_LINKOPTS
90 echo "linkopts ${CRUNCH_LINKOPTS}" >>${.TARGET}
93 echo "libs ${CRUNCH_LIBS}" >>${.TARGET}
96 echo "libs_so ${CRUNCH_SHLIBS}" >>${.TARGET}
98 .for D in ${CRUNCH_SRCDIRS}
99 .for P in ${CRUNCH_PROGS_${D}}
100 echo "progs ${P}" >>${.TARGET}
101 echo "special ${P} srcdir ${CRUNCH_SRCDIR_${P}}" >>${.TARGET}
102 .ifdef CRUNCH_BUILDOPTS_${P}
103 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS_${P}}" >>${.TARGET}
105 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/" >>${.TARGET}
107 .ifdef CRUNCH_KEEP_${P}
108 echo "special ${P} keep ${CRUNCH_KEEP_${P}}" >>${.TARGET}
110 .for A in ${CRUNCH_ALIAS_${P}}
111 echo "ln ${P} ${A}" >>${.TARGET}
116 CRUNCHGEN?= crunchgen
118 .ORDER: ${OUTPUTS} objs
119 ${OUTPUTS:[1]}: .META
120 ${OUTPUTS:[2..-1]}: .NOMETA
122 MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
123 ${CRUNCHGEN} -fq -m ${OUTMK} -c ${OUTC} ${CONF}
124 # Avoid redundantly calling 'make objs' which we've done by our
126 sed -i '' -e "/^${PROG}:/s/\$$[({]SUBMAKE_TARGETS[})]//" ${OUTMK}
128 # These 2 targets cannot use .MAKE since they depend on the generated
130 ${PROG}: ${OUTPUTS} objs .NOMETA .PHONY
131 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
132 ${MAKE} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \
133 .MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \
137 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
138 ${MAKE} -f ${OUTMK} objs
140 # Use a separate build tree to hold files compiled for this crunchgen binary
141 # Yes, this does seem to partly duplicate <bsd.subdir.mk>, but I can't
142 # get that to cooperate with <bsd.prog.mk>. Besides, many of the standard
143 # targets should NOT be propagated into the components.
144 __targets= clean cleandepend cleandir obj objlink depend
145 .for __target in ${__targets}
146 .for D in ${CRUNCH_SRCDIRS}
147 .for P in ${CRUNCH_PROGS_${D}}
148 ${__target}_crunchdir_${P}: .PHONY .MAKE
149 (cd ${CRUNCH_SRCDIR_${P}} && \
150 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
151 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target})
152 ${__target}: ${__target}_crunchdir_${P}
159 if [ -e ${.OBJDIR}/${OUTMK} ]; then \
160 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
161 ${MAKE} -f ${OUTMK} clean; \
164 .ORDER: ${__targets} all install