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