1 #################################################################
3 # Generate crunched binaries using crunchgen(1).
7 # A number of Make variables are used to generate the crunchgen config file.
9 # CRUNCH_SRCDIRS: lists directories to search for included programs
10 # CRUNCH_PROGS: lists programs to be included
11 # CRUNCH_LIBS: libraries to statically link with
12 # CRUNCH_SHLIBS: libraries to dynamically link with
13 # CRUNCH_BUILDOPTS: generic build options to be added to every program
14 # CRUNCH_BUILDTOOLS: lists programs that need build tools built in the
17 # 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_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 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, no links will be generated.
32 ##################################################################
33 # The following is pretty nearly a generic crunchgen-handling makefile
39 OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
40 CRUNCHOBJS= ${.OBJDIR}
41 CRUNCH_GENERATE_LINKS?= yes
43 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
45 # Don't try to extract debug info from ${PROG}.
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}?= ${.CURDIR}/../../${D}/${P}
55 # Program names and their aliases contribute hardlinks to 'rescue' executable,
56 # except for those that get suppressed.
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 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
64 .for A in ${CRUNCH_ALIAS_${P}}
65 .ifndef CRUNCH_SUPPRESS_LINK_${A}
66 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
73 .if !defined(_SKIP_BUILD)
79 echo \# Auto-generated, do not edit >${.TARGET}
80 .ifdef CRUNCH_BUILDOPTS
81 echo buildopts ${CRUNCH_BUILDOPTS} >>${.TARGET}
84 echo libs ${CRUNCH_LIBS} >>${.TARGET}
87 echo libs_so ${CRUNCH_SHLIBS} >>${.TARGET}
89 .for D in ${CRUNCH_SRCDIRS}
90 .for P in ${CRUNCH_PROGS_${D}}
91 echo progs ${P} >>${.TARGET}
92 echo special ${P} srcdir ${CRUNCH_SRCDIR_${P}} >>${.TARGET}
93 .ifdef CRUNCH_BUILDOPTS_${P}
94 echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ \
95 ${CRUNCH_BUILDOPTS_${P}} >>${.TARGET}
97 echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ >>${.TARGET}
99 .for A in ${CRUNCH_ALIAS_${P}}
100 echo ln ${P} ${A} >>${.TARGET}
105 CRUNCHGEN?= crunchgen
106 CRUNCHENV?= MK_TESTS=no
107 .ORDER: ${OUTPUTS} objs
108 ${OUTPUTS}: ${CONF} .META
109 MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${CRUNCHGEN} -fq \
110 -m ${OUTMK} -c ${OUTC} ${CONF}
112 # These 2 targets cannot use .MAKE since they depend on the generated
114 ${PROG}: ${OUTPUTS} objs
115 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f ${OUTMK} exe
118 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f ${OUTMK} objs
120 # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
121 # shell scripts so we can remove this nonsense.
122 .for _tool in ${CRUNCH_BUILDTOOLS}
123 build-tools-${_tool}:
124 ${_+_}cd ${.CURDIR}/../../${_tool}; \
125 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
126 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
127 build-tools: build-tools-${_tool}
130 # Use a separate build tree to hold files compiled for this crunchgen binary
131 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
132 # get that to cooperate with bsd.prog.mk. Besides, many of the standard
133 # targets should NOT be propagated into the components.
134 .for __target in clean cleandepend cleandir obj objlink
135 .for D in ${CRUNCH_SRCDIRS}
136 .for P in ${CRUNCH_PROGS_${D}}
137 ${__target}_crunchdir_${P}: .PHONY .MAKE
138 ${_+_}cd ${CRUNCH_SRCDIR_${P}} && \
139 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
140 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${__target}
141 ${__target}: ${__target}_crunchdir_${P}
148 ${_+_}if [ -e ${.OBJDIR}/${OUTMK} ]; then \
149 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} \