sets.subr revision 1.209
1#	$NetBSD: sets.subr,v 1.209 2024/07/11 17:27:25 riastradh Exp $
2#
3
4#
5# The following variables contain defaults for sets.subr functions and callers:
6#	setsdir			path to src/distrib/sets
7#	nlists			list of base sets
8#	xlists			list of x11 sets
9#	obsolete		controls if obsolete files are selected instead
10#	module			if != "no", enable MODULE sets
11#	shlib			shared library format (a.out, elf, or "")
12#	stlib			static library format (a.out, elf)
13#
14# The following <bsd.own.mk> variables are exported to the environment:
15#	MACHINE
16#	MACHINE_ARCH
17#	MACHINE_CPU
18#	HAVE_ACPI
19#	HAVE_BINUTILS
20#	HAVE_GCC
21#	HAVE_GDB
22#	HAVE_NVMM
23#	HAVE_OPENSSL
24#	HAVE_SSP
25#	HAVE_UEFI
26#	TOOLCHAIN_MISSING
27#	OBJECT_FMT
28# as well as:
29#
30
31#
32# The following variables refer to tools that are used when building sets:
33#
34: ${AWK:=awk}
35: ${CKSUM:=cksum}
36: ${COMM:=comm}
37: ${DATE:=date}
38: ${DB:=db}
39: ${EGREP:=egrep}
40: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
41: ${FGREP:=fgrep}
42: ${FIND:=find}
43: ${GREP:=grep}
44: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
45: ${HOSTNAME_CMD:=hostname}	# ${HOSTNAME} is special to bash(1)
46: ${HOST_SH:=sh}
47: ${IDENT:=ident}
48: ${JOIN:=join}
49: ${LS:=ls}
50: ${MAKE:=make}
51: ${MKTEMP:=mktemp}
52: ${MTREE:=mtree}
53: ${PASTE:=paste}
54: ${PAX:=pax}
55: ${PRINTF:=printf}
56: ${SED:=sed}
57: ${SORT:=sort}
58: ${STAT:=stat}
59: ${TSORT:=tsort}
60: ${UNAME:=uname}
61: ${WC:=wc}
62: ${XARGS:=xargs}
63
64#
65# If printf is a shell builtin command, then we can
66# implement cheaper versions of basename and dirname
67# that do not involve any fork/exec overhead.
68# If printf is not builtin, approximate it using echo,
69# and hope there are no weird file names that cause
70# some versions of echo to do the wrong thing.
71# (Converting to this version of dirname speeded up the
72# syspkgdeps script by an order of magnitude, from 68
73# seconds to 6.3 seconds on one particular host.)
74#
75# Note that naive approximations for dirname
76# using ${foo%/*} do not do the right thing in cases
77# where the result should be "/" or ".".
78#
79case "$(type printf)" in
80*builtin*)
81	basename ()
82	{
83		local bn
84		bn="${1##*/}"
85		bn="${bn%$2}"
86		printf "%s\n" "$bn"
87	}
88	dirname ()
89	{
90		local dn
91		case "$1" in
92		?*/*)	dn="${1%/*}" ;;
93		/*)	dn=/ ;;
94		*)	dn=. ;;
95		esac
96		printf "%s\n" "$dn"
97	}
98	;;
99*)
100	basename ()
101	{
102		local bn
103		bn="${1##*/}"
104		bn="${bn%$2}"
105		echo "$bn"
106	}
107	dirname ()
108	{
109		local dn
110		case "$1" in
111		?*/*)	dn="${1%/*}" ;;
112		/*)	dn=/ ;;
113		*)	dn=. ;;
114		esac
115		echo "$dn"
116	}
117	;;
118esac
119
120#####
121
122oIFS=$IFS
123IFS="
124"
125
126for x in $( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
127	eval export $x
128done
129
130IFS=$oIFS
131
132MKVARS="$( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )"
133
134#####
135
136setsdir=${rundir}
137obsolete=0
138if [ "${MKKMOD}" = "no" ]; then
139	module=no			# MODULEs are off.
140	modset=""
141else
142	module=yes
143	modset="modules"
144fi
145if [ "${MKATF}" = "no" ]; then
146	testset=""
147else
148	testset="tests"
149fi
150if [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then
151	debugset=""
152	xdebugset=""
153else
154	debugset="debug"
155	xdebugset="xdebug"
156fi
157if [ -z "${debugset}" -o "${MKCOMPAT}" = "no" ]; then
158	debug32set=""
159else
160	debug32set="debug32"
161fi
162if [ -z "${debug32set}" ]; then
163	debug64set=""
164else
165	if [ "${MACHINE_ARCH}" = "mips64eb" -o "${MACHINE_ARCH}" = "mips64el" ]; then
166		debug64set="debug64"
167	else
168		debug64set=""
169	fi
170fi
171if [ "${MKDTB}" = "no" ]; then
172	dtbset=""
173else
174	dtbset="dtb"
175fi
176if [ "${MKHTML}" = "no" ]; then
177	manhtmlset=""
178else
179	manhtmlset="manhtml"
180fi
181if [ "${MKCOMPAT}" = "no" ]; then
182	base32set=""
183else
184	base32set="base32"
185fi
186if [ "${MKCOMPAT}" != "no" ]; then
187	if [ "${MACHINE_ARCH}" = "mips64eb" -o "${MACHINE_ARCH}" = "mips64el" ]; then
188		base64set="base64"
189	else
190		base64set=""
191	fi
192else
193	base64set=""
194fi
195
196# XXX This should not be encoded here -- this mostly duplicates
197# information in compat/archdirs.mk, except that it also identifies
198# which compat architectures are `32-bit' and which ones are `64-bit'.
199case $MACHINE_ARCH in
200aarch64)
201	compat32arches='eabi eabihf'
202	;;
203aarch64eb)
204	compat32arches=eabi
205	;;
206mips64eb|mips64el)
207	compat32arches=o32
208	compat64arches=64
209	;;
210mipsn64eb|mipsn64el)
211	compat32arches='n32 o32'
212	;;
213powerpc64)
214	compat32arches=powerpc
215	;;
216riscv64)
217	compat32arches=rv32
218	;;
219sparc64)
220	compat32arches=sparc
221	;;
222x86_64)	compat32arches=i386
223	;;
224esac
225: ${compat32arches:=}
226: ${compat64arches:=}
227
228
229# Determine lib type. Do this first so stlib also gets set.
230if [ "${OBJECT_FMT}" = "ELF" ]; then
231	shlib=elf
232else
233	shlib=aout
234fi
235stlib=$shlib
236# Now check for MKPIC or specials and turn off shlib if need be.
237if [ "${MKPIC}" = "no" ]; then
238	shlib=no
239fi
240nlists="base $base32set $base64set comp $debugset $debug32set $debug64set $dtbset etc games gpufw man $manhtmlset misc $modset rescue $testset text"
241xlists="xbase xcomp $xdebugset xetc xfont xserver"
242
243OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
244if [ "${KERNEL_DIR}" = "yes" ]; then
245	MODULEDIR="netbsd/modules"
246else
247	MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
248fi
249SUBST="s#@MODULEDIR@#${MODULEDIR}#g"
250SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
251SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
252
253#
254# list_set_files setfile [...]
255#
256# Produce a packing list for setfile(s).
257# In each file, a record consists of a path and a System Package name,
258# separated by whitespace. E.g.,
259#
260# 	# $NetBSD: sets.subr,v 1.209 2024/07/11 17:27:25 riastradh Exp $
261# 	.			base-sys-root	[keyword[,...]]
262# 	./altroot		base-sys-root
263# 	./bin			base-sys-root
264# 	./bin/[			base-util-root
265# 	./bin/cat		base-util-root
266#		[...]
267#
268# A # in the first column marks a comment.
269#
270# If ${obsolete} != 0, only entries with an "obsolete" keyword will
271# be printed.  All other keywords must be present.
272#
273# The third field is an optional comma separated list of keywords to
274# control if a record is printed; every keyword listed must be enabled
275# for the record to be printed. The list of all available make variables
276# that can be turned on or off can be found by running in this directory:
277#
278#	make -f mkvars.mk mkvarsyesno
279#
280# These MK<NAME> variables can be used as selectors in the sets as <name>.
281#
282# The following extra keywords are also available, listed by:
283#
284#	make -f mkvars.mk mkextravars
285#
286# These are:
287#    1. The HAVE_<name>:
288#	ssp			${HAVE_SSP} != no
289#	libgcc_eh		${HAVE_LIBGCC_EH} != no
290#	acpi			${HAVE_ACPI} != no
291#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
292#	gcc=<n>			<n> = value of ${HAVE_GCC}
293#	gdb=<n>			<n> = value of ${HAVE_GDB}
294#	mesa_ver=<n>		<n> = value of ${HAVE_MESA_VER}
295#	nvmm			${HAVE_NVMM} != no
296#	openssl=<n>		<n> = value of ${HAVE_OPENSSL}
297#	uefi			${HAVE_UEFI} != no
298#	xorg_server_ver=<n>	<n> = value of ${HAVE_XORG_SERVER_VER}
299#	xorg_glamor		${HAVE_XORG_GLAMOR} != no
300#
301#    2. The USE_<name>:
302#	use_inet6		${USE_INET6} != no
303#	use_kerberos		${USE_KERBEROS} != no
304#	use_ldap		${USE_LDAP} != no
305#	use_yp			${USE_YP} != no
306#
307#    3. Finally:
308#	dummy			dummy entry (ignored)
309#	obsolete		file is obsolete, and only printed if
310#				${obsolete} != 0
311#
312#	solaris			${MKDTRACE} != no or ${MKZFS} != no or ${MKCTF} != no
313#
314#
315#	endian=<n>		<n> = value of ${TARGET_ENDIANNESS}
316#
317#
318#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
319#				  automatically append ".gz" to the filename
320#
321#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
322#				  automatically append ".gz" to the filename
323#
324list_set_files()
325{
326	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
327		verbose=false
328	else
329		verbose=true
330	fi
331	local CONFIGS="$( list_kernel_configs )"
332	print_set_lists "$@" | \
333	${AWK} -v obsolete=${obsolete} '
334		function addkmod(line, fname, prefix, pat, patlen) {
335			if (substr(line, 1, patlen) != pat) {
336				return
337			}
338			for (d in kmodarchdirs) {
339				xd = prefix kmodarchdirs[d]
340				xline = xd substr(line, patlen + 1)
341				xfname = xd substr(fname, patlen + 1)
342				list[xline] = xfname
343				emit(xline)
344			}
345		}
346		function adddebugkernel(line, fname, pat, patlen) {
347			if (pat == "" || substr(line, 1, patlen) != pat) {
348				return 0
349			}
350			split("'"${CONFIGS}"'", configs)
351			for (d in configs) {
352				xfname = fname
353				sub("@CONFIG@", configs[d], xfname)
354				xline = line;
355				sub("@CONFIG@", configs[d], xline)
356				list[xline] = xfname
357				emit(xline)
358			}
359			return 1
360		}
361		function emit(fname) {
362			emitf[fname] = 1
363		}
364		BEGIN {
365			if (obsolete)
366				wanted["obsolete"] = 1
367
368			ncpaths = 0
369			split("'"${MKVARS}"'", needvars)
370			doingcompat = 0
371			doingcompattests = 0
372			ignoredkeywords["compatdir"] = 1
373			ignoredkeywords["compatfile"] = 1
374			ignoredkeywords["compattestdir"] = 1
375			ignoredkeywords["compattestfile"] = 1
376			ignoredkeywords["compatx11dir"] = 1
377			ignoredkeywords["compatx11file"] = 1
378			for (vi in needvars) {
379				nv = needvars[vi]
380				kw = tolower(nv)
381				sub(/^mk/, "", kw)
382				sub(/^have_/, "", kw)
383				sub(/^target_endianness/, "endian", kw)
384				if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
385					wanted[kw] = 1
386				}
387			}
388
389			if ("compat" in wanted) {
390				doingcompat = 1;
391				split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
392				compatdirkeywords["compatdir"] = 1
393				compatfilekeywords["compatfile"] = 1
394
395				if (wanted["compattests"]) {
396					doingcompattests = 1;
397					compatdirkeywords["compattestdir"] = 1
398					compatfilekeywords["compattestfile"] = 1
399				}
400				if (wanted["compatx11"]) {
401					doingcompatx11 = 1;
402					compatdirkeywords["compatx11dir"] = 1
403					compatfilekeywords["compatx11file"] = 1
404				}
405			}
406
407			if (("kmod" in wanted) && ("compatmodules" in wanted)) {
408				split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
409				kmodprefix = "./stand/"
410				kmodpat = kmodprefix ENVIRON["MACHINE"]
411				l_kmodpat = length(kmodpat)
412				kmoddbprefix = "./usr/libdata/debug/stand/"
413				kmoddbpat = kmoddbprefix ENVIRON["MACHINE"]
414				l_kmoddbpat = length(kmoddbpat)
415			}
416			if ("debug" in wanted) {
417				debugkernelname = "./usr/libdata/debug/netbsd-@CONFIG@.debug"
418				l_debugkernelname = length(debugkernelname);
419			}
420
421			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
422				if ("binutils" in wanted)
423					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
424				if ("gcc" in wanted)
425					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
426				if ("gdb" in wanted)
427					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
428			}
429			if ("acpi" in wanted) {
430				wanted["acpi=" "'"${HAVE_ACPI}"'"] = 1
431			}
432			if ("mesa_ver" in wanted) {
433				wanted["mesa_ver=" "'"${HAVE_MESA_VER}"'"] = 1
434			}
435			if ("nvmm" in wanted) {
436				wanted["nvmm=" "'"${HAVE_NVMM}"'"] = 1
437			}
438			if ("openssl" in wanted) {
439				wanted["openssl=" "'"${HAVE_OPENSSL}"'"] = 1
440			}
441			if ("xorg_server_ver" in wanted) {
442				wanted["xorg_server_ver=" "'"${HAVE_XORG_SERVER_VER}"'"] = 1
443			}
444			if ("uefi" in wanted) {
445				wanted["uefi=" "'"${HAVE_UEFI}"'"] = 1
446			}
447			if (("man" in wanted) && ("catpages" in wanted))
448				wanted[".cat"] = 1
449			if (("man" in wanted) && ("manpages" in wanted))
450				wanted[".man"] = 1
451			if ("endian" in wanted)
452				wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
453			if ("machine" in wanted)
454				wanted["machine=" "'"${MACHINE}"'"] = 1
455			if ("machine_arch" in wanted)
456				wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
457			if ("machine_cpu" in wanted)
458				wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
459		}
460
461		/^#/ {
462			next;
463		}
464
465		/^-/ {
466			notwanted[substr($1, 2)] = 1;
467			delete list [substr($1, 2)];
468			next;
469		}
470
471		NF > 2 && $3 != "-" {
472			if (notwanted[$1] != "")
473				next;
474			split($3, keywords, ",")
475			show = 1
476			haveobs = 0
477			iscompatfile = 0
478			havekmod = 0
479			iscompatdir = 0
480			omitcompat = 0
481			takecompat[$1] = 0
482			for (ki in keywords) {
483				kw = keywords[ki]
484				if (("manz" in wanted) &&
485				    (kw == ".cat" || kw == ".man"))
486					$1 = $1 ".gz"
487				if (substr(kw, 1, 1) == "!") {
488					kw = substr(kw, 2)
489					if (kw in wanted)
490						show = 0
491				} else if (kw in compatdirkeywords) {
492					iscompatdir = 1
493				} else if (kw in compatfilekeywords) {
494					iscompatfile = 1
495				} else if (kw == "nocompatmodules") {
496					havekmod = -1
497				} else if (kw == "omitcompat") {
498					omitcompat = 1
499				} else if (kw ~ /^takecompat=/) {
500					takecompat[$1] = 1
501					takecompatarch[substr(kw,
502					    1 + length("takecompat=")), $1] = 1
503				} else if (kw in ignoredkeywords) {
504					# ignore
505				} else if (! (kw in wanted)) {
506					show = 0
507				} else if (kw == "kmod" && havekmod == 0) {
508					havekmod = 1
509				}
510				if (kw == "obsolete")
511					haveobs = 1
512			}
513
514			if (takecompat[$1] && !(iscompatdir || iscompatfile)) {
515				next
516			}
517			if (iscompatdir && !omitcompat) {
518				for (d in cpaths) {
519					if (cpaths[d] == $1 "/") {
520						break
521					}
522				}
523				cpaths[ncpaths++] = $1 "/"
524			}
525			if (obsolete && ! haveobs)
526				next
527			if (!show)
528				next
529			if (adddebugkernel($0, $1, debugkernelname, l_debugkernelname))
530				next
531
532			list[$1] = $0
533			if (havekmod > 0) {
534				addkmod($0, $1, kmodprefix, kmodpat, l_kmodpat)
535				addkmod($0, $1, kmoddbprefix, kmoddbpat, l_kmoddbpat)
536				emit($1)
537				next
538			}
539
540			if (!doingcompat || !(iscompatfile || iscompatdir)) {
541				emit($1)
542				next
543			}
544
545			if (iscompatfile) {
546				if (omitcompat) {
547					emit($1)
548				} else if (takecompat[$1]) {
549					emitcompat[$1] = 1
550				} else {
551					emit($1)
552					emitcompat[$1] = 1
553				}
554				next
555			}
556			if (iscompatdir) {
557				if (omitcompat) {
558					# /lib in base
559					emit($1)
560				} else if (takecompat[$1]) {
561					# /lib in base32
562					# nothing to do
563				} else {
564					# /usr/include in comp
565					emit($1)
566				}
567			} else {
568				emit($1)
569			}
570			if (omitcompat)
571				next
572			for (d in compatarchdirs) {
573				if (takecompat[$1] &&
574				    !takecompatarch[compatarchdirs[d], $1])
575					continue
576				tmp = $0
577				xfile = $1 "/" compatarchdirs[d]
578				tmp = xfile substr(tmp, length($1) + 1)
579				if (xfile in notwanted)
580					continue;
581				sub("compatdir","compat",tmp);
582				sub("compattestdir","compat",tmp);
583				list[xfile] = tmp
584				emit(xfile)
585			}
586			next
587		}
588
589		{
590			if ($1 in notwanted)
591				next;
592			if (! obsolete) {
593				list[$1] = $0
594				emit($1)
595			}
596		}
597
598		END {
599			for (i in list) {
600				if (i in emitf)
601					print list[i]
602				if (! (i in emitcompat))
603					continue;
604				l_i = length(i)
605				l = 0
606				for (j in cpaths) {
607					lx = length(cpaths[j])
608					if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
609						continue;
610					}
611					if (lx > l) {
612						l = lx;
613						cpath = cpaths[j];
614					}
615				}
616				for (d in compatarchdirs) {
617					if (takecompat[$1] &&
618					    !takecompatarch[compatarchdirs[d],
619						i]) {
620						continue
621					}
622					tmp = list[i]
623					extrapath = compatarchdirs[d] "/"
624					xfile = cpath extrapath substr(i, l + 1)
625					if (xfile in notwanted)
626						continue;
627					sub("compatfile","compat",tmp);
628					sub("compattestfile","compat",tmp);
629					tmp = xfile substr(tmp, l_i + 1)
630					print tmp;
631				}
632			}
633		}'
634
635}
636
637#
638# list_set_lists setname
639#
640# Print to stdout a list of files, one filename per line, which
641# concatenate to create the packing list for setname. E.g.,
642#
643# 	.../lists/base/mi
644# 	.../lists/base/rescue.mi
645# 	.../lists/base/md.i386
646#		[...]
647#
648# For a given setname $set, the following files may be selected from
649# .../list/$set:
650#	mi
651#	mi.ext.*
652#	ad.${MACHINE_ARCH}
653# (or)	ad.${MACHINE_CPU}
654#	ad.${MACHINE_CPU}.shl
655#	md.${MACHINE}.${MACHINE_ARCH}
656# (or)	md.${MACHINE}
657#	stl.mi
658#	stl.${stlib}
659#	shl.mi
660#	shl.mi.ext.*
661#	shl.${shlib}
662#	shl.${shlib}.ext.*
663#	module.mi			if ${module} != no
664#	module.${MACHINE}		if ${module} != no
665#	module.ad.${MACHINE_ARCH}	if ${module} != no
666# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
667#	rescue.shl
668#	rescue.${MACHINE}
669#	rescue.ad.${MACHINE_ARCH}
670# (or)	rescue.ad.${MACHINE_CPU}
671# 	rescue.ad.${MACHINE_CPU}.shl
672#
673# Environment:
674# 	shlib
675# 	stlib
676#
677list_set_lists()
678{
679	setname=$1
680
681	list_set_lists_mi $setname
682	list_set_lists_ad $setname
683	list_set_lists_md $setname
684	list_set_lists_stl $setname
685	list_set_lists_shl $setname
686	list_set_lists_module $setname
687	list_set_lists_rescue $setname
688	return 0
689}
690
691list_set_lists_mi()
692{
693	setdir=$setsdir/lists/$1
694	# always exist!
695	echo $setdir/mi
696}
697
698list_set_lists_ad()
699{
700	setdir=$setsdir/lists/$1
701	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
702	list_set_lists_common_ad $1
703}
704
705list_set_lists_md()
706{
707	setdir=$setsdir/lists/$1
708	echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
709	echo_if_exist $setdir/md.${MACHINE}
710}
711
712list_set_lists_stl()
713{
714	setdir=$setsdir/lists/$1
715	echo_if_exist $setdir/stl.mi
716	echo_if_exist $setdir/stl.${stlib}
717}
718
719list_set_lists_shl()
720{
721	setdir=$setsdir/lists/$1
722	[ "$shlib" != "no" ] || return
723	echo_if_exist $setdir/shl.mi
724	echo_if_exist $setdir/shl.${shlib}
725}
726
727list_set_lists_module()
728{
729	setdir=$setsdir/lists/$1
730	[ "$module" != "no" ] || return
731	echo_if_exist $setdir/module.mi
732	echo_if_exist $setdir/module.${MACHINE}
733	echo_if_exist $setdir/module.ad.${MACHINE}
734	echo_if_exist $setdir/module.md.${MACHINE}
735	# XXX module never has .shl
736	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
737	list_set_lists_common_ad $1 module
738}
739
740list_set_lists_rescue()
741{
742	setdir=$setsdir/lists/$1
743	echo_if_exist $setdir/rescue.mi
744	echo_if_exist $setdir/rescue.${MACHINE}
745	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
746	list_set_lists_common_ad $1 rescue
747}
748
749list_set_lists_common_ad()
750{
751	setdir=$setsdir/lists/$1; _prefix=$2
752
753	[ -n "$_prefix" ] && prefix="$_prefix".
754
755	# Prefer a <prefix>.ad.${MACHINE_ARCH} over a
756	# <prefix>.ad.${MACHINE_CPU}, since the arch-
757	# specific one will be more specific than the
758	# cpu-specific one.
759	echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
760	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
761	[ "$shlib" != "no" ] && \
762	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
763}
764
765echo_if_exist()
766{
767	[ -f $1 ] && echo $1
768	return $?
769}
770
771echo_if_exist_foreach()
772{
773	local _list=$1; shift
774	for _suffix in $@; do
775		echo_if_exist ${_list}.${_suffix}
776	done
777}
778
779print_set_lists()
780{
781	for setname; do
782		list=$(list_set_lists $setname)
783		for l in $list; do
784			echo $l
785			if $verbose; then
786				echo >&2 "DEBUG: list_set_files: $l"
787			fi
788		done \
789		| ${XARGS} ${SED} ${SUBST} \
790		| case $setname in
791		base|debug)
792			awk '
793				!/^#/ && !/^$/ {
794					print $1, $2, \
795					    ($3 ? $3"," : "")"omitcompat"
796				}
797			'
798			;;
799		*)	cat
800			;;
801		esac
802
803		case $setname in
804		base32|base64)
805			ursetname=base
806			;;
807		debug32|debug64)
808			ursetname=debug
809			;;
810		*)	continue
811			;;
812		esac
813		case $setname in
814		*32)	compatarches=$compat32arches
815			;;
816		*64)	compatarches=$compat64arches
817			;;
818		esac
819		list=$(list_set_lists $ursetname)
820		for l in $list; do
821			echo $l
822			if $verbose; then
823				echo >&2 "DEBUG: list_set_files: $l"
824			fi
825		done \
826		| ${XARGS} ${SED} ${SUBST} \
827		| awk -v compatarches="$compatarches" '
828			BEGIN {
829				split(compatarches, compatarch, " ")
830				flags = ""
831				for (i in compatarch)
832					flags = (flags ? flags"," : "") \
833					    "takecompat="compatarch[i]
834			}
835			!/^#/ && !/^$/ {
836				print $1, $2, ($3 ? $3"," : "")flags
837			}
838		'
839	done
840}
841
842
843list_kernel_configs()
844{
845	(cd ${NETBSDSRCDIR}/etc
846	MAKEFLAGS= \
847	${MAKE} -m ${NETBSDSRCDIR}/share/mk -V '${ALL_KERNELS}')
848}
849
850# arch_to_cpu mach
851#
852# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
853# as determined by <bsd.own.mk>.
854#
855arch_to_cpu()
856{
857	MACHINE_ARCH=${1} MAKEFLAGS= \
858	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
859		-f ${NETBSDSRCDIR}/share/mk/bsd.own.mk \
860		-V '${MACHINE_CPU}'
861}
862
863# arch_to_endian mach
864#
865# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
866# as determined by <bsd.endian.mk>.
867#
868arch_to_endian()
869{
870	MACHINE_ARCH=${1} MAKEFLAGS= \
871	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
872		-f ${NETBSDSRCDIR}/share/mk/bsd.endian.mk \
873		-V '${TARGET_ENDIANNESS}'
874}
875
876#####
877
878# print_mkvars
879print_mkvars()
880{
881	for v in $MKVARS; do
882		eval echo $v=\$$v
883	done
884}
885
886# print_set_lists_{base,x,ext}
887# list_set_lists_{base,x,ext}
888# list_set_files_{base,x,ext}
889for func in print_set_lists list_set_lists list_set_files; do
890	for x in base x ext; do
891		if [ $x = base ]; then
892			list=nlists
893		else
894			list=${x}lists
895		fi
896		eval ${func}_${x} \(\) \{ $func \$$list \; \}
897	done
898done
899