sets.subr revision 1.210
11.210Smartin#	$NetBSD: sets.subr,v 1.210 2025/02/24 18:02:02 martin Exp $
21.1Sdyoung#
31.9Slukem
41.9Slukem#
51.11Slukem# The following variables contain defaults for sets.subr functions and callers:
61.9Slukem#	setsdir			path to src/distrib/sets
71.9Slukem#	nlists			list of base sets
81.9Slukem#	xlists			list of x11 sets
91.9Slukem#	obsolete		controls if obsolete files are selected instead
101.76Stsutsui#	module			if != "no", enable MODULE sets
111.9Slukem#	shlib			shared library format (a.out, elf, or "")
121.9Slukem#	stlib			static library format (a.out, elf)
131.11Slukem#
141.11Slukem# The following <bsd.own.mk> variables are exported to the environment:
151.203Srillig#	MACHINE
161.11Slukem#	MACHINE_ARCH
171.11Slukem#	MACHINE_CPU
181.192Sjmcneill#	HAVE_ACPI
191.87Sskrll#	HAVE_BINUTILS
201.48Smrg#	HAVE_GCC
211.52Slukem#	HAVE_GDB
221.193Sjmcneill#	HAVE_NVMM
231.193Sjmcneill#	HAVE_OPENSSL
241.143Snakayama#	HAVE_SSP
251.192Sjmcneill#	HAVE_UEFI
261.210Smartin#	HAVE_EFI_RT
271.11Slukem#	TOOLCHAIN_MISSING
281.11Slukem#	OBJECT_FMT
291.22Slukem# as well as:
301.22Slukem#
311.95Suebayasi
321.42Sapb#
331.42Sapb# The following variables refer to tools that are used when building sets:
341.42Sapb#
351.43Sapb: ${AWK:=awk}
361.42Sapb: ${CKSUM:=cksum}
371.43Sapb: ${COMM:=comm}
381.44Sapb: ${DATE:=date}
391.43Sapb: ${DB:=db}
401.43Sapb: ${EGREP:=egrep}
411.43Sapb: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
421.44Sapb: ${FGREP:=fgrep}
431.43Sapb: ${FIND:=find}
441.44Sapb: ${GREP:=grep}
451.43Sapb: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
461.99Sapb: ${HOSTNAME_CMD:=hostname}	# ${HOSTNAME} is special to bash(1)
471.42Sapb: ${HOST_SH:=sh}
481.43Sapb: ${IDENT:=ident}
491.43Sapb: ${JOIN:=join}
501.43Sapb: ${LS:=ls}
511.43Sapb: ${MAKE:=make}
521.42Sapb: ${MKTEMP:=mktemp}
531.43Sapb: ${MTREE:=mtree}
541.43Sapb: ${PASTE:=paste}
551.42Sapb: ${PAX:=pax}
561.43Sapb: ${PRINTF:=printf}
571.43Sapb: ${SED:=sed}
581.43Sapb: ${SORT:=sort}
591.44Sapb: ${STAT:=stat}
601.44Sapb: ${TSORT:=tsort}
611.43Sapb: ${UNAME:=uname}
621.43Sapb: ${WC:=wc}
631.118Suebayasi: ${XARGS:=xargs}
641.43Sapb
651.45Sapb#
661.45Sapb# If printf is a shell builtin command, then we can
671.45Sapb# implement cheaper versions of basename and dirname
681.45Sapb# that do not involve any fork/exec overhead.
691.45Sapb# If printf is not builtin, approximate it using echo,
701.45Sapb# and hope there are no weird file names that cause
711.45Sapb# some versions of echo to do the wrong thing.
721.45Sapb# (Converting to this version of dirname speeded up the
731.45Sapb# syspkgdeps script by an order of magnitude, from 68
741.45Sapb# seconds to 6.3 seconds on one particular host.)
751.45Sapb#
761.45Sapb# Note that naive approximations for dirname
771.45Sapb# using ${foo%/*} do not do the right thing in cases
781.45Sapb# where the result should be "/" or ".".
791.45Sapb#
801.45Sapbcase "$(type printf)" in
811.45Sapb*builtin*)
821.45Sapb	basename ()
831.45Sapb	{
841.45Sapb		local bn
851.45Sapb		bn="${1##*/}"
861.45Sapb		bn="${bn%$2}"
871.45Sapb		printf "%s\n" "$bn"
881.45Sapb	}
891.45Sapb	dirname ()
901.45Sapb	{
911.45Sapb		local dn
921.45Sapb		case "$1" in
931.45Sapb		?*/*)	dn="${1%/*}" ;;
941.45Sapb		/*)	dn=/ ;;
951.45Sapb		*)	dn=. ;;
961.45Sapb		esac
971.45Sapb		printf "%s\n" "$dn"
981.45Sapb	}
991.45Sapb	;;
1001.45Sapb*)
1011.45Sapb	basename ()
1021.45Sapb	{
1031.45Sapb		local bn
1041.45Sapb		bn="${1##*/}"
1051.45Sapb		bn="${bn%$2}"
1061.45Sapb		echo "$bn"
1071.45Sapb	}
1081.45Sapb	dirname ()
1091.45Sapb	{
1101.45Sapb		local dn
1111.45Sapb		case "$1" in
1121.45Sapb		?*/*)	dn="${1%/*}" ;;
1131.45Sapb		/*)	dn=/ ;;
1141.45Sapb		*)	dn=. ;;
1151.45Sapb		esac
1161.45Sapb		echo "$dn"
1171.45Sapb	}
1181.45Sapb	;;
1191.45Sapbesac
1201.45Sapb
1211.108Suebayasi#####
1221.108Suebayasi
1231.9SlukemoIFS=$IFS
1241.9SlukemIFS="
1251.9Slukem"
1261.100Suebayasi
1271.180Schristosfor x in $( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
1281.108Suebayasi	eval export $x
1291.9Slukemdone
1301.100Suebayasi
1311.9SlukemIFS=$oIFS
1321.9Slukem
1331.180SchristosMKVARS="$( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )"
1341.100Suebayasi
1351.105Suebayasi#####
1361.105Suebayasi
1371.117Suebayasisetsdir=${rundir}
1381.9Slukemobsolete=0
1391.91Sdyoungif [ "${MKKMOD}" = "no" ]; then
1401.91Sdyoung	module=no			# MODULEs are off.
1411.125Snjoly	modset=""
1421.125Snjolyelse
1431.125Snjoly	module=yes
1441.125Snjoly	modset="modules"
1451.125Snjolyfi
1461.125Snjolyif [ "${MKATF}" = "no" ]; then
1471.125Snjoly	testset=""
1481.125Snjolyelse
1491.125Snjoly	testset="tests"
1501.9Slukemfi
1511.171Smattif [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then
1521.141Schristos	debugset=""
1531.142Schristos	xdebugset=""
1541.141Schristoselse
1551.141Schristos	debugset="debug"
1561.142Schristos	xdebugset="xdebug"
1571.141Schristosfi
1581.205Sniaif [ -z "${debugset}" -o "${MKCOMPAT}" = "no" ]; then
1591.205Snia	debug32set=""
1601.205Sniaelse
1611.205Snia	debug32set="debug32"
1621.205Sniafi
1631.206Sniaif [ -z "${debug32set}" ]; then
1641.206Snia	debug64set=""
1651.206Sniaelse
1661.206Snia	if [ "${MACHINE_ARCH}" = "mips64eb" -o "${MACHINE_ARCH}" = "mips64el" ]; then
1671.206Snia		debug64set="debug64"
1681.206Snia	else
1691.206Snia		debug64set=""
1701.206Snia	fi
1711.206Sniafi
1721.191Sjmcneillif [ "${MKDTB}" = "no" ]; then
1731.191Sjmcneill	dtbset=""
1741.191Sjmcneillelse
1751.191Sjmcneill	dtbset="dtb"
1761.191Sjmcneillfi
1771.205Sniaif [ "${MKHTML}" = "no" ]; then
1781.205Snia	manhtmlset=""
1791.205Sniaelse
1801.205Snia	manhtmlset="manhtml"
1811.205Sniafi
1821.205Sniaif [ "${MKCOMPAT}" = "no" ]; then
1831.205Snia	base32set=""
1841.205Sniaelse
1851.205Snia	base32set="base32"
1861.205Sniafi
1871.206Sniaif [ "${MKCOMPAT}" != "no" ]; then
1881.206Snia	if [ "${MACHINE_ARCH}" = "mips64eb" -o "${MACHINE_ARCH}" = "mips64el" ]; then
1891.206Snia		base64set="base64"
1901.206Snia	else
1911.206Snia		base64set=""
1921.206Snia	fi
1931.206Sniaelse
1941.206Snia	base64set=""
1951.206Sniafi
1961.206Snia
1971.207Sriastrad# XXX This should not be encoded here -- this mostly duplicates
1981.207Sriastrad# information in compat/archdirs.mk, except that it also identifies
1991.207Sriastrad# which compat architectures are `32-bit' and which ones are `64-bit'.
2001.207Sriastradcase $MACHINE_ARCH in
2011.207Sriastradaarch64)
2021.207Sriastrad	compat32arches='eabi eabihf'
2031.207Sriastrad	;;
2041.207Sriastradaarch64eb)
2051.207Sriastrad	compat32arches=eabi
2061.207Sriastrad	;;
2071.207Sriastradmips64eb|mips64el)
2081.207Sriastrad	compat32arches=o32
2091.207Sriastrad	compat64arches=64
2101.207Sriastrad	;;
2111.207Sriastradmipsn64eb|mipsn64el)
2121.207Sriastrad	compat32arches='n32 o32'
2131.207Sriastrad	;;
2141.207Sriastradpowerpc64)
2151.207Sriastrad	compat32arches=powerpc
2161.207Sriastrad	;;
2171.207Sriastradriscv64)
2181.208Sriastrad	compat32arches=rv32
2191.207Sriastrad	;;
2201.207Sriastradsparc64)
2211.207Sriastrad	compat32arches=sparc
2221.207Sriastrad	;;
2231.207Sriastradx86_64)	compat32arches=i386
2241.207Sriastrad	;;
2251.207Sriastradesac
2261.209Sriastrad: ${compat32arches:=}
2271.207Sriastrad: ${compat64arches:=}
2281.207Sriastrad
2291.205Snia
2301.31Sjmc# Determine lib type. Do this first so stlib also gets set.
2311.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
2321.9Slukem	shlib=elf
2331.9Slukemelse
2341.9Slukem	shlib=aout
2351.9Slukemfi
2361.9Slukemstlib=$shlib
2371.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
2381.31Sjmcif [ "${MKPIC}" = "no" ]; then
2391.31Sjmc	shlib=no
2401.31Sjmcfi
2411.206Snianlists="base $base32set $base64set comp $debugset $debug32set $debug64set $dtbset etc games gpufw man $manhtmlset misc $modset rescue $testset text"
2421.142Schristosxlists="xbase xcomp $xdebugset xetc xfont xserver"
2431.9Slukem
2441.136SchristosOSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
2451.188Schristosif [ "${KERNEL_DIR}" = "yes" ]; then
2461.188Schristos	MODULEDIR="netbsd/modules"
2471.188Schristoselse
2481.188Schristos	MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
2491.188Schristosfi
2501.62SadSUBST="s#@MODULEDIR@#${MODULEDIR}#g"
2511.62SadSUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
2521.62SadSUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
2531.60Sad
2541.9Slukem#
2551.9Slukem# list_set_files setfile [...]
2561.203Srillig#
2571.9Slukem# Produce a packing list for setfile(s).
2581.9Slukem# In each file, a record consists of a path and a System Package name,
2591.9Slukem# separated by whitespace. E.g.,
2601.9Slukem#
2611.210Smartin# 	# $NetBSD: sets.subr,v 1.210 2025/02/24 18:02:02 martin Exp $
2621.9Slukem# 	.			base-sys-root	[keyword[,...]]
2631.9Slukem# 	./altroot		base-sys-root
2641.9Slukem# 	./bin			base-sys-root
2651.9Slukem# 	./bin/[			base-util-root
2661.9Slukem# 	./bin/cat		base-util-root
2671.9Slukem#		[...]
2681.9Slukem#
2691.9Slukem# A # in the first column marks a comment.
2701.9Slukem#
2711.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
2721.52Slukem# be printed.  All other keywords must be present.
2731.9Slukem#
2741.9Slukem# The third field is an optional comma separated list of keywords to
2751.9Slukem# control if a record is printed; every keyword listed must be enabled
2761.204Srillig# for the record to be printed. The list of all available make variables
2771.179Schristos# that can be turned on or off can be found by running in this directory:
2781.179Schristos#
2791.179Schristos#	make -f mkvars.mk mkvarsyesno
2801.179Schristos#
2811.179Schristos# These MK<NAME> variables can be used as selectors in the sets as <name>.
2821.203Srillig#
2831.179Schristos# The following extra keywords are also available, listed by:
2841.179Schristos#
2851.179Schristos#	make -f mkvars.mk mkextravars
2861.13Slukem#
2871.179Schristos# These are:
2881.179Schristos#    1. The HAVE_<name>:
2891.179Schristos#	ssp			${HAVE_SSP} != no
2901.160Sjoerg#	libgcc_eh		${HAVE_LIBGCC_EH} != no
2911.192Sjmcneill#	acpi			${HAVE_ACPI} != no
2921.87Sskrll#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
2931.52Slukem#	gcc=<n>			<n> = value of ${HAVE_GCC}
2941.52Slukem#	gdb=<n>			<n> = value of ${HAVE_GDB}
2951.192Sjmcneill#	mesa_ver=<n>		<n> = value of ${HAVE_MESA_VER}
2961.193Sjmcneill#	nvmm			${HAVE_NVMM} != no
2971.183Schristos#	openssl=<n>		<n> = value of ${HAVE_OPENSSL}
2981.192Sjmcneill#	uefi			${HAVE_UEFI} != no
2991.210Smartin#	efi_rt			${HAVE_EFI_RT} != no
3001.177Smrg#	xorg_server_ver=<n>	<n> = value of ${HAVE_XORG_SERVER_VER}
3011.186Smrg#	xorg_glamor		${HAVE_XORG_GLAMOR} != no
3021.52Slukem#
3031.179Schristos#    2. The USE_<name>:
3041.41Slukem#	use_inet6		${USE_INET6} != no
3051.41Slukem#	use_kerberos		${USE_KERBEROS} != no
3061.179Schristos#	use_ldap		${USE_LDAP} != no
3071.41Slukem#	use_yp			${USE_YP} != no
3081.41Slukem#
3091.179Schristos#    3. Finally:
3101.179Schristos#	dummy			dummy entry (ignored)
3111.203Srillig#	obsolete		file is obsolete, and only printed if
3121.179Schristos#				${obsolete} != 0
3131.179Schristos#
3141.179Schristos#	solaris			${MKDTRACE} != no or ${MKZFS} != no or ${MKCTF} != no
3151.179Schristos#
3161.179Schristos#
3171.179Schristos#	endian=<n>		<n> = value of ${TARGET_ENDIANNESS}
3181.179Schristos#
3191.179Schristos#
3201.195Skamil#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
3211.195Skamil#				  automatically append ".gz" to the filename
3221.195Skamil#
3231.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
3241.22Slukem#				  automatically append ".gz" to the filename
3251.1Sdyoung#
3261.8Slukemlist_set_files()
3271.8Slukem{
3281.83Sapb	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
3291.65She		verbose=false
3301.65She	else
3311.65She		verbose=true
3321.65She	fi
3331.198Schristos	local CONFIGS="$( list_kernel_configs )"
3341.116Suebayasi	print_set_lists "$@" | \
3351.43Sapb	${AWK} -v obsolete=${obsolete} '
3361.190Schristos		function addkmod(line, fname, prefix, pat, patlen) {
3371.190Schristos			if (substr(line, 1, patlen) != pat) {
3381.198Schristos				return
3391.190Schristos			}
3401.190Schristos			for (d in kmodarchdirs) {
3411.190Schristos				xd = prefix kmodarchdirs[d]
3421.198Schristos				xline = xd substr(line, patlen + 1)
3431.198Schristos				xfname = xd substr(fname, patlen + 1)
3441.198Schristos				list[xline] = xfname
3451.207Sriastrad				emit(xline)
3461.190Schristos			}
3471.190Schristos		}
3481.198Schristos		function adddebugkernel(line, fname, pat, patlen) {
3491.199Schristos			if (pat == "" || substr(line, 1, patlen) != pat) {
3501.198Schristos				return 0
3511.198Schristos			}
3521.198Schristos			split("'"${CONFIGS}"'", configs)
3531.198Schristos			for (d in configs) {
3541.198Schristos				xfname = fname
3551.200Schristos				sub("@CONFIG@", configs[d], xfname)
3561.198Schristos				xline = line;
3571.200Schristos				sub("@CONFIG@", configs[d], xline)
3581.198Schristos				list[xline] = xfname
3591.207Sriastrad				emit(xline)
3601.198Schristos			}
3611.198Schristos			return 1
3621.198Schristos		}
3631.207Sriastrad		function emit(fname) {
3641.207Sriastrad			emitf[fname] = 1
3651.207Sriastrad		}
3661.9Slukem		BEGIN {
3671.52Slukem			if (obsolete)
3681.52Slukem				wanted["obsolete"] = 1
3691.203Srillig
3701.207Sriastrad			ncpaths = 0
3711.100Suebayasi			split("'"${MKVARS}"'", needvars)
3721.165Smatt			doingcompat = 0
3731.165Smatt			doingcompattests = 0
3741.165Smatt			ignoredkeywords["compatdir"] = 1
3751.165Smatt			ignoredkeywords["compatfile"] = 1
3761.165Smatt			ignoredkeywords["compattestdir"] = 1
3771.165Smatt			ignoredkeywords["compattestfile"] = 1
3781.170Smatt			ignoredkeywords["compatx11dir"] = 1
3791.170Smatt			ignoredkeywords["compatx11file"] = 1
3801.52Slukem			for (vi in needvars) {
3811.52Slukem				nv = needvars[vi]
3821.52Slukem				kw = tolower(nv)
3831.52Slukem				sub(/^mk/, "", kw)
3841.143Snakayama				sub(/^have_/, "", kw)
3851.148Smatt				sub(/^target_endianness/, "endian", kw)
3861.167Smatt				if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
3871.203Srillig					wanted[kw] = 1
3881.167Smatt				}
3891.166Smatt			}
3901.166Smatt
3911.167Smatt			if ("compat" in wanted) {
3921.166Smatt				doingcompat = 1;
3931.166Smatt				split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
3941.166Smatt				compatdirkeywords["compatdir"] = 1
3951.166Smatt				compatfilekeywords["compatfile"] = 1
3961.166Smatt
3971.166Smatt				if (wanted["compattests"]) {
3981.165Smatt					doingcompattests = 1;
3991.165Smatt					compatdirkeywords["compattestdir"] = 1
4001.165Smatt					compatfilekeywords["compattestfile"] = 1
4011.166Smatt				}
4021.170Smatt				if (wanted["compatx11"]) {
4031.170Smatt					doingcompatx11 = 1;
4041.170Smatt					compatdirkeywords["compatx11dir"] = 1
4051.170Smatt					compatfilekeywords["compatx11file"] = 1
4061.170Smatt				}
4071.166Smatt			}
4081.166Smatt
4091.167Smatt			if (("kmod" in wanted) && ("compatmodules" in wanted)) {
4101.166Smatt				split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
4111.190Schristos				kmodprefix = "./stand/"
4121.190Schristos				kmodpat = kmodprefix ENVIRON["MACHINE"]
4131.166Smatt				l_kmodpat = length(kmodpat)
4141.203Srillig				kmoddbprefix = "./usr/libdata/debug/stand/"
4151.190Schristos				kmoddbpat = kmoddbprefix ENVIRON["MACHINE"]
4161.190Schristos				l_kmoddbpat = length(kmoddbpat)
4171.52Slukem			}
4181.198Schristos			if ("debug" in wanted) {
4191.201Schristos				debugkernelname = "./usr/libdata/debug/netbsd-@CONFIG@.debug"
4201.198Schristos				l_debugkernelname = length(debugkernelname);
4211.198Schristos			}
4221.52Slukem
4231.52Slukem			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
4241.90Sdyoung				if ("binutils" in wanted)
4251.90Sdyoung					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
4261.90Sdyoung				if ("gcc" in wanted)
4271.90Sdyoung					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
4281.90Sdyoung				if ("gdb" in wanted)
4291.90Sdyoung					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
4301.9Slukem			}
4311.192Sjmcneill			if ("acpi" in wanted) {
4321.192Sjmcneill				wanted["acpi=" "'"${HAVE_ACPI}"'"] = 1
4331.192Sjmcneill			}
4341.192Sjmcneill			if ("mesa_ver" in wanted) {
4351.192Sjmcneill				wanted["mesa_ver=" "'"${HAVE_MESA_VER}"'"] = 1
4361.192Sjmcneill			}
4371.193Sjmcneill			if ("nvmm" in wanted) {
4381.193Sjmcneill				wanted["nvmm=" "'"${HAVE_NVMM}"'"] = 1
4391.193Sjmcneill			}
4401.183Schristos			if ("openssl" in wanted) {
4411.183Schristos				wanted["openssl=" "'"${HAVE_OPENSSL}"'"] = 1
4421.183Schristos			}
4431.178Smrg			if ("xorg_server_ver" in wanted) {
4441.178Smrg				wanted["xorg_server_ver=" "'"${HAVE_XORG_SERVER_VER}"'"] = 1
4451.177Smrg			}
4461.192Sjmcneill			if ("uefi" in wanted) {
4471.192Sjmcneill				wanted["uefi=" "'"${HAVE_UEFI}"'"] = 1
4481.185Smrg			}
4491.210Smartin			if ("efi_rt" in wanted) {
4501.210Smartin				wanted["efi_rt=" "'"${HAVE_EFI_RT}"'"] = 1
4511.210Smartin			}
4521.195Skamil			if (("man" in wanted) && ("catpages" in wanted))
4531.195Skamil				wanted[".cat"] = 1
4541.52Slukem			if (("man" in wanted) && ("manpages" in wanted))
4551.52Slukem				wanted[".man"] = 1
4561.148Smatt			if ("endian" in wanted)
4571.148Smatt				wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
4581.162Smrg			if ("machine" in wanted)
4591.162Smrg				wanted["machine=" "'"${MACHINE}"'"] = 1
4601.162Smrg			if ("machine_arch" in wanted)
4611.162Smrg				wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
4621.162Smrg			if ("machine_cpu" in wanted)
4631.162Smrg				wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
4641.9Slukem		}
4651.9Slukem
4661.9Slukem		/^#/ {
4671.9Slukem			next;
4681.9Slukem		}
4691.9Slukem
4701.127Smatt		/^-/ {
4711.127Smatt			notwanted[substr($1, 2)] = 1;
4721.127Smatt			delete list [substr($1, 2)];
4731.127Smatt			next;
4741.127Smatt		}
4751.203Srillig
4761.9Slukem		NF > 2 && $3 != "-" {
4771.127Smatt			if (notwanted[$1] != "")
4781.127Smatt				next;
4791.9Slukem			split($3, keywords, ",")
4801.9Slukem			show = 1
4811.52Slukem			haveobs = 0
4821.167Smatt			iscompatfile = 0
4831.165Smatt			havekmod = 0
4841.165Smatt			iscompatdir = 0
4851.207Sriastrad			omitcompat = 0
4861.207Sriastrad			takecompat[$1] = 0
4871.9Slukem			for (ki in keywords) {
4881.9Slukem				kw = keywords[ki]
4891.22Slukem				if (("manz" in wanted) &&
4901.22Slukem				    (kw == ".cat" || kw == ".man"))
4911.22Slukem					$1 = $1 ".gz"
4921.134Sjoerg				if (substr(kw, 1, 1) == "!") {
4931.134Sjoerg					kw = substr(kw, 2)
4941.59Sjmmv					if (kw in wanted)
4951.59Sjmmv						show = 0
4961.165Smatt				} else if (kw in compatdirkeywords) {
4971.165Smatt					iscompatdir = 1
4981.165Smatt				} else if (kw in compatfilekeywords) {
4991.167Smatt					iscompatfile = 1
5001.172Smatt				} else if (kw == "nocompatmodules") {
5011.172Smatt					havekmod = -1
5021.207Sriastrad				} else if (kw == "omitcompat") {
5031.207Sriastrad					omitcompat = 1
5041.207Sriastrad				} else if (kw ~ /^takecompat=/) {
5051.207Sriastrad					takecompat[$1] = 1
5061.207Sriastrad					takecompatarch[substr(kw,
5071.207Sriastrad					    1 + length("takecompat=")), $1] = 1
5081.165Smatt				} else if (kw in ignoredkeywords) {
5091.165Smatt					# ignore
5101.167Smatt				} else if (! (kw in wanted)) {
5111.167Smatt					show = 0
5121.172Smatt				} else if (kw == "kmod" && havekmod == 0) {
5131.167Smatt					havekmod = 1
5141.59Sjmmv				}
5151.52Slukem				if (kw == "obsolete")
5161.52Slukem					haveobs = 1
5171.9Slukem			}
5181.207Sriastrad
5191.207Sriastrad			if (takecompat[$1] && !(iscompatdir || iscompatfile)) {
5201.207Sriastrad				next
5211.207Sriastrad			}
5221.207Sriastrad			if (iscompatdir && !omitcompat) {
5231.184Snakayama				for (d in cpaths) {
5241.207Sriastrad					if (cpaths[d] == $1 "/") {
5251.207Sriastrad						break
5261.207Sriastrad					}
5271.184Snakayama				}
5281.184Snakayama				cpaths[ncpaths++] = $1 "/"
5291.184Snakayama			}
5301.52Slukem			if (obsolete && ! haveobs)
5311.52Slukem				next
5321.165Smatt			if (!show)
5331.165Smatt				next
5341.198Schristos			if (adddebugkernel($0, $1, debugkernelname, l_debugkernelname))
5351.198Schristos				next
5361.165Smatt
5371.165Smatt			list[$1] = $0
5381.190Schristos			if (havekmod > 0) {
5391.190Schristos				addkmod($0, $1, kmodprefix, kmodpat, l_kmodpat)
5401.190Schristos				addkmod($0, $1, kmoddbprefix, kmoddbpat, l_kmoddbpat)
5411.207Sriastrad				emit($1)
5421.165Smatt				next
5431.165Smatt			}
5441.165Smatt
5451.207Sriastrad			if (!doingcompat || !(iscompatfile || iscompatdir)) {
5461.207Sriastrad				emit($1)
5471.165Smatt				next
5481.207Sriastrad			}
5491.165Smatt
5501.167Smatt			if (iscompatfile) {
5511.207Sriastrad				if (omitcompat) {
5521.207Sriastrad					emit($1)
5531.207Sriastrad				} else if (takecompat[$1]) {
5541.207Sriastrad					emitcompat[$1] = 1
5551.207Sriastrad				} else {
5561.207Sriastrad					emit($1)
5571.207Sriastrad					emitcompat[$1] = 1
5581.207Sriastrad				}
5591.168Smatt				next
5601.168Smatt			}
5611.207Sriastrad			if (iscompatdir) {
5621.207Sriastrad				if (omitcompat) {
5631.207Sriastrad					# /lib in base
5641.207Sriastrad					emit($1)
5651.207Sriastrad				} else if (takecompat[$1]) {
5661.207Sriastrad					# /lib in base32
5671.207Sriastrad					# nothing to do
5681.207Sriastrad				} else {
5691.207Sriastrad					# /usr/include in comp
5701.207Sriastrad					emit($1)
5711.207Sriastrad				}
5721.207Sriastrad			} else {
5731.207Sriastrad				emit($1)
5741.207Sriastrad			}
5751.207Sriastrad			if (omitcompat)
5761.207Sriastrad				next
5771.165Smatt			for (d in compatarchdirs) {
5781.207Sriastrad				if (takecompat[$1] &&
5791.207Sriastrad				    !takecompatarch[compatarchdirs[d], $1])
5801.207Sriastrad					continue
5811.165Smatt				tmp = $0
5821.165Smatt				xfile = $1 "/" compatarchdirs[d]
5831.165Smatt				tmp = xfile substr(tmp, length($1) + 1)
5841.165Smatt				if (xfile in notwanted)
5851.165Smatt					continue;
5861.165Smatt				sub("compatdir","compat",tmp);
5871.165Smatt				sub("compattestdir","compat",tmp);
5881.165Smatt				list[xfile] = tmp
5891.207Sriastrad				emit(xfile)
5901.165Smatt			}
5911.9Slukem			next
5921.9Slukem		}
5931.9Slukem
5941.9Slukem		{
5951.165Smatt			if ($1 in notwanted)
5961.127Smatt				next;
5971.207Sriastrad			if (! obsolete) {
5981.127Smatt				list[$1] = $0
5991.207Sriastrad				emit($1)
6001.207Sriastrad			}
6011.127Smatt		}
6021.127Smatt
6031.127Smatt		END {
6041.127Smatt			for (i in list) {
6051.207Sriastrad				if (i in emitf)
6061.207Sriastrad					print list[i]
6071.165Smatt				if (! (i in emitcompat))
6081.165Smatt					continue;
6091.165Smatt				l_i = length(i)
6101.165Smatt				l = 0
6111.165Smatt				for (j in cpaths) {
6121.165Smatt					lx = length(cpaths[j])
6131.165Smatt					if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
6141.165Smatt						continue;
6151.165Smatt					}
6161.165Smatt					if (lx > l) {
6171.165Smatt						l = lx;
6181.165Smatt						cpath = cpaths[j];
6191.165Smatt					}
6201.165Smatt				}
6211.165Smatt				for (d in compatarchdirs) {
6221.207Sriastrad					if (takecompat[$1] &&
6231.207Sriastrad					    !takecompatarch[compatarchdirs[d],
6241.207Sriastrad						i]) {
6251.207Sriastrad						continue
6261.207Sriastrad					}
6271.165Smatt					tmp = list[i]
6281.165Smatt					extrapath = compatarchdirs[d] "/"
6291.165Smatt					xfile = cpath extrapath substr(i, l + 1)
6301.165Smatt					if (xfile in notwanted)
6311.165Smatt						continue;
6321.165Smatt					sub("compatfile","compat",tmp);
6331.165Smatt					sub("compattestfile","compat",tmp);
6341.165Smatt					tmp = xfile substr(tmp, l_i + 1)
6351.165Smatt					print tmp;
6361.165Smatt				}
6371.127Smatt			}
6381.9Slukem		}'
6391.9Slukem
6401.1Sdyoung}
6411.1Sdyoung
6421.1Sdyoung#
6431.1Sdyoung# list_set_lists setname
6441.203Srillig#
6451.1Sdyoung# Print to stdout a list of files, one filename per line, which
6461.1Sdyoung# concatenate to create the packing list for setname. E.g.,
6471.1Sdyoung#
6481.1Sdyoung# 	.../lists/base/mi
6491.1Sdyoung# 	.../lists/base/rescue.mi
6501.1Sdyoung# 	.../lists/base/md.i386
6511.9Slukem#		[...]
6521.1Sdyoung#
6531.9Slukem# For a given setname $set, the following files may be selected from
6541.9Slukem# .../list/$set:
6551.9Slukem#	mi
6561.92Suebayasi#	mi.ext.*
6571.11Slukem#	ad.${MACHINE_ARCH}
6581.11Slukem# (or)	ad.${MACHINE_CPU}
6591.11Slukem#	ad.${MACHINE_CPU}.shl
6601.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
6611.11Slukem# (or)	md.${MACHINE}
6621.9Slukem#	stl.mi
6631.92Suebayasi#	stl.${stlib}
6641.9Slukem#	shl.mi
6651.92Suebayasi#	shl.mi.ext.*
6661.92Suebayasi#	shl.${shlib}
6671.92Suebayasi#	shl.${shlib}.ext.*
6681.77Stsutsui#	module.mi			if ${module} != no
6691.77Stsutsui#	module.${MACHINE}		if ${module} != no
6701.77Stsutsui#	module.ad.${MACHINE_ARCH}	if ${module} != no
6711.77Stsutsui# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
6721.9Slukem#	rescue.shl
6731.11Slukem#	rescue.${MACHINE}
6741.11Slukem#	rescue.ad.${MACHINE_ARCH}
6751.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
6761.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
6771.1Sdyoung#
6781.9Slukem# Environment:
6791.1Sdyoung# 	shlib
6801.1Sdyoung# 	stlib
6811.1Sdyoung#
6821.8Slukemlist_set_lists()
6831.8Slukem{
6841.1Sdyoung	setname=$1
6851.1Sdyoung
6861.111Suebayasi	list_set_lists_mi $setname
6871.113Suebayasi	list_set_lists_ad $setname
6881.111Suebayasi	list_set_lists_md $setname
6891.111Suebayasi	list_set_lists_stl $setname
6901.113Suebayasi	list_set_lists_shl $setname
6911.113Suebayasi	list_set_lists_module $setname
6921.111Suebayasi	list_set_lists_rescue $setname
6931.117Suebayasi	return 0
6941.111Suebayasi}
6951.110Suebayasi
6961.111Suebayasilist_set_lists_mi()
6971.111Suebayasi{
6981.111Suebayasi	setdir=$setsdir/lists/$1
6991.113Suebayasi	# always exist!
7001.9Slukem	echo $setdir/mi
7011.111Suebayasi}
7021.110Suebayasi
7031.111Suebayasilist_set_lists_ad()
7041.111Suebayasi{
7051.111Suebayasi	setdir=$setsdir/lists/$1
7061.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
7071.113Suebayasi	list_set_lists_common_ad $1
7081.111Suebayasi}
7091.110Suebayasi
7101.111Suebayasilist_set_lists_md()
7111.111Suebayasi{
7121.111Suebayasi	setdir=$setsdir/lists/$1
7131.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
7141.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}
7151.111Suebayasi}
7161.110Suebayasi
7171.111Suebayasilist_set_lists_stl()
7181.111Suebayasi{
7191.111Suebayasi	setdir=$setsdir/lists/$1
7201.110Suebayasi	echo_if_exist $setdir/stl.mi
7211.110Suebayasi	echo_if_exist $setdir/stl.${stlib}
7221.111Suebayasi}
7231.110Suebayasi
7241.111Suebayasilist_set_lists_shl()
7251.111Suebayasi{
7261.111Suebayasi	setdir=$setsdir/lists/$1
7271.113Suebayasi	[ "$shlib" != "no" ] || return
7281.112Suebayasi	echo_if_exist $setdir/shl.mi
7291.112Suebayasi	echo_if_exist $setdir/shl.${shlib}
7301.111Suebayasi}
7311.110Suebayasi
7321.111Suebayasilist_set_lists_module()
7331.111Suebayasi{
7341.111Suebayasi	setdir=$setsdir/lists/$1
7351.113Suebayasi	[ "$module" != "no" ] || return
7361.112Suebayasi	echo_if_exist $setdir/module.mi
7371.112Suebayasi	echo_if_exist $setdir/module.${MACHINE}
7381.189Schristos	echo_if_exist $setdir/module.ad.${MACHINE}
7391.189Schristos	echo_if_exist $setdir/module.md.${MACHINE}
7401.113Suebayasi	# XXX module never has .shl
7411.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
7421.113Suebayasi	list_set_lists_common_ad $1 module
7431.111Suebayasi}
7441.1Sdyoung
7451.111Suebayasilist_set_lists_rescue()
7461.111Suebayasi{
7471.111Suebayasi	setdir=$setsdir/lists/$1
7481.110Suebayasi	echo_if_exist $setdir/rescue.mi
7491.110Suebayasi	echo_if_exist $setdir/rescue.${MACHINE}
7501.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
7511.113Suebayasi	list_set_lists_common_ad $1 rescue
7521.111Suebayasi}
7531.111Suebayasi
7541.113Suebayasilist_set_lists_common_ad()
7551.111Suebayasi{
7561.113Suebayasi	setdir=$setsdir/lists/$1; _prefix=$2
7571.113Suebayasi
7581.113Suebayasi	[ -n "$_prefix" ] && prefix="$_prefix".
7591.113Suebayasi
7601.113Suebayasi	# Prefer a <prefix>.ad.${MACHINE_ARCH} over a
7611.113Suebayasi	# <prefix>.ad.${MACHINE_CPU}, since the arch-
7621.112Suebayasi	# specific one will be more specific than the
7631.112Suebayasi	# cpu-specific one.
7641.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
7651.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
7661.113Suebayasi	[ "$shlib" != "no" ] && \
7671.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
7681.5Sdyoung}
7691.5Sdyoung
7701.110Suebayasiecho_if_exist()
7711.110Suebayasi{
7721.110Suebayasi	[ -f $1 ] && echo $1
7731.110Suebayasi	return $?
7741.110Suebayasi}
7751.110Suebayasi
7761.110Suebayasiecho_if_exist_foreach()
7771.110Suebayasi{
7781.110Suebayasi	local _list=$1; shift
7791.110Suebayasi	for _suffix in $@; do
7801.110Suebayasi		echo_if_exist ${_list}.${_suffix}
7811.110Suebayasi	done
7821.110Suebayasi}
7831.110Suebayasi
7841.116Suebayasiprint_set_lists()
7851.116Suebayasi{
7861.116Suebayasi	for setname; do
7871.136Schristos		list=$(list_set_lists $setname)
7881.116Suebayasi		for l in $list; do
7891.116Suebayasi			echo $l
7901.116Suebayasi			if $verbose; then
7911.116Suebayasi				echo >&2 "DEBUG: list_set_files: $l"
7921.116Suebayasi			fi
7931.207Sriastrad		done \
7941.207Sriastrad		| ${XARGS} ${SED} ${SUBST} \
7951.207Sriastrad		| case $setname in
7961.207Sriastrad		base|debug)
7971.207Sriastrad			awk '
7981.207Sriastrad				!/^#/ && !/^$/ {
7991.207Sriastrad					print $1, $2, \
8001.207Sriastrad					    ($3 ? $3"," : "")"omitcompat"
8011.207Sriastrad				}
8021.207Sriastrad			'
8031.207Sriastrad			;;
8041.207Sriastrad		*)	cat
8051.207Sriastrad			;;
8061.207Sriastrad		esac
8071.207Sriastrad
8081.207Sriastrad		case $setname in
8091.207Sriastrad		base32|base64)
8101.207Sriastrad			ursetname=base
8111.207Sriastrad			;;
8121.207Sriastrad		debug32|debug64)
8131.207Sriastrad			ursetname=debug
8141.207Sriastrad			;;
8151.207Sriastrad		*)	continue
8161.207Sriastrad			;;
8171.207Sriastrad		esac
8181.207Sriastrad		case $setname in
8191.207Sriastrad		*32)	compatarches=$compat32arches
8201.207Sriastrad			;;
8211.207Sriastrad		*64)	compatarches=$compat64arches
8221.207Sriastrad			;;
8231.207Sriastrad		esac
8241.207Sriastrad		list=$(list_set_lists $ursetname)
8251.207Sriastrad		for l in $list; do
8261.207Sriastrad			echo $l
8271.207Sriastrad			if $verbose; then
8281.207Sriastrad				echo >&2 "DEBUG: list_set_files: $l"
8291.207Sriastrad			fi
8301.207Sriastrad		done \
8311.207Sriastrad		| ${XARGS} ${SED} ${SUBST} \
8321.207Sriastrad		| awk -v compatarches="$compatarches" '
8331.207Sriastrad			BEGIN {
8341.207Sriastrad				split(compatarches, compatarch, " ")
8351.207Sriastrad				flags = ""
8361.207Sriastrad				for (i in compatarch)
8371.207Sriastrad					flags = (flags ? flags"," : "") \
8381.207Sriastrad					    "takecompat="compatarch[i]
8391.207Sriastrad			}
8401.207Sriastrad			!/^#/ && !/^$/ {
8411.207Sriastrad				print $1, $2, ($3 ? $3"," : "")flags
8421.207Sriastrad			}
8431.207Sriastrad		'
8441.207Sriastrad	done
8451.116Suebayasi}
8461.116Suebayasi
8471.198Schristos
8481.198Schristoslist_kernel_configs()
8491.198Schristos{
8501.198Schristos	(cd ${NETBSDSRCDIR}/etc
8511.198Schristos	MAKEFLAGS= \
8521.198Schristos	${MAKE} -m ${NETBSDSRCDIR}/share/mk -V '${ALL_KERNELS}')
8531.198Schristos}
8541.198Schristos
8551.9Slukem# arch_to_cpu mach
8561.9Slukem#
8571.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
8581.9Slukem# as determined by <bsd.own.mk>.
8591.9Slukem#
8601.8Slukemarch_to_cpu()
8611.8Slukem{
8621.182Suwe	MACHINE_ARCH=${1} MAKEFLAGS= \
8631.182Suwe	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
8641.182Suwe		-f ${NETBSDSRCDIR}/share/mk/bsd.own.mk \
8651.182Suwe		-V '${MACHINE_CPU}'
8661.1Sdyoung}
8671.46Sapb
8681.46Sapb# arch_to_endian mach
8691.46Sapb#
8701.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
8711.46Sapb# as determined by <bsd.endian.mk>.
8721.46Sapb#
8731.46Sapbarch_to_endian()
8741.46Sapb{
8751.182Suwe	MACHINE_ARCH=${1} MAKEFLAGS= \
8761.182Suwe	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
8771.182Suwe		-f ${NETBSDSRCDIR}/share/mk/bsd.endian.mk \
8781.182Suwe		-V '${TARGET_ENDIANNESS}'
8791.46Sapb}
8801.117Suebayasi
8811.117Suebayasi#####
8821.117Suebayasi
8831.117Suebayasi# print_mkvars
8841.117Suebayasiprint_mkvars()
8851.117Suebayasi{
8861.117Suebayasi	for v in $MKVARS; do
8871.117Suebayasi		eval echo $v=\$$v
8881.117Suebayasi	done
8891.117Suebayasi}
8901.117Suebayasi
8911.117Suebayasi# print_set_lists_{base,x,ext}
8921.117Suebayasi# list_set_lists_{base,x,ext}
8931.117Suebayasi# list_set_files_{base,x,ext}
8941.117Suebayasifor func in print_set_lists list_set_lists list_set_files; do
8951.117Suebayasi	for x in base x ext; do
8961.117Suebayasi		if [ $x = base ]; then
8971.117Suebayasi			list=nlists
8981.117Suebayasi		else
8991.117Suebayasi			list=${x}lists
9001.117Suebayasi		fi
9011.117Suebayasi		eval ${func}_${x} \(\) \{ $func \$$list \; \}
9021.117Suebayasi	done
9031.117Suebayasidone
904