sets.subr revision 1.206
11.206Snia#	$NetBSD: sets.subr,v 1.206 2024/04/22 14:41:25 nia 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.11Slukem#	TOOLCHAIN_MISSING
271.11Slukem#	OBJECT_FMT
281.22Slukem# as well as:
291.22Slukem#
301.95Suebayasi
311.42Sapb#
321.42Sapb# The following variables refer to tools that are used when building sets:
331.42Sapb#
341.43Sapb: ${AWK:=awk}
351.42Sapb: ${CKSUM:=cksum}
361.43Sapb: ${COMM:=comm}
371.44Sapb: ${DATE:=date}
381.43Sapb: ${DB:=db}
391.43Sapb: ${EGREP:=egrep}
401.43Sapb: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
411.44Sapb: ${FGREP:=fgrep}
421.43Sapb: ${FIND:=find}
431.44Sapb: ${GREP:=grep}
441.43Sapb: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
451.99Sapb: ${HOSTNAME_CMD:=hostname}	# ${HOSTNAME} is special to bash(1)
461.42Sapb: ${HOST_SH:=sh}
471.43Sapb: ${IDENT:=ident}
481.43Sapb: ${JOIN:=join}
491.43Sapb: ${LS:=ls}
501.43Sapb: ${MAKE:=make}
511.42Sapb: ${MKTEMP:=mktemp}
521.43Sapb: ${MTREE:=mtree}
531.43Sapb: ${PASTE:=paste}
541.42Sapb: ${PAX:=pax}
551.43Sapb: ${PRINTF:=printf}
561.43Sapb: ${SED:=sed}
571.43Sapb: ${SORT:=sort}
581.44Sapb: ${STAT:=stat}
591.44Sapb: ${TSORT:=tsort}
601.43Sapb: ${UNAME:=uname}
611.43Sapb: ${WC:=wc}
621.118Suebayasi: ${XARGS:=xargs}
631.43Sapb
641.45Sapb#
651.45Sapb# If printf is a shell builtin command, then we can
661.45Sapb# implement cheaper versions of basename and dirname
671.45Sapb# that do not involve any fork/exec overhead.
681.45Sapb# If printf is not builtin, approximate it using echo,
691.45Sapb# and hope there are no weird file names that cause
701.45Sapb# some versions of echo to do the wrong thing.
711.45Sapb# (Converting to this version of dirname speeded up the
721.45Sapb# syspkgdeps script by an order of magnitude, from 68
731.45Sapb# seconds to 6.3 seconds on one particular host.)
741.45Sapb#
751.45Sapb# Note that naive approximations for dirname
761.45Sapb# using ${foo%/*} do not do the right thing in cases
771.45Sapb# where the result should be "/" or ".".
781.45Sapb#
791.45Sapbcase "$(type printf)" in
801.45Sapb*builtin*)
811.45Sapb	basename ()
821.45Sapb	{
831.45Sapb		local bn
841.45Sapb		bn="${1##*/}"
851.45Sapb		bn="${bn%$2}"
861.45Sapb		printf "%s\n" "$bn"
871.45Sapb	}
881.45Sapb	dirname ()
891.45Sapb	{
901.45Sapb		local dn
911.45Sapb		case "$1" in
921.45Sapb		?*/*)	dn="${1%/*}" ;;
931.45Sapb		/*)	dn=/ ;;
941.45Sapb		*)	dn=. ;;
951.45Sapb		esac
961.45Sapb		printf "%s\n" "$dn"
971.45Sapb	}
981.45Sapb	;;
991.45Sapb*)
1001.45Sapb	basename ()
1011.45Sapb	{
1021.45Sapb		local bn
1031.45Sapb		bn="${1##*/}"
1041.45Sapb		bn="${bn%$2}"
1051.45Sapb		echo "$bn"
1061.45Sapb	}
1071.45Sapb	dirname ()
1081.45Sapb	{
1091.45Sapb		local dn
1101.45Sapb		case "$1" in
1111.45Sapb		?*/*)	dn="${1%/*}" ;;
1121.45Sapb		/*)	dn=/ ;;
1131.45Sapb		*)	dn=. ;;
1141.45Sapb		esac
1151.45Sapb		echo "$dn"
1161.45Sapb	}
1171.45Sapb	;;
1181.45Sapbesac
1191.45Sapb
1201.108Suebayasi#####
1211.108Suebayasi
1221.9SlukemoIFS=$IFS
1231.9SlukemIFS="
1241.9Slukem"
1251.100Suebayasi
1261.180Schristosfor x in $( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
1271.108Suebayasi	eval export $x
1281.9Slukemdone
1291.100Suebayasi
1301.9SlukemIFS=$oIFS
1311.9Slukem
1321.180SchristosMKVARS="$( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )"
1331.100Suebayasi
1341.105Suebayasi#####
1351.105Suebayasi
1361.117Suebayasisetsdir=${rundir}
1371.9Slukemobsolete=0
1381.91Sdyoungif [ "${MKKMOD}" = "no" ]; then
1391.91Sdyoung	module=no			# MODULEs are off.
1401.125Snjoly	modset=""
1411.125Snjolyelse
1421.125Snjoly	module=yes
1431.125Snjoly	modset="modules"
1441.125Snjolyfi
1451.125Snjolyif [ "${MKATF}" = "no" ]; then
1461.125Snjoly	testset=""
1471.125Snjolyelse
1481.125Snjoly	testset="tests"
1491.9Slukemfi
1501.171Smattif [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then
1511.141Schristos	debugset=""
1521.142Schristos	xdebugset=""
1531.141Schristoselse
1541.141Schristos	debugset="debug"
1551.142Schristos	xdebugset="xdebug"
1561.141Schristosfi
1571.205Sniaif [ -z "${debugset}" -o "${MKCOMPAT}" = "no" ]; then
1581.205Snia	debug32set=""
1591.205Sniaelse
1601.205Snia	debug32set="debug32"
1611.205Sniafi
1621.206Sniaif [ -z "${debug32set}" ]; then
1631.206Snia	debug64set=""
1641.206Sniaelse
1651.206Snia	if [ "${MACHINE_ARCH}" = "mips64eb" -o "${MACHINE_ARCH}" = "mips64el" ]; then
1661.206Snia		debug64set="debug64"
1671.206Snia	else
1681.206Snia		debug64set=""
1691.206Snia	fi
1701.206Sniafi
1711.191Sjmcneillif [ "${MKDTB}" = "no" ]; then
1721.191Sjmcneill	dtbset=""
1731.191Sjmcneillelse
1741.191Sjmcneill	dtbset="dtb"
1751.191Sjmcneillfi
1761.205Sniaif [ "${MKHTML}" = "no" ]; then
1771.205Snia	manhtmlset=""
1781.205Sniaelse
1791.205Snia	manhtmlset="manhtml"
1801.205Sniafi
1811.205Sniaif [ "${MKCOMPAT}" = "no" ]; then
1821.205Snia	base32set=""
1831.205Sniaelse
1841.205Snia	base32set="base32"
1851.205Sniafi
1861.206Sniaif [ "${MKCOMPAT}" != "no" ]; then
1871.206Snia	if [ "${MACHINE_ARCH}" = "mips64eb" -o "${MACHINE_ARCH}" = "mips64el" ]; then
1881.206Snia		base64set="base64"
1891.206Snia	else
1901.206Snia		base64set=""
1911.206Snia	fi
1921.206Sniaelse
1931.206Snia	base64set=""
1941.206Sniafi
1951.206Snia
1961.205Snia
1971.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1981.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1991.9Slukem	shlib=elf
2001.9Slukemelse
2011.9Slukem	shlib=aout
2021.9Slukemfi
2031.9Slukemstlib=$shlib
2041.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
2051.31Sjmcif [ "${MKPIC}" = "no" ]; then
2061.31Sjmc	shlib=no
2071.31Sjmcfi
2081.206Snianlists="base $base32set $base64set comp $debugset $debug32set $debug64set $dtbset etc games gpufw man $manhtmlset misc $modset rescue $testset text"
2091.142Schristosxlists="xbase xcomp $xdebugset xetc xfont xserver"
2101.9Slukem
2111.136SchristosOSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
2121.188Schristosif [ "${KERNEL_DIR}" = "yes" ]; then
2131.188Schristos	MODULEDIR="netbsd/modules"
2141.188Schristoselse
2151.188Schristos	MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
2161.188Schristosfi
2171.62SadSUBST="s#@MODULEDIR@#${MODULEDIR}#g"
2181.62SadSUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
2191.62SadSUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
2201.60Sad
2211.9Slukem#
2221.9Slukem# list_set_files setfile [...]
2231.203Srillig#
2241.9Slukem# Produce a packing list for setfile(s).
2251.9Slukem# In each file, a record consists of a path and a System Package name,
2261.9Slukem# separated by whitespace. E.g.,
2271.9Slukem#
2281.206Snia# 	# $NetBSD: sets.subr,v 1.206 2024/04/22 14:41:25 nia Exp $
2291.9Slukem# 	.			base-sys-root	[keyword[,...]]
2301.9Slukem# 	./altroot		base-sys-root
2311.9Slukem# 	./bin			base-sys-root
2321.9Slukem# 	./bin/[			base-util-root
2331.9Slukem# 	./bin/cat		base-util-root
2341.9Slukem#		[...]
2351.9Slukem#
2361.9Slukem# A # in the first column marks a comment.
2371.9Slukem#
2381.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
2391.52Slukem# be printed.  All other keywords must be present.
2401.9Slukem#
2411.9Slukem# The third field is an optional comma separated list of keywords to
2421.9Slukem# control if a record is printed; every keyword listed must be enabled
2431.204Srillig# for the record to be printed. The list of all available make variables
2441.179Schristos# that can be turned on or off can be found by running in this directory:
2451.179Schristos#
2461.179Schristos#	make -f mkvars.mk mkvarsyesno
2471.179Schristos#
2481.179Schristos# These MK<NAME> variables can be used as selectors in the sets as <name>.
2491.203Srillig#
2501.179Schristos# The following extra keywords are also available, listed by:
2511.179Schristos#
2521.179Schristos#	make -f mkvars.mk mkextravars
2531.13Slukem#
2541.179Schristos# These are:
2551.179Schristos#    1. The HAVE_<name>:
2561.179Schristos#	ssp			${HAVE_SSP} != no
2571.160Sjoerg#	libgcc_eh		${HAVE_LIBGCC_EH} != no
2581.192Sjmcneill#	acpi			${HAVE_ACPI} != no
2591.87Sskrll#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
2601.52Slukem#	gcc=<n>			<n> = value of ${HAVE_GCC}
2611.52Slukem#	gdb=<n>			<n> = value of ${HAVE_GDB}
2621.192Sjmcneill#	mesa_ver=<n>		<n> = value of ${HAVE_MESA_VER}
2631.193Sjmcneill#	nvmm			${HAVE_NVMM} != no
2641.183Schristos#	openssl=<n>		<n> = value of ${HAVE_OPENSSL}
2651.192Sjmcneill#	uefi			${HAVE_UEFI} != no
2661.177Smrg#	xorg_server_ver=<n>	<n> = value of ${HAVE_XORG_SERVER_VER}
2671.186Smrg#	xorg_glamor		${HAVE_XORG_GLAMOR} != no
2681.52Slukem#
2691.179Schristos#    2. The USE_<name>:
2701.41Slukem#	use_inet6		${USE_INET6} != no
2711.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2721.179Schristos#	use_ldap		${USE_LDAP} != no
2731.41Slukem#	use_yp			${USE_YP} != no
2741.41Slukem#
2751.179Schristos#    3. Finally:
2761.179Schristos#	dummy			dummy entry (ignored)
2771.203Srillig#	obsolete		file is obsolete, and only printed if
2781.179Schristos#				${obsolete} != 0
2791.179Schristos#
2801.179Schristos#	solaris			${MKDTRACE} != no or ${MKZFS} != no or ${MKCTF} != no
2811.179Schristos#
2821.179Schristos#
2831.179Schristos#	endian=<n>		<n> = value of ${TARGET_ENDIANNESS}
2841.179Schristos#
2851.179Schristos#
2861.195Skamil#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2871.195Skamil#				  automatically append ".gz" to the filename
2881.195Skamil#
2891.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2901.22Slukem#				  automatically append ".gz" to the filename
2911.1Sdyoung#
2921.8Slukemlist_set_files()
2931.8Slukem{
2941.83Sapb	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
2951.65She		verbose=false
2961.65She	else
2971.65She		verbose=true
2981.65She	fi
2991.198Schristos	local CONFIGS="$( list_kernel_configs )"
3001.116Suebayasi	print_set_lists "$@" | \
3011.43Sapb	${AWK} -v obsolete=${obsolete} '
3021.190Schristos		function addkmod(line, fname, prefix, pat, patlen) {
3031.190Schristos			if (substr(line, 1, patlen) != pat) {
3041.198Schristos				return
3051.190Schristos			}
3061.190Schristos			for (d in kmodarchdirs) {
3071.190Schristos				xd = prefix kmodarchdirs[d]
3081.198Schristos				xline = xd substr(line, patlen + 1)
3091.198Schristos				xfname = xd substr(fname, patlen + 1)
3101.198Schristos				list[xline] = xfname
3111.190Schristos			}
3121.190Schristos		}
3131.198Schristos		function adddebugkernel(line, fname, pat, patlen) {
3141.199Schristos			if (pat == "" || substr(line, 1, patlen) != pat) {
3151.198Schristos				return 0
3161.198Schristos			}
3171.198Schristos			split("'"${CONFIGS}"'", configs)
3181.198Schristos			for (d in configs) {
3191.198Schristos				xfname = fname
3201.200Schristos				sub("@CONFIG@", configs[d], xfname)
3211.198Schristos				xline = line;
3221.200Schristos				sub("@CONFIG@", configs[d], xline)
3231.198Schristos				list[xline] = xfname
3241.198Schristos			}
3251.198Schristos			return 1
3261.198Schristos		}
3271.9Slukem		BEGIN {
3281.52Slukem			if (obsolete)
3291.52Slukem				wanted["obsolete"] = 1
3301.203Srillig
3311.100Suebayasi			split("'"${MKVARS}"'", needvars)
3321.165Smatt			doingcompat = 0
3331.165Smatt			doingcompattests = 0
3341.165Smatt			ignoredkeywords["compatdir"] = 1
3351.165Smatt			ignoredkeywords["compatfile"] = 1
3361.165Smatt			ignoredkeywords["compattestdir"] = 1
3371.165Smatt			ignoredkeywords["compattestfile"] = 1
3381.170Smatt			ignoredkeywords["compatx11dir"] = 1
3391.170Smatt			ignoredkeywords["compatx11file"] = 1
3401.52Slukem			for (vi in needvars) {
3411.52Slukem				nv = needvars[vi]
3421.52Slukem				kw = tolower(nv)
3431.52Slukem				sub(/^mk/, "", kw)
3441.143Snakayama				sub(/^have_/, "", kw)
3451.148Smatt				sub(/^target_endianness/, "endian", kw)
3461.167Smatt				if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
3471.203Srillig					wanted[kw] = 1
3481.167Smatt				}
3491.166Smatt			}
3501.166Smatt
3511.167Smatt			if ("compat" in wanted) {
3521.166Smatt				doingcompat = 1;
3531.166Smatt				split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
3541.166Smatt				compatdirkeywords["compatdir"] = 1
3551.166Smatt				compatfilekeywords["compatfile"] = 1
3561.166Smatt
3571.166Smatt				if (wanted["compattests"]) {
3581.165Smatt					doingcompattests = 1;
3591.165Smatt					compatdirkeywords["compattestdir"] = 1
3601.165Smatt					compatfilekeywords["compattestfile"] = 1
3611.166Smatt				}
3621.170Smatt				if (wanted["compatx11"]) {
3631.170Smatt					doingcompatx11 = 1;
3641.170Smatt					compatdirkeywords["compatx11dir"] = 1
3651.170Smatt					compatfilekeywords["compatx11file"] = 1
3661.170Smatt				}
3671.166Smatt			}
3681.166Smatt
3691.167Smatt			if (("kmod" in wanted) && ("compatmodules" in wanted)) {
3701.166Smatt				split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
3711.190Schristos				kmodprefix = "./stand/"
3721.190Schristos				kmodpat = kmodprefix ENVIRON["MACHINE"]
3731.166Smatt				l_kmodpat = length(kmodpat)
3741.203Srillig				kmoddbprefix = "./usr/libdata/debug/stand/"
3751.190Schristos				kmoddbpat = kmoddbprefix ENVIRON["MACHINE"]
3761.190Schristos				l_kmoddbpat = length(kmoddbpat)
3771.52Slukem			}
3781.198Schristos			if ("debug" in wanted) {
3791.201Schristos				debugkernelname = "./usr/libdata/debug/netbsd-@CONFIG@.debug"
3801.198Schristos				l_debugkernelname = length(debugkernelname);
3811.198Schristos			}
3821.52Slukem
3831.52Slukem			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
3841.90Sdyoung				if ("binutils" in wanted)
3851.90Sdyoung					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
3861.90Sdyoung				if ("gcc" in wanted)
3871.90Sdyoung					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
3881.90Sdyoung				if ("gdb" in wanted)
3891.90Sdyoung					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
3901.9Slukem			}
3911.192Sjmcneill			if ("acpi" in wanted) {
3921.192Sjmcneill				wanted["acpi=" "'"${HAVE_ACPI}"'"] = 1
3931.192Sjmcneill			}
3941.192Sjmcneill			if ("mesa_ver" in wanted) {
3951.192Sjmcneill				wanted["mesa_ver=" "'"${HAVE_MESA_VER}"'"] = 1
3961.192Sjmcneill			}
3971.193Sjmcneill			if ("nvmm" in wanted) {
3981.193Sjmcneill				wanted["nvmm=" "'"${HAVE_NVMM}"'"] = 1
3991.193Sjmcneill			}
4001.183Schristos			if ("openssl" in wanted) {
4011.183Schristos				wanted["openssl=" "'"${HAVE_OPENSSL}"'"] = 1
4021.183Schristos			}
4031.178Smrg			if ("xorg_server_ver" in wanted) {
4041.178Smrg				wanted["xorg_server_ver=" "'"${HAVE_XORG_SERVER_VER}"'"] = 1
4051.177Smrg			}
4061.192Sjmcneill			if ("uefi" in wanted) {
4071.192Sjmcneill				wanted["uefi=" "'"${HAVE_UEFI}"'"] = 1
4081.185Smrg			}
4091.195Skamil			if (("man" in wanted) && ("catpages" in wanted))
4101.195Skamil				wanted[".cat"] = 1
4111.52Slukem			if (("man" in wanted) && ("manpages" in wanted))
4121.52Slukem				wanted[".man"] = 1
4131.148Smatt			if ("endian" in wanted)
4141.148Smatt				wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
4151.162Smrg			if ("machine" in wanted)
4161.162Smrg				wanted["machine=" "'"${MACHINE}"'"] = 1
4171.162Smrg			if ("machine_arch" in wanted)
4181.162Smrg				wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
4191.162Smrg			if ("machine_cpu" in wanted)
4201.162Smrg				wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
4211.9Slukem		}
4221.9Slukem
4231.9Slukem		/^#/ {
4241.9Slukem			next;
4251.9Slukem		}
4261.9Slukem
4271.127Smatt		/^-/ {
4281.127Smatt			notwanted[substr($1, 2)] = 1;
4291.127Smatt			delete list [substr($1, 2)];
4301.127Smatt			next;
4311.127Smatt		}
4321.203Srillig
4331.127Smatt
4341.9Slukem		NF > 2 && $3 != "-" {
4351.127Smatt			if (notwanted[$1] != "")
4361.127Smatt				next;
4371.9Slukem			split($3, keywords, ",")
4381.9Slukem			show = 1
4391.52Slukem			haveobs = 0
4401.167Smatt			iscompatfile = 0
4411.165Smatt			havekmod = 0
4421.165Smatt			iscompatdir = 0
4431.9Slukem			for (ki in keywords) {
4441.9Slukem				kw = keywords[ki]
4451.22Slukem				if (("manz" in wanted) &&
4461.22Slukem				    (kw == ".cat" || kw == ".man"))
4471.22Slukem					$1 = $1 ".gz"
4481.134Sjoerg				if (substr(kw, 1, 1) == "!") {
4491.134Sjoerg					kw = substr(kw, 2)
4501.59Sjmmv					if (kw in wanted)
4511.59Sjmmv						show = 0
4521.165Smatt				} else if (kw in compatdirkeywords) {
4531.165Smatt					iscompatdir = 1
4541.165Smatt				} else if (kw in compatfilekeywords) {
4551.167Smatt					iscompatfile = 1
4561.172Smatt				} else if (kw == "nocompatmodules") {
4571.172Smatt					havekmod = -1
4581.165Smatt				} else if (kw in ignoredkeywords) {
4591.165Smatt					# ignore
4601.167Smatt				} else if (! (kw in wanted)) {
4611.167Smatt					show = 0
4621.172Smatt				} else if (kw == "kmod" && havekmod == 0) {
4631.167Smatt					havekmod = 1
4641.59Sjmmv				}
4651.52Slukem				if (kw == "obsolete")
4661.52Slukem					haveobs = 1
4671.9Slukem			}
4681.184Snakayama			if (iscompatdir) {
4691.184Snakayama				for (d in cpaths) {
4701.184Snakayama					if (cpaths[d] == $1 "/")
4711.184Snakayama						next
4721.184Snakayama				}
4731.184Snakayama				cpaths[ncpaths++] = $1 "/"
4741.184Snakayama			}
4751.52Slukem			if (obsolete && ! haveobs)
4761.52Slukem				next
4771.165Smatt			if (!show)
4781.165Smatt				next
4791.198Schristos			if (adddebugkernel($0, $1, debugkernelname, l_debugkernelname))
4801.198Schristos				next
4811.165Smatt
4821.165Smatt			list[$1] = $0
4831.190Schristos			if (havekmod > 0) {
4841.190Schristos				addkmod($0, $1, kmodprefix, kmodpat, l_kmodpat)
4851.190Schristos				addkmod($0, $1, kmoddbprefix, kmoddbpat, l_kmoddbpat)
4861.165Smatt				next
4871.165Smatt			}
4881.165Smatt
4891.167Smatt			if (!doingcompat || !(iscompatfile || iscompatdir))
4901.165Smatt				next
4911.165Smatt
4921.167Smatt			if (iscompatfile) {
4931.165Smatt				emitcompat[$1] = 1;
4941.168Smatt				next
4951.168Smatt			}
4961.165Smatt			for (d in compatarchdirs) {
4971.165Smatt				tmp = $0
4981.165Smatt				xfile = $1 "/" compatarchdirs[d]
4991.165Smatt				tmp = xfile substr(tmp, length($1) + 1)
5001.165Smatt				if (xfile in notwanted)
5011.165Smatt					continue;
5021.165Smatt				sub("compatdir","compat",tmp);
5031.165Smatt				sub("compattestdir","compat",tmp);
5041.165Smatt				list[xfile] = tmp
5051.165Smatt			}
5061.9Slukem			next
5071.9Slukem		}
5081.9Slukem
5091.9Slukem		{
5101.165Smatt			if ($1 in notwanted)
5111.127Smatt				next;
5121.9Slukem			if (! obsolete)
5131.127Smatt				list[$1] = $0
5141.127Smatt		}
5151.127Smatt
5161.127Smatt		END {
5171.127Smatt			for (i in list) {
5181.127Smatt				print list[i]
5191.165Smatt				if (! (i in emitcompat))
5201.165Smatt					continue;
5211.165Smatt				l_i = length(i)
5221.165Smatt				l = 0
5231.165Smatt				for (j in cpaths) {
5241.165Smatt					lx = length(cpaths[j])
5251.165Smatt					if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
5261.165Smatt						continue;
5271.165Smatt					}
5281.165Smatt					if (lx > l) {
5291.165Smatt						l = lx;
5301.165Smatt						cpath = cpaths[j];
5311.165Smatt					}
5321.165Smatt				}
5331.165Smatt				for (d in compatarchdirs) {
5341.165Smatt					tmp = list[i]
5351.165Smatt					extrapath = compatarchdirs[d] "/"
5361.165Smatt					xfile = cpath extrapath substr(i, l + 1)
5371.165Smatt					if (xfile in notwanted)
5381.165Smatt						continue;
5391.165Smatt					sub("compatfile","compat",tmp);
5401.165Smatt					sub("compattestfile","compat",tmp);
5411.165Smatt					tmp = xfile substr(tmp, l_i + 1)
5421.165Smatt					print tmp;
5431.165Smatt				}
5441.127Smatt			}
5451.9Slukem		}'
5461.9Slukem
5471.1Sdyoung}
5481.1Sdyoung
5491.1Sdyoung#
5501.1Sdyoung# list_set_lists setname
5511.203Srillig#
5521.1Sdyoung# Print to stdout a list of files, one filename per line, which
5531.1Sdyoung# concatenate to create the packing list for setname. E.g.,
5541.1Sdyoung#
5551.1Sdyoung# 	.../lists/base/mi
5561.1Sdyoung# 	.../lists/base/rescue.mi
5571.1Sdyoung# 	.../lists/base/md.i386
5581.9Slukem#		[...]
5591.1Sdyoung#
5601.9Slukem# For a given setname $set, the following files may be selected from
5611.9Slukem# .../list/$set:
5621.9Slukem#	mi
5631.92Suebayasi#	mi.ext.*
5641.11Slukem#	ad.${MACHINE_ARCH}
5651.11Slukem# (or)	ad.${MACHINE_CPU}
5661.11Slukem#	ad.${MACHINE_CPU}.shl
5671.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
5681.11Slukem# (or)	md.${MACHINE}
5691.9Slukem#	stl.mi
5701.92Suebayasi#	stl.${stlib}
5711.9Slukem#	shl.mi
5721.92Suebayasi#	shl.mi.ext.*
5731.92Suebayasi#	shl.${shlib}
5741.92Suebayasi#	shl.${shlib}.ext.*
5751.77Stsutsui#	module.mi			if ${module} != no
5761.77Stsutsui#	module.${MACHINE}		if ${module} != no
5771.77Stsutsui#	module.ad.${MACHINE_ARCH}	if ${module} != no
5781.77Stsutsui# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
5791.9Slukem#	rescue.shl
5801.11Slukem#	rescue.${MACHINE}
5811.11Slukem#	rescue.ad.${MACHINE_ARCH}
5821.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
5831.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
5841.1Sdyoung#
5851.9Slukem# Environment:
5861.1Sdyoung# 	shlib
5871.1Sdyoung# 	stlib
5881.1Sdyoung#
5891.8Slukemlist_set_lists()
5901.8Slukem{
5911.1Sdyoung	setname=$1
5921.1Sdyoung
5931.111Suebayasi	list_set_lists_mi $setname
5941.113Suebayasi	list_set_lists_ad $setname
5951.111Suebayasi	list_set_lists_md $setname
5961.111Suebayasi	list_set_lists_stl $setname
5971.113Suebayasi	list_set_lists_shl $setname
5981.113Suebayasi	list_set_lists_module $setname
5991.111Suebayasi	list_set_lists_rescue $setname
6001.117Suebayasi	return 0
6011.111Suebayasi}
6021.110Suebayasi
6031.111Suebayasilist_set_lists_mi()
6041.111Suebayasi{
6051.111Suebayasi	setdir=$setsdir/lists/$1
6061.113Suebayasi	# always exist!
6071.9Slukem	echo $setdir/mi
6081.111Suebayasi}
6091.110Suebayasi
6101.111Suebayasilist_set_lists_ad()
6111.111Suebayasi{
6121.111Suebayasi	setdir=$setsdir/lists/$1
6131.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
6141.113Suebayasi	list_set_lists_common_ad $1
6151.111Suebayasi}
6161.110Suebayasi
6171.111Suebayasilist_set_lists_md()
6181.111Suebayasi{
6191.111Suebayasi	setdir=$setsdir/lists/$1
6201.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
6211.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}
6221.111Suebayasi}
6231.110Suebayasi
6241.111Suebayasilist_set_lists_stl()
6251.111Suebayasi{
6261.111Suebayasi	setdir=$setsdir/lists/$1
6271.110Suebayasi	echo_if_exist $setdir/stl.mi
6281.110Suebayasi	echo_if_exist $setdir/stl.${stlib}
6291.111Suebayasi}
6301.110Suebayasi
6311.111Suebayasilist_set_lists_shl()
6321.111Suebayasi{
6331.111Suebayasi	setdir=$setsdir/lists/$1
6341.113Suebayasi	[ "$shlib" != "no" ] || return
6351.112Suebayasi	echo_if_exist $setdir/shl.mi
6361.112Suebayasi	echo_if_exist $setdir/shl.${shlib}
6371.111Suebayasi}
6381.110Suebayasi
6391.111Suebayasilist_set_lists_module()
6401.111Suebayasi{
6411.111Suebayasi	setdir=$setsdir/lists/$1
6421.113Suebayasi	[ "$module" != "no" ] || return
6431.112Suebayasi	echo_if_exist $setdir/module.mi
6441.112Suebayasi	echo_if_exist $setdir/module.${MACHINE}
6451.189Schristos	echo_if_exist $setdir/module.ad.${MACHINE}
6461.189Schristos	echo_if_exist $setdir/module.md.${MACHINE}
6471.113Suebayasi	# XXX module never has .shl
6481.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
6491.113Suebayasi	list_set_lists_common_ad $1 module
6501.111Suebayasi}
6511.1Sdyoung
6521.111Suebayasilist_set_lists_rescue()
6531.111Suebayasi{
6541.111Suebayasi	setdir=$setsdir/lists/$1
6551.110Suebayasi	echo_if_exist $setdir/rescue.mi
6561.110Suebayasi	echo_if_exist $setdir/rescue.${MACHINE}
6571.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
6581.113Suebayasi	list_set_lists_common_ad $1 rescue
6591.111Suebayasi}
6601.111Suebayasi
6611.113Suebayasilist_set_lists_common_ad()
6621.111Suebayasi{
6631.113Suebayasi	setdir=$setsdir/lists/$1; _prefix=$2
6641.113Suebayasi
6651.113Suebayasi	[ -n "$_prefix" ] && prefix="$_prefix".
6661.113Suebayasi
6671.113Suebayasi	# Prefer a <prefix>.ad.${MACHINE_ARCH} over a
6681.113Suebayasi	# <prefix>.ad.${MACHINE_CPU}, since the arch-
6691.112Suebayasi	# specific one will be more specific than the
6701.112Suebayasi	# cpu-specific one.
6711.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
6721.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
6731.113Suebayasi	[ "$shlib" != "no" ] && \
6741.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
6751.5Sdyoung}
6761.5Sdyoung
6771.110Suebayasiecho_if_exist()
6781.110Suebayasi{
6791.110Suebayasi	[ -f $1 ] && echo $1
6801.110Suebayasi	return $?
6811.110Suebayasi}
6821.110Suebayasi
6831.110Suebayasiecho_if_exist_foreach()
6841.110Suebayasi{
6851.110Suebayasi	local _list=$1; shift
6861.110Suebayasi	for _suffix in $@; do
6871.110Suebayasi		echo_if_exist ${_list}.${_suffix}
6881.110Suebayasi	done
6891.110Suebayasi}
6901.110Suebayasi
6911.116Suebayasiprint_set_lists()
6921.116Suebayasi{
6931.116Suebayasi	for setname; do
6941.136Schristos		list=$(list_set_lists $setname)
6951.116Suebayasi		for l in $list; do
6961.116Suebayasi			echo $l
6971.116Suebayasi			if $verbose; then
6981.116Suebayasi				echo >&2 "DEBUG: list_set_files: $l"
6991.116Suebayasi			fi
7001.116Suebayasi		done
7011.118Suebayasi	done | ${XARGS} ${SED} ${SUBST}
7021.116Suebayasi}
7031.116Suebayasi
7041.198Schristos
7051.198Schristoslist_kernel_configs()
7061.198Schristos{
7071.198Schristos	(cd ${NETBSDSRCDIR}/etc
7081.198Schristos	MAKEFLAGS= \
7091.198Schristos	${MAKE} -m ${NETBSDSRCDIR}/share/mk -V '${ALL_KERNELS}')
7101.198Schristos}
7111.198Schristos
7121.9Slukem# arch_to_cpu mach
7131.9Slukem#
7141.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
7151.9Slukem# as determined by <bsd.own.mk>.
7161.9Slukem#
7171.8Slukemarch_to_cpu()
7181.8Slukem{
7191.182Suwe	MACHINE_ARCH=${1} MAKEFLAGS= \
7201.182Suwe	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
7211.182Suwe		-f ${NETBSDSRCDIR}/share/mk/bsd.own.mk \
7221.182Suwe		-V '${MACHINE_CPU}'
7231.1Sdyoung}
7241.46Sapb
7251.46Sapb# arch_to_endian mach
7261.46Sapb#
7271.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
7281.46Sapb# as determined by <bsd.endian.mk>.
7291.46Sapb#
7301.46Sapbarch_to_endian()
7311.46Sapb{
7321.182Suwe	MACHINE_ARCH=${1} MAKEFLAGS= \
7331.182Suwe	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
7341.182Suwe		-f ${NETBSDSRCDIR}/share/mk/bsd.endian.mk \
7351.182Suwe		-V '${TARGET_ENDIANNESS}'
7361.46Sapb}
7371.117Suebayasi
7381.117Suebayasi#####
7391.117Suebayasi
7401.117Suebayasi# print_mkvars
7411.117Suebayasiprint_mkvars()
7421.117Suebayasi{
7431.117Suebayasi	for v in $MKVARS; do
7441.117Suebayasi		eval echo $v=\$$v
7451.117Suebayasi	done
7461.117Suebayasi}
7471.117Suebayasi
7481.117Suebayasi# print_set_lists_{base,x,ext}
7491.117Suebayasi# list_set_lists_{base,x,ext}
7501.117Suebayasi# list_set_files_{base,x,ext}
7511.117Suebayasifor func in print_set_lists list_set_lists list_set_files; do
7521.117Suebayasi	for x in base x ext; do
7531.117Suebayasi		if [ $x = base ]; then
7541.117Suebayasi			list=nlists
7551.117Suebayasi		else
7561.117Suebayasi			list=${x}lists
7571.117Suebayasi		fi
7581.117Suebayasi		eval ${func}_${x} \(\) \{ $func \$$list \; \}
7591.117Suebayasi	done
7601.117Suebayasidone
761