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.
30 # $FreeBSD: head/share/mk/bsd.crunchgen.mk 251512 2013-06-07 21:40:02Z emaste $
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 # 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}?
= ${.CURDIR
}/..
/..
/..
/${D}/${P}
52 # Program names and their aliases contribute hardlinks to 'rescue' executable,
53 # except for those that get suppressed.
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 LINKS
+= ${BINDIR}/${PROG} ${BINDIR}/${P}
61 .for A in
${CRUNCH_ALIAS_
${P}}
62 .
ifndef CRUNCH_SUPPRESS_LINK_
${A}
63 LINKS
+= ${BINDIR}/${PROG} ${BINDIR}/${A}
74 echo \
# Auto-generated, do not edit >${.TARGET}
75 .
ifdef CRUNCH_BUILDOPTS
76 echo buildopts
${CRUNCH_BUILDOPTS} >>${.TARGET
}
79 echo libs
${CRUNCH_LIBS} >>${.TARGET
}
82 echo libs_so
${CRUNCH_SHLIBS} >>${.TARGET
}
84 .for D in
${CRUNCH_SRCDIRS}
85 .for P in
${CRUNCH_PROGS_
${D}}
86 echo progs
${P} >>${.TARGET
}
87 echo special
${P} srcdir ${CRUNCH_SRCDIR_
${P}} >>${.TARGET
}
88 .
ifdef CRUNCH_BUILDOPTS_
${P}
89 echo special
${P} buildopts DIRPRFX
=${DIRPRFX}${P}/ \
90 ${CRUNCH_BUILDOPTS_
${P}} >>${.TARGET
}
92 echo special
${P} buildopts DIRPRFX
=${DIRPRFX}${P}/ >>${.TARGET
}
94 .
ifdef CRUNCH_KEEP_
${P}
95 echo special
${P} keep
${CRUNCH_KEEP_
${P}} >>${.TARGET
}
97 .for A in
${CRUNCH_ALIAS_
${P}}
98 echo ln
${P} ${A} >>${.TARGET
}
103 CRUNCHGEN?
= crunchgen
105 .ORDER
: ${OUTPUTS} objs
107 MAKE
=${MAKE} ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CRUNCHOBJS} \
108 ${CRUNCHGEN} -fq
-m
${OUTMK} -c
${OUTC} ${CONF}
110 ${PROG}: ${OUTPUTS} objs
111 ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CRUNCHOBJS} \
112 ${MAKE} -f
${OUTMK} exe
115 ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CRUNCHOBJS} \
116 ${MAKE} -f
${OUTMK} objs
118 # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
119 # shell scripts so we can remove this nonsense.
121 .for _tool in
${CRUNCH_BUILDTOOLS}
122 cd
${.CURDIR
}/..
/..
/..
/${_tool}; \
123 ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CRUNCHOBJS} ${MAKE} obj
; \
124 ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CRUNCHOBJS} ${MAKE} build-tools
127 # Use a separate build tree to hold files compiled for this crunchgen binary
128 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
129 # get that to cooperate with bsd.prog.mk. Besides, many of the standard
130 # targets should NOT be propagated into the components.
131 cleandepend cleandir obj objlink
:
132 .for D in
${CRUNCH_SRCDIRS}
133 .for P in
${CRUNCH_PROGS_
${D}}
134 cd
${CRUNCH_SRCDIR_
${P}} && \
135 ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CANONICALOBJDIR} ${MAKE} \
136 DIRPRFX
=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET
}
142 if
[ -e
${.OBJDIR
}/${OUTMK} ]; then \
143 ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CRUNCHOBJS} \
144 ${MAKE} -f
${OUTMK} clean; \
146 .for D in
${CRUNCH_SRCDIRS}
147 .for P in
${CRUNCH_PROGS_
${D}}
148 cd
${CRUNCH_SRCDIR_
${P}} && \
149 ${CRUNCHENV} MAKEOBJDIRPREFIX
=${CANONICALOBJDIR} ${MAKE} \
150 DIRPRFX
=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET
}