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
13 # Special options can be specified for individual programs:
15 # CRUNCH_SRCDIR_${P} Base source directory for program ${P}
16 # CRUNCH_BUILDOPTS_${P} Additional build options for ${P}
17 # CRUNCH_ALIAS_${P} Additional names to be used for ${P}
19 # By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
20 # will be used to generate a hard/soft link to the resulting binary.
21 # Specific links can be suppressed by setting
22 # CRUNCH_SUPPRESS_LINK_${NAME} to 1.
24 # If CRUNCH_GENERATE_LINKS is set to 'no', then no links will be generated.
25 # If CRUNCH_USE_SYMLINKS is defined, then soft links will be used instead
29 # $FreeBSD: head/share/mk/bsd.crunchgen.mk 305257 2016-09-01 23:52:20Z bdrewery $
35 OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
36 CRUNCHOBJS= ${.OBJDIR}
37 CRUNCH_GENERATE_LINKS?= yes
38 CRUNCH_LINKTYPE?= hard
39 .if defined(CRUNCH_USE_SYMLINKS)
43 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
45 # Set a default SRCDIR for each for simpler handling below.
46 .for D in ${CRUNCH_SRCDIRS}
47 .for P in ${CRUNCH_PROGS_${D}}
48 CRUNCH_SRCDIR_${P}?= ${CRUNCH_PATH_${D}}/${D}/${P}
52 # Program names and their aliases that contribute links to crunched
53 # executable, except for the suppressed ones.
54 .for D in ${CRUNCH_SRCDIRS}
55 .for P in ${CRUNCH_PROGS_${D}}
56 ${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile
57 .if ${CRUNCH_GENERATE_LINKS} == "yes"
58 .ifndef CRUNCH_SUPPRESS_LINK_${P}
59 .if ${CRUNCH_LINKTYPE} == "soft"
60 SYMLINKS+= ${PROG} ${BINDIR}/${P}
62 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
64 .endif # !CRUNCH_SUPPRESS_LINK_${P}
65 .for A in ${CRUNCH_ALIAS_${P}}
66 .ifndef CRUNCH_SUPPRESS_LINK_${A}
67 .if ${CRUNCH_LINKTYPE} == "soft"
68 SYMLINKS+= ${PROG} ${BINDIR}/${A}
70 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
72 .endif # !CRUNCH_SUPPRESS_LINK_${A}
73 .endfor # CRUNCH_ALIAS_${P}
74 .endif # CRUNCH_GENERATE_LINKS
75 .endfor # CRUNCH_PROGS_${D}
76 .endfor # CRUNCH_SRCDIRS
78 .if !defined(_SKIP_BUILD)
84 echo "# Auto-generated, do not edit" >${.TARGET}
85 .ifdef CRUNCH_BUILDOPTS
86 echo "buildopts ${CRUNCH_BUILDOPTS}" >>${.TARGET}
89 echo "libs ${CRUNCH_LIBS}" >>${.TARGET}
92 echo "libs_so ${CRUNCH_SHLIBS}" >>${.TARGET}
94 .for D in ${CRUNCH_SRCDIRS}
95 .for P in ${CRUNCH_PROGS_${D}}
96 echo "progs ${P}" >>${.TARGET}
97 echo "special ${P} srcdir ${CRUNCH_SRCDIR_${P}}" >>${.TARGET}
98 .ifdef CRUNCH_BUILDOPTS_${P}
99 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS_${P}}" >>${.TARGET}
101 echo "special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/" >>${.TARGET}
103 .ifdef CRUNCH_KEEP_${P}
104 echo "special ${P} keep ${CRUNCH_KEEP_${P}}" >>${.TARGET}
106 .for A in ${CRUNCH_ALIAS_${P}}
107 echo "ln ${P} ${A}" >>${.TARGET}
112 CRUNCHGEN?= crunchgen
114 .ORDER: ${OUTPUTS} objs
115 ${OUTPUTS:[1]}: .META
116 ${OUTPUTS:[2..-1]}: .NOMETA
118 MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
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
127 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
128 ${MAKE} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \
129 .MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \
133 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
134 ${MAKE} -f ${OUTMK} objs
136 # Use a separate build tree to hold files compiled for this crunchgen binary
137 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
138 # get that to cooperate with bsd.prog.mk. Besides, many of the standard
139 # targets should NOT be propagated into the components.
140 .for __target in clean cleandepend cleandir obj objlink
141 .for D in ${CRUNCH_SRCDIRS}
142 .for P in ${CRUNCH_PROGS_${D}}
143 ${__target}_crunchdir_${P}: .PHONY .MAKE
144 (cd ${CRUNCH_SRCDIR_${P}} && \
145 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
146 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target})
147 ${__target}: ${__target}_crunchdir_${P}
154 if [ -e ${.OBJDIR}/${OUTMK} ]; then \
155 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
156 ${MAKE} -f ${OUTMK} clean; \