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