]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.crunchgen.mk
Follow-up r296324: Fix STATICOBJS dependency guesses conditions.
[FreeBSD/FreeBSD.git] / share / mk / bsd.crunchgen.mk
1 #################################################################
2 #
3 # Generate crunched binaries using crunchgen(1).
4 #
5 # General notes:
6 #
7 # A number of Make variables are used to generate the crunchgen config file.
8 #
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.
16 #
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}
21 #
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.
26 #
27 # If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
28 #
29
30 # $FreeBSD$
31
32 ##################################################################
33 #  The following is pretty nearly a generic crunchgen-handling makefile
34 #
35
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
42
43 CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
44
45 # Don't try to extract debug info from ${PROG}.
46 MK_DEBUG_FILES= no
47
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}
52 .endfor
53 .endfor
54
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}
63 .endif
64 .for A in ${CRUNCH_ALIAS_${P}}
65 .ifndef CRUNCH_SUPPRESS_LINK_${A}
66 LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
67 .endif
68 .endfor
69 .endif
70 .endfor
71 .endfor
72
73 .if !defined(_SKIP_BUILD)
74 all: ${PROG}
75 .endif
76 exe: ${PROG}
77
78 ${CONF}: Makefile
79         echo \# Auto-generated, do not edit >${.TARGET}
80 .ifdef CRUNCH_BUILDOPTS
81         echo buildopts ${CRUNCH_BUILDOPTS} >>${.TARGET}
82 .endif
83 .ifdef CRUNCH_LIBS
84         echo libs ${CRUNCH_LIBS} >>${.TARGET}
85 .endif
86 .ifdef CRUNCH_SHLIBS
87         echo libs_so ${CRUNCH_SHLIBS} >>${.TARGET}
88 .endif
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}
96 .else
97         echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ >>${.TARGET}
98 .endif
99 .for A in ${CRUNCH_ALIAS_${P}}
100         echo ln ${P} ${A} >>${.TARGET}
101 .endfor
102 .endfor
103 .endfor
104
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}
111
112 # These 2 targets cannot use .MAKE since they depend on the generated
113 # ${OUTMK} above.
114 ${PROG}: ${OUTPUTS} objs
115         ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f ${OUTMK} exe
116
117 objs: ${OUTMK}
118         ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f ${OUTMK} objs
119
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}
128 .endfor
129
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}
142 .endfor
143 .endfor
144 .endfor
145
146 clean:
147         rm -f ${CLEANFILES}
148         ${_+_}if [ -e ${.OBJDIR}/${OUTMK} ]; then                       \
149                 ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE}     \
150                 -f ${OUTMK} clean;                                      \
151         fi