Makefile revision 1.99 1 # $NetBSD: Makefile,v 1.99 2015/11/26 15:41:58 joerg Exp $
2
3 # Experimental RCS METALOG versioning
4 # (Needs host's rcs(1) commands)
5 #
6 # TODO:
7 # - In 'build.sh distribution', print diff to previous
8 #RCSMETALOG=1
9
10 # The `all' target must appear before bsd.own.mk is pulled in.
11 all:
12 @echo "Please understand what you are doing, first."
13 @false
14
15 .include <bsd.own.mk>
16 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
17
18 COMPRESS_PROGRAM=${TOOL_GZIP}
19 GZIP_FLAGS= ${GZIP_N_FLAG}
20
21 SETSENV= DESTDIR=${DESTDIR:Q} \
22 MACHINE=${MACHINE:Q} \
23 MACHINE_ARCH=${MACHINE_ARCH:Q} \
24 AWK=${TOOL_AWK:Q} \
25 CKSUM=${TOOL_CKSUM:Q} \
26 DB=${TOOL_DB:Q} \
27 EGREP=${TOOL_GREP:Q}\ -E \
28 HOST_SH=${HOST_SH:Q} \
29 MAKE=${MAKE:Q} \
30 MKTEMP=${TOOL_MKTEMP:Q} \
31 MTREE=${TOOL_MTREE:Q} \
32 PAX=${TOOL_PAX:Q} \
33 COMPRESS_PROGRAM=${COMPRESS_PROGRAM:Q} \
34 GZIP=${GZIP_FLAGS:Q} \
35 PKG_CREATE=${TOOL_PKG_CREATE:Q} \
36 SED=${TOOL_SED:Q} \
37 TSORT=${TSORT:Q}
38 SETSCMD= cd ${.CURDIR} && \
39 ${SETSENV} \
40 ${HOST_SH}
41
42 MAKETARS_FLAGS=
43 .if ${MKX11} != "no"
44 MAKESRCTARS_X11_FLAGS= -x ${X11SRCDIR}
45 .endif
46 .if ${MKEXTSRC} != "no"
47 MAKESRCTARS_EXTSRC_FLAGS= -y ${EXTSRCSRCDIR}
48 .endif
49 .if ${MKX11} != "no"
50 MAKEFLIST_X11_FLAGS= ,x
51 .endif
52 .if ${MKEXTSRC} != "no"
53 MAKEFLIST_EXTSRC_FLAGS= ,ext
54 .endif
55 MAKEFLIST_FLAGS= -L base${MAKEFLIST_X11_FLAGS}${MAKEFLIST_EXTSRC_FLAGS}
56 MAKESRCTARS_FLAGS= -N ${NETBSDSRCDIR}/etc
57
58 .if ${MAKEVERBOSE} < 2
59 MAKETARS_FLAGS+= -q
60 MAKESRCTARS_FLAGS+= -q
61 .endif
62
63 .if !defined(MAKETARSETS)
64 MAKETARSETS!= ${SETSCMD} ./makeflist -l ${MAKEFLIST_FLAGS}
65 .endif
66
67 print_have_gcc: .PHONY
68 @echo ${HAVE_GCC}
69
70 print_machine: .PHONY
71 @echo ${MACHINE}
72
73 print_machine_arch: .PHONY
74 @echo ${MACHINE_ARCH}
75
76 print_machine_cpu: .PHONY
77 @echo ${MACHINE_CPU}
78
79 print_object_fmt: .PHONY
80 @echo ${OBJECT_FMT}
81
82 print_toolchain_missing: .PHONY
83 @echo "${TOOLCHAIN_MISSING}"
84
85 print_mkvars \
86 print_set_lists_base print_set_lists_x print_set_lists_ext \
87 list_set_lists_base list_set_lists_x list_set_lists_ext \
88 list_set_files_base list_set_files_x list_set_files_ext \
89 : .PHONY
90 @${SETSENV}; rundir="${.CURDIR}"; . ./sets.subr; ${.TARGET}
91
92 #
93 # METALOG MANIPULATION TARGETS
94 #
95 # METALOG is the name of a metadata log file, and is set in <bsd.own.mk>
96 # if MKUNPRIVED is not "no".
97 #
98 # METALOG.unpriv is a command line option passed to various scripts;
99 # it is either blank or "-M ${METALOG}.sanitised", depending on the
100 # MKUNPRIVED flag.
101 #
102 # The sanitise_METALOG target creates METALOG.sanitised from METALOG,
103 # without modifying METALOG itself. This is used near the end of
104 # a build, after build products have been installed in DESTDIR
105 # and corresponding lines have been added to METALOG, but before
106 # METALOG.sanitised is used in the creation of sets in RELEASEDIR.
107 # For update builds, METALOG.sanitised has duplicates merged (keeping
108 # only the last of multiple entries for the same item), but for clean
109 # builds it's an error if a file or directory name appears twice.
110 # METALOG.sanitised is always sorted and has timestamps removed.
111 #
112 # The clean_METALOG target either deletes METALOG, or replaces METALOG with
113 # a sanitised version of itself, depending on the MKUPDATE flag, and
114 # deletes old METALOG.* files. This is intended to be used at the start
115 # of a build, to ensure that repeated MKUPDATE builds do not cause
116 # unbounded growth of METALOG.
117 #
118
119 METALOG_REMOVE_DUPLICATES= \
120 ${TOOL_AWK} '{ a[$$1] = $$0; } END { for (f in a) print a[f]; }'
121
122 .if ${MKUNPRIVED} == "no"
123 METALOG.unpriv=
124 sanitise_METALOG: .PHONY
125 @true
126 clean_METALOG: .PHONY
127 @true
128 .else # MKUNPRIVED
129 METALOG.unpriv= -M ${METALOG}.sanitised
130 sanitise_METALOG: .PHONY ${METALOG}.sanitised
131 ${METALOG}.sanitised: ${METALOG}
132 <${METALOG} \
133 ${${MKUPDATE} != "no" :? ${METALOG_REMOVE_DUPLICATES} | :} \
134 sort | ${TOOL_MTREE} -CSM -k all -R time -N ${NETBSDSRCDIR}/etc \
135 >${METALOG}.new
136 mv ${METALOG}.new ${METALOG}.sanitised
137 .if defined(RCSMETALOG)
138 . ./metalog.subr; \
139 xrcs_descr="build distribution METALOG"; \
140 xrcs_msg="$$(date)"; \
141 xrcs_cur=${METALOG}.sanitised; \
142 xrcs update
143 .endif
144 .if ${MKUPDATE} == "no" || !exists(${METALOG})
145 clean_METALOG: .PHONY
146 rm -f ${METALOG} ${METALOG}.*
147 .else # MKUPDATE
148 clean_METALOG: .PHONY ${METALOG}.sanitised
149 mv ${METALOG}.sanitised ${METALOG}
150 .if defined(RCSMETALOG)
151 [ -f ${METALOG}.sanitised,v ] && mv ${METALOG}.sanitised,v ${METALOG},v
152 .endif
153 rm -f ${METALOG}.*
154 .if defined(RCSMETALOG)
155 [ -f ${METALOG},v ] && mv ${METALOG},v ${METALOG}.sanitised,v
156 .endif
157 .endif # MKUPDATE
158 .endif # MKUNPRIVED
159
160 #
161 # FILE LIST TARGETS
162 #
163
164 # This target has debugging value only, really.
165 makeflist: .PHONY .PRECIOUS check_DESTDIR
166 ${SETSCMD} ./makeflist ${MAKEFLIST_FLAGS}
167
168 checkflist: .PRECIOUS .PHONY check_DESTDIR sanitise_METALOG
169 ${SETSCMD} ${.CURDIR}/checkflist \
170 ${MAKEFLIST_FLAGS} ${CHECKFLIST_FLAGS} ${METALOG.unpriv}
171
172 checkflist-x11: .PHONY check_DESTDIR
173 ${SETSCMD} ./checkflist -x ${CHECKFLIST_FLAGS}
174
175 checkflist-extsrc: .PHONY check_DESTDIR
176 ${SETSCMD} ./checkflist -y ${CHECKFLIST_FLAGS}
177
178 .if defined(DESTDIR) && ${DESTDIR} != ""
179 checkflist_if_DESTDIR: checkflist
180 .else
181 checkflist_if_DESTDIR:
182 .endif
183
184 #
185 # SET BUILDING TARGETS
186 #
187
188 TARDIR= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
189 SOURCETARDIR= ${RELEASEDIR}/source/sets
190
191 # If MAKETARS_SERIAL is set to "YES" or "yes", then the tar sets will be
192 # made in series, even if make's "-j" flag requests multiple parallel
193 # jobs. This is useful on systems that exhibit poor performance when
194 # running multiple parallel disk-intensive operations. The default is
195 # MAKETARS_SERIAL=NO, which will obey the "-j" flag passed to the make
196 # command.
197 #
198 MAKETARS_SERIAL?= NO
199 .if empty(MAKETARS_SERIAL:M[Yy][Ee][Ss])
200 _MAKETARS_WAIT= # empty
201 .else
202 _MAKETARS_WAIT= .WAIT
203 .endif
204
205 maketars: .PRECIOUS .PHONY check_DESTDIR check_RELEASEDIR \
206 sanitise_METALOG checkflist_if_DESTDIR .WAIT \
207 maketarsetup .WAIT \
208 ${MAKETARSETS:@.TARS.@${_MAKETARS_WAIT} do-${.TARS.}@}
209 @true
210
211 maketarsetup: .EXEC
212 .if defined(DESTDIR) && ${DESTDIR} != ""
213 ${_MKMSG} "execute checkflist"
214 cd ${.CURDIR}; ${MAKE} checkflist
215 .endif
216 mkdir -p ${TARDIR}
217 for i in MD5 SHA512; do \
218 rm -f ${TARDIR}/$$i ${TARDIR}/$$i.tmp; \
219 done
220
221 makesetfiles: .PHONY sanitise_METALOG
222 ${_MKMSG_CREATE} "set lists"
223 ${SETSCMD} ./maketars -S -d ${DESTDIR:S,^$,/,} ${MAKETARS_FLAGS} \
224 ${METALOG.unpriv} \
225 -N ${NETBSDSRCDIR}/etc ${MAKEFLIST_FLAGS} -t ${TARDIR}
226
227 .for tar in ${MAKETARSETS}
228 do-${tar}: .PHONY sanitise_METALOG
229 ${_MKMSG_CREATE} "${tar}.tgz"
230 ${SETSCMD} ./maketars -d ${DESTDIR:S,^$,/,} ${MAKETARS_FLAGS} \
231 ${METALOG.unpriv} \
232 -N ${NETBSDSRCDIR}/etc -t ${TARDIR} ${tar} \
233 || { rm -f ${TARDIR}/${tar}.tgz; false; }
234 .endfor
235
236
237 makesrctars: .PRECIOUS .PHONY check_RELEASEDIR
238 ${_MKMSG_CREATE} "source tar files"
239 mkdir -p ${SOURCETARDIR}
240 ${SETSCMD} ./makesrctars ${MAKESRCTARS_FLAGS} \
241 ${MAKESRCTARS_X11_FLAGS} ${MAKESRCTARS_EXTSRC_FLAGS} \
242 ${NETBSDSRCDIR} ${SOURCETARDIR}
243
244
245 makesums: .PRECIOUS .PHONY check_RELEASEDIR .WAIT \
246 ${MAKETARSETS:@.TARS.@do-sum-${.TARS.}@}
247 for i in MD5 SHA512; do \
248 mv ${TARDIR}/$$i.tmp ${TARDIR}/$$i; \
249 done
250
251 .for tar in ${MAKETARSETS}
252 do-sum-${tar}: .PHONY do-${tar}
253 ${_MKMSG_CREATE} "${tar} checksums"
254 ${MAKESUMS} -t ${TARDIR} ${tar}.tgz
255 for i in MD5 SHA512; do \
256 ${TOOL_CAT} ${TARDIR}/$$i >> ${TARDIR}/$$i.tmp; \
257 done
258 .endfor
259 .ORDER: ${MAKETARSETS:@.TARS.@do-sum-${.TARS.}@}
260
261
262 installsets: .PHONY check_DESTDIR sanitise_METALOG
263 .if !defined(INSTALLDIR)
264 @echo "setenv INSTALLDIR before doing that!"
265 @false
266 .endif
267 ${SETSCMD} ./maketars -d ${DESTDIR:S,^$,/,} ${MAKETARS_FLAGS} \
268 ${METALOG.unpriv} -N ${NETBSDSRCDIR}/etc \
269 ${MAKEFLIST_FLAGS} -i ${INSTALLDIR} ${INSTALLSETS}
270
271 # Should we ignore errors like extra or missing files in the flists?
272 SLOPPY_FLIST?= NO
273 .if !empty(SLOPPY_FLIST:M[Yy][Ee][Ss])
274 CHECKFLIST_FLAGS+= -e -m
275 REGPKG.sloppy= -m
276 .endif
277
278 .if ${MAKEVERBOSE} == 0
279 REGPKG.verbose?= -q
280 .elif ${MAKEVERBOSE} == 1
281 REGPKG.verbose?=
282 .else # MAKEVERBOSE >= 2
283 REGPKG.verbose?= -v
284 .endif
285 REGPKG.force?= # -f, or empty
286 REGPKG.cache?= -c # -c, or empty
287 REGPKG.update:= ${MKUPDATE:tl:Nno:C/..*/-u/}
288 SYSPKGSETS?= all
289 makesyspkgs: .PHONY check_DESTDIR check_RELEASEDIR \
290 sanitise_METALOG checkflist_if_DESTDIR
291 mkdir -p ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
292 ${SETSCMD} ${.CURDIR}/regpkgset \
293 ${REGPKG.verbose} ${REGPKG.force} ${REGPKG.sloppy} \
294 ${REGPKG.cache} ${REGPKG.update} \
295 -d ${DESTDIR:S,^$,/,} ${METALOG.unpriv} \
296 -N ${NETBSDSRCDIR}/etc \
297 -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs ${SYSPKGSETS}
298
299 makesyspkgsums: .PHONY check_RELEASEDIR
300 ${MAKESUMS} -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
301
302 # Update the "deps" file.
303 # XXX: Why is "deps" checked in to the source tree, instead of
304 # just being created as necessary?
305 makedeps: .PHONY
306 ${SETSCMD} ./syspkgdeps all >${.CURDIR}/deps
307
308 # Sort the lists files.
309 #
310 # The tricky stuff with awk and sort -k options is to ensure that the
311 # heading remains undisturbed, and on non-heading lines anything before
312 # the first "." is ignored, so that "./dir/file" and "#./dir/file" are
313 # sorted together.
314 #
315 sortlists: .PHONY
316 find ${.CURDIR}/lists \! \( -name CVS -prune \) \! -name .#\* \
317 -type f -print \
318 | while read f ; do \
319 ${_MKSHMSG} "sorting $${f#${.CURDIR}/}" ; \
320 awk 'BEGIN { inheader = 1 } \
321 /^#*\.\// { inheader = 0 } \
322 // { tag = (inheader ? NR : 999999); \
323 print tag "." $$0 }' \
324 <"$$f" \
325 | sort -t . -k 1n,2 -k 3 \
326 | cut -d . -f 2- \
327 | cat -s >"$$f".tmp; \
328 if cmp "$$f" "$$f".tmp >/dev/null; then \
329 : "$$f is unchanged" ; \
330 rm "$$f".tmp ; \
331 else \
332 mv "$$f".tmp "$$f" ; \
333 fi ; \
334 done
335
336 #
337 # MAIN ENTRY POINTS
338 #
339
340 syspkgs: .PHONY makesyspkgs .WAIT makesyspkgsums
341 @true
342
343 sets: .PHONY maketars .WAIT makesums
344 @true
345
346 sourcesets: .PHONY makesrctars
347 @true
348
349 .include <bsd.files.mk>
350