bsd.crunchgen.mk: Simplify mk logic a bit.
[dragonfly.git] / share / mk / bsd.crunchgen.mk
blob2f4cb22170919d7e769c7a78c5d90cf993af520f
1 #################################################################
3 # Generate crunched binaries using crunchgen(1).
5 # General notes:
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
15 # local architecture.
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
36 CONF= ${PROG}.conf
37 OUTMK= ${PROG}.mk
38 OUTC= ${PROG}.c
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}
49 .endfor
50 .endfor
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}
60 .endif
61 .for A in ${CRUNCH_ALIAS_${P}}
62 .ifndef CRUNCH_SUPPRESS_LINK_${A}
63 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
64 .endif
65 .endfor
66 .endif
67 .endfor
68 .endfor
70 all: ${PROG}
71 exe: ${PROG}
73 ${CONF}: Makefile
74 echo \# Auto-generated, do not edit >${.TARGET}
75 .ifdef CRUNCH_BUILDOPTS
76 echo buildopts ${CRUNCH_BUILDOPTS} >>${.TARGET}
77 .endif
78 .ifdef CRUNCH_LIBS
79 echo libs ${CRUNCH_LIBS} >>${.TARGET}
80 .endif
81 .ifdef CRUNCH_SHLIBS
82 echo libs_so ${CRUNCH_SHLIBS} >>${.TARGET}
83 .endif
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}
91 .else
92 echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ >>${.TARGET}
93 .endif
94 .ifdef CRUNCH_KEEP_${P}
95 echo special ${P} keep ${CRUNCH_KEEP_${P}} >>${.TARGET}
96 .endif
97 .for A in ${CRUNCH_ALIAS_${P}}
98 echo ln ${P} ${A} >>${.TARGET}
99 .endfor
100 .endfor
101 .endfor
103 CRUNCHGEN?= crunchgen
104 CRUNCHENV?= # empty
105 .ORDER: ${OUTPUTS} objs
106 ${OUTPUTS}: ${CONF}
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
114 objs: ${OUTMK}
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.
120 build-tools:
121 .for _tool in ${CRUNCH_BUILDTOOLS}
122 cd ${.CURDIR}/../../../${_tool}; \
123 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
124 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
125 .endfor
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}
137 .endfor
138 .endfor
140 clean:
141 rm -f ${CLEANFILES}
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}
151 .endfor
152 .endfor