xref: /netbsd-src/distrib/sets/Makefile (revision aa397e14a26329ebed113de91843ca8ac2c9d8b8)
1#	$NetBSD: Makefile,v 1.111 2024/03/09 06:50:15 mrg 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.
11all:
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
18COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
19TAR_SUFF=${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
20XZ_OPT?=		-9
21GZIP_FLAGS=	${GZIP_N_FLAG}
22UMASK=		umask 022
23
24SETSENV=	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}
43SETSCMD=	cd ${.CURDIR} && \
44		${SETSENV} \
45		${HOST_SH}
46
47MAKETARS_FLAGS=
48.if ${MKREPRO_TIMESTAMP:Uno} != "no"
49MAKETARS_FLAGS+= -T "${MKREPRO_TIMESTAMP}"
50.endif
51.if ${MKX11} != "no"
52MAKESRCTARS_X11_FLAGS=	-x ${X11SRCDIR}
53.endif
54.if ${MKX11} != "no"
55MAKEFLIST_X11_FLAGS=	,x
56.endif
57MAKEFLIST_FLAGS=	-L base${MAKEFLIST_X11_FLAGS}
58MAKESRCTARS_FLAGS= 	-N ${NETBSDSRCDIR}/etc
59
60.if ${MAKEVERBOSE} < 2
61MAKETARS_FLAGS+=	-q
62MAKESRCTARS_FLAGS+= 	-q
63.endif
64
65.if !defined(MAKETARSETS)
66MAKETARSETS!= ${SETSCMD} ./makeflist -l ${MAKEFLIST_FLAGS}
67.endif
68
69print_have_xorg_server_ver: .PHONY
70	@echo ${HAVE_XORG_SERVER_VER}
71
72print_have_mesa_ver: .PHONY
73	@echo ${HAVE_MESA_VER}
74
75print_have_gcc: .PHONY
76	@echo ${HAVE_GCC}
77
78print_machine: .PHONY
79	@echo ${MACHINE}
80
81print_machine_arch: .PHONY
82	@echo ${MACHINE_ARCH}
83
84print_machine_cpu: .PHONY
85	@echo ${MACHINE_CPU}
86
87print_object_fmt: .PHONY
88	@echo ${OBJECT_FMT}
89
90print_toolchain_missing: .PHONY
91	@echo "${TOOLCHAIN_MISSING}"
92
93print_mkvars \
94print_set_lists_base print_set_lists_x print_set_lists_ext \
95list_set_lists_base list_set_lists_x list_set_lists_ext \
96list_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
127METALOG_REMOVE_DUPLICATES= \
128	${TOOL_AWK} '{ a[$$1] = $$0; } END { for (f in a) print a[f]; }'
129
130.if ${MKUNPRIVED} == "no"
131METALOG.unpriv=
132sanitise_METALOG: .PHONY
133	@true
134clean_METALOG: .PHONY
135	@true
136.else	# MKUNPRIVED
137METALOG.unpriv= -M ${METALOG}.sanitised
138sanitise_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})
154clean_METALOG: .PHONY
155	rm -f ${METALOG} ${METALOG}.*
156.else	# MKUPDATE
157clean_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.
174makeflist: .PHONY .PRECIOUS check_DESTDIR
175	${_MKMSG_EXECUTE} "makeflist"
176	${SETSCMD} ./makeflist ${MAKEFLIST_FLAGS}
177
178checkflist: .PRECIOUS .PHONY check_DESTDIR sanitise_METALOG
179	${_MKMSG_EXECUTE} "checkflist"
180	${SETSCMD} ${.CURDIR}/checkflist \
181	    ${MAKEFLIST_FLAGS} ${CHECKFLIST_FLAGS} ${METALOG.unpriv}
182
183checkflist-x11: .PHONY check_DESTDIR
184	${_MKMSG_EXECUTE} "checkflist -x"
185	${SETSCMD} ./checkflist -x ${CHECKFLIST_FLAGS}
186
187.if defined(DESTDIR) && ${DESTDIR} != ""
188checkflist_if_DESTDIR: checkflist
189.else
190checkflist_if_DESTDIR:
191.endif
192
193#
194# SET BUILDING TARGETS
195#
196
197TARDIR=		${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
198SOURCETARDIR=	${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#
207MAKETARS_SERIAL?= NO
208.if empty(MAKETARS_SERIAL:M[Yy][Ee][Ss])
209_MAKETARS_WAIT= # empty
210.else
211_MAKETARS_WAIT= .WAIT
212.endif
213
214maketars: .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
220maketarsetup: .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
230makesetfiles: .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}
237do-${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
246makesrctars: .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
254makesums: .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}
261do-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
271installsets: .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?
282SLOPPY_FLIST?= NO
283.if !empty(SLOPPY_FLIST:M[Yy][Ee][Ss])
284CHECKFLIST_FLAGS+=	-e -m
285REGPKG.sloppy=		-m
286.endif
287
288.if ${MAKEVERBOSE} == 0
289REGPKG.verbose?= -q
290.elif ${MAKEVERBOSE} == 1
291REGPKG.verbose?=
292.else	# MAKEVERBOSE >= 2
293REGPKG.verbose?= -v
294.endif
295REGPKG.force?=		# -f, or empty
296REGPKG.cache?= -c	# -c, or empty
297REGPKG.update:= ${MKUPDATE:tl:Nno:C/..*/-u/}
298SYSPKGSETS?= all
299makesyspkgs: .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
310makesyspkgsums: .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?
317makedeps: .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#
328sortlists: .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
354syspkgs: .PHONY makesyspkgs .WAIT makesyspkgsums
355	@true
356
357sets: .PHONY maketars .WAIT makesums
358	@true
359
360sourcesets: .PHONY makesrctars
361	@true
362
363.include <bsd.files.mk>
364