sets.subr revision 1.184
11.184Snakayama#	$NetBSD: sets.subr,v 1.184 2018/04/12 11:49:04 nakayama 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.92Suebayasi#	extlists		list of extsrc sets
101.9Slukem#	obsolete		controls if obsolete files are selected instead
111.76Stsutsui#	module			if != "no", enable MODULE sets
121.9Slukem#	shlib			shared library format (a.out, elf, or "")
131.9Slukem#	stlib			static library format (a.out, elf)
141.11Slukem#
151.11Slukem# The following <bsd.own.mk> variables are exported to the environment:
161.11Slukem#	MACHINE	
171.11Slukem#	MACHINE_ARCH
181.11Slukem#	MACHINE_CPU
191.87Sskrll#	HAVE_BINUTILS
201.48Smrg#	HAVE_GCC
211.52Slukem#	HAVE_GDB
221.143Snakayama#	HAVE_SSP
231.183Schristos#	HAVE_OPENSSL
241.11Slukem#	TOOLCHAIN_MISSING
251.11Slukem#	OBJECT_FMT
261.22Slukem# as well as:
271.22Slukem#
281.95Suebayasi
291.42Sapb#
301.42Sapb# The following variables refer to tools that are used when building sets:
311.42Sapb#
321.43Sapb: ${AWK:=awk}
331.42Sapb: ${CKSUM:=cksum}
341.43Sapb: ${COMM:=comm}
351.44Sapb: ${DATE:=date}
361.43Sapb: ${DB:=db}
371.43Sapb: ${EGREP:=egrep}
381.43Sapb: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
391.44Sapb: ${FGREP:=fgrep}
401.43Sapb: ${FIND:=find}
411.44Sapb: ${GREP:=grep}
421.43Sapb: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
431.99Sapb: ${HOSTNAME_CMD:=hostname}	# ${HOSTNAME} is special to bash(1)
441.42Sapb: ${HOST_SH:=sh}
451.43Sapb: ${IDENT:=ident}
461.43Sapb: ${JOIN:=join}
471.43Sapb: ${LS:=ls}
481.43Sapb: ${MAKE:=make}
491.42Sapb: ${MKTEMP:=mktemp}
501.43Sapb: ${MTREE:=mtree}
511.43Sapb: ${PASTE:=paste}
521.42Sapb: ${PAX:=pax}
531.43Sapb: ${PRINTF:=printf}
541.43Sapb: ${SED:=sed}
551.43Sapb: ${SORT:=sort}
561.44Sapb: ${STAT:=stat}
571.44Sapb: ${TSORT:=tsort}
581.43Sapb: ${UNAME:=uname}
591.43Sapb: ${WC:=wc}
601.118Suebayasi: ${XARGS:=xargs}
611.43Sapb
621.45Sapb#
631.45Sapb# If printf is a shell builtin command, then we can
641.45Sapb# implement cheaper versions of basename and dirname
651.45Sapb# that do not involve any fork/exec overhead.
661.45Sapb# If printf is not builtin, approximate it using echo,
671.45Sapb# and hope there are no weird file names that cause
681.45Sapb# some versions of echo to do the wrong thing.
691.45Sapb# (Converting to this version of dirname speeded up the
701.45Sapb# syspkgdeps script by an order of magnitude, from 68
711.45Sapb# seconds to 6.3 seconds on one particular host.)
721.45Sapb#
731.45Sapb# Note that naive approximations for dirname
741.45Sapb# using ${foo%/*} do not do the right thing in cases
751.45Sapb# where the result should be "/" or ".".
761.45Sapb#
771.45Sapbcase "$(type printf)" in
781.45Sapb*builtin*)
791.45Sapb	basename ()
801.45Sapb	{
811.45Sapb		local bn
821.45Sapb		bn="${1##*/}"
831.45Sapb		bn="${bn%$2}"
841.45Sapb		printf "%s\n" "$bn"
851.45Sapb	}
861.45Sapb	dirname ()
871.45Sapb	{
881.45Sapb		local dn
891.45Sapb		case "$1" in
901.45Sapb		?*/*)	dn="${1%/*}" ;;
911.45Sapb		/*)	dn=/ ;;
921.45Sapb		*)	dn=. ;;
931.45Sapb		esac
941.45Sapb		printf "%s\n" "$dn"
951.45Sapb	}
961.45Sapb	;;
971.45Sapb*)
981.45Sapb	basename ()
991.45Sapb	{
1001.45Sapb		local bn
1011.45Sapb		bn="${1##*/}"
1021.45Sapb		bn="${bn%$2}"
1031.45Sapb		echo "$bn"
1041.45Sapb	}
1051.45Sapb	dirname ()
1061.45Sapb	{
1071.45Sapb		local dn
1081.45Sapb		case "$1" in
1091.45Sapb		?*/*)	dn="${1%/*}" ;;
1101.45Sapb		/*)	dn=/ ;;
1111.45Sapb		*)	dn=. ;;
1121.45Sapb		esac
1131.45Sapb		echo "$dn"
1141.45Sapb	}
1151.45Sapb	;;
1161.45Sapbesac
1171.45Sapb
1181.108Suebayasi#####
1191.108Suebayasi
1201.9SlukemoIFS=$IFS
1211.9SlukemIFS="
1221.9Slukem"
1231.100Suebayasi
1241.180Schristosfor x in $( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
1251.108Suebayasi	eval export $x
1261.9Slukemdone
1271.100Suebayasi
1281.9SlukemIFS=$oIFS
1291.9Slukem
1301.180SchristosMKVARS="$( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )"
1311.100Suebayasi
1321.105Suebayasi#####
1331.105Suebayasi
1341.117Suebayasisetsdir=${rundir}
1351.9Slukemobsolete=0
1361.91Sdyoungif [ "${MKKMOD}" = "no" ]; then
1371.91Sdyoung	module=no			# MODULEs are off.
1381.125Snjoly	modset=""
1391.125Snjolyelse
1401.125Snjoly	module=yes
1411.125Snjoly	modset="modules"
1421.125Snjolyfi
1431.125Snjolyif [ "${MKATF}" = "no" ]; then
1441.125Snjoly	testset=""
1451.125Snjolyelse
1461.125Snjoly	testset="tests"
1471.9Slukemfi
1481.171Smattif [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then
1491.141Schristos	debugset=""
1501.142Schristos	xdebugset=""
1511.141Schristoselse
1521.141Schristos	debugset="debug"
1531.142Schristos	xdebugset="xdebug"
1541.141Schristosfi
1551.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1561.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1571.9Slukem	shlib=elf
1581.9Slukemelse
1591.9Slukem	shlib=aout
1601.9Slukemfi
1611.9Slukemstlib=$shlib
1621.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1631.31Sjmcif [ "${MKPIC}" = "no" ]; then
1641.31Sjmc	shlib=no
1651.31Sjmcfi
1661.141Schristosnlists="base comp $debugset etc games man misc $modset $testset text"
1671.142Schristosxlists="xbase xcomp $xdebugset xetc xfont xserver"
1681.92Suebayasiextlists="extbase extcomp extetc"
1691.9Slukem
1701.136SchristosOSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
1711.81SrmindMODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
1721.62SadSUBST="s#@MODULEDIR@#${MODULEDIR}#g"
1731.62SadSUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
1741.62SadSUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
1751.60Sad
1761.9Slukem#
1771.9Slukem# list_set_files setfile [...]
1781.1Sdyoung# 
1791.9Slukem# Produce a packing list for setfile(s).
1801.9Slukem# In each file, a record consists of a path and a System Package name,
1811.9Slukem# separated by whitespace. E.g.,
1821.9Slukem#
1831.184Snakayama# 	# $NetBSD: sets.subr,v 1.184 2018/04/12 11:49:04 nakayama Exp $
1841.9Slukem# 	.			base-sys-root	[keyword[,...]]
1851.9Slukem# 	./altroot		base-sys-root
1861.9Slukem# 	./bin			base-sys-root
1871.9Slukem# 	./bin/[			base-util-root
1881.9Slukem# 	./bin/cat		base-util-root
1891.9Slukem#		[...]
1901.9Slukem#
1911.9Slukem# A # in the first column marks a comment.
1921.9Slukem#
1931.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1941.52Slukem# be printed.  All other keywords must be present.
1951.9Slukem#
1961.9Slukem# The third field is an optional comma separated list of keywords to
1971.9Slukem# control if a record is printed; every keyword listed must be enabled
1981.179Schristos# for the record to be printed. The list of all avalaible make variables
1991.179Schristos# that can be turned on or off can be found by running in this directory:
2001.179Schristos#
2011.179Schristos#	make -f mkvars.mk mkvarsyesno
2021.179Schristos#
2031.179Schristos# These MK<NAME> variables can be used as selectors in the sets as <name>.
2041.179Schristos# 
2051.179Schristos# The following extra keywords are also available, listed by:
2061.179Schristos#
2071.179Schristos#	make -f mkvars.mk mkextravars
2081.13Slukem#
2091.179Schristos# These are:
2101.179Schristos#    1. The HAVE_<name>:
2111.179Schristos#	ssp			${HAVE_SSP} != no
2121.160Sjoerg#	libgcc_eh		${HAVE_LIBGCC_EH} != no
2131.87Sskrll#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
2141.52Slukem#	gcc=<n>			<n> = value of ${HAVE_GCC}
2151.52Slukem#	gdb=<n>			<n> = value of ${HAVE_GDB}
2161.183Schristos#	openssl=<n>		<n> = value of ${HAVE_OPENSSL}
2171.177Smrg#	xorg_server_ver=<n>	<n> = value of ${HAVE_XORG_SERVER_VER}
2181.52Slukem#
2191.179Schristos#    2. The USE_<name>:
2201.41Slukem#	use_inet6		${USE_INET6} != no
2211.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2221.179Schristos#	use_ldap		${USE_LDAP} != no
2231.41Slukem#	use_yp			${USE_YP} != no
2241.41Slukem#
2251.179Schristos#    3. Finally:
2261.179Schristos#	dummy			dummy entry (ignored)
2271.179Schristos#	obsolete		file is obsolete, and only printed if 
2281.179Schristos#				${obsolete} != 0
2291.179Schristos#
2301.179Schristos#	solaris			${MKDTRACE} != no or ${MKZFS} != no or ${MKCTF} != no
2311.179Schristos#
2321.179Schristos#
2331.179Schristos#	endian=<n>		<n> = value of ${TARGET_ENDIANNESS}
2341.179Schristos#
2351.179Schristos#
2361.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2371.22Slukem#				  automatically append ".gz" to the filename
2381.22Slukem#
2391.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2401.22Slukem#				  automatically append ".gz" to the filename
2411.1Sdyoung#
2421.8Slukemlist_set_files()
2431.8Slukem{
2441.83Sapb	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
2451.65She		verbose=false
2461.65She	else
2471.65She		verbose=true
2481.65She	fi
2491.116Suebayasi	print_set_lists "$@" | \
2501.43Sapb	${AWK} -v obsolete=${obsolete} '
2511.9Slukem		BEGIN {
2521.52Slukem			if (obsolete)
2531.52Slukem				wanted["obsolete"] = 1
2541.52Slukem		
2551.100Suebayasi			split("'"${MKVARS}"'", needvars)
2561.165Smatt			doingcompat = 0
2571.165Smatt			doingcompattests = 0
2581.165Smatt			ignoredkeywords["compatdir"] = 1
2591.165Smatt			ignoredkeywords["compatfile"] = 1
2601.165Smatt			ignoredkeywords["compattestdir"] = 1
2611.165Smatt			ignoredkeywords["compattestfile"] = 1
2621.170Smatt			ignoredkeywords["compatx11dir"] = 1
2631.170Smatt			ignoredkeywords["compatx11file"] = 1
2641.52Slukem			for (vi in needvars) {
2651.52Slukem				nv = needvars[vi]
2661.52Slukem				kw = tolower(nv)
2671.52Slukem				sub(/^mk/, "", kw)
2681.143Snakayama				sub(/^have_/, "", kw)
2691.148Smatt				sub(/^target_endianness/, "endian", kw)
2701.167Smatt				if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
2711.165Smatt					wanted[kw] = 1 
2721.167Smatt				}
2731.166Smatt			}
2741.166Smatt
2751.167Smatt			if ("compat" in wanted) {
2761.166Smatt				doingcompat = 1;
2771.166Smatt				split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
2781.166Smatt				compatdirkeywords["compatdir"] = 1
2791.166Smatt				compatfilekeywords["compatfile"] = 1
2801.166Smatt
2811.166Smatt				if (wanted["compattests"]) {
2821.165Smatt					doingcompattests = 1;
2831.165Smatt					compatdirkeywords["compattestdir"] = 1
2841.165Smatt					compatfilekeywords["compattestfile"] = 1
2851.166Smatt				}
2861.170Smatt				if (wanted["compatx11"]) {
2871.170Smatt					doingcompatx11 = 1;
2881.170Smatt					compatdirkeywords["compatx11dir"] = 1
2891.170Smatt					compatfilekeywords["compatx11file"] = 1
2901.170Smatt				}
2911.166Smatt			}
2921.166Smatt
2931.167Smatt			if (("kmod" in wanted) && ("compatmodules" in wanted)) {
2941.166Smatt				split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
2951.166Smatt				kmodpat = "./stand/" ENVIRON["MACHINE"]
2961.166Smatt				l_kmodpat = length(kmodpat)
2971.52Slukem			}
2981.52Slukem
2991.52Slukem			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
3001.90Sdyoung				if ("binutils" in wanted)
3011.90Sdyoung					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
3021.90Sdyoung				if ("gcc" in wanted)
3031.90Sdyoung					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
3041.90Sdyoung				if ("gdb" in wanted)
3051.90Sdyoung					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
3061.9Slukem			}
3071.183Schristos			if ("openssl" in wanted) {
3081.183Schristos				wanted["openssl=" "'"${HAVE_OPENSSL}"'"] = 1
3091.183Schristos			}
3101.178Smrg			if ("xorg_server_ver" in wanted) {
3111.178Smrg				wanted["xorg_server_ver=" "'"${HAVE_XORG_SERVER_VER}"'"] = 1
3121.177Smrg			}
3131.52Slukem			if (("man" in wanted) && ("catpages" in wanted))
3141.52Slukem				wanted[".cat"] = 1
3151.52Slukem			if (("man" in wanted) && ("manpages" in wanted))
3161.52Slukem				wanted[".man"] = 1
3171.148Smatt			if ("endian" in wanted)
3181.148Smatt				wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
3191.162Smrg			if ("machine" in wanted)
3201.162Smrg				wanted["machine=" "'"${MACHINE}"'"] = 1
3211.162Smrg			if ("machine_arch" in wanted)
3221.162Smrg				wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
3231.162Smrg			if ("machine_cpu" in wanted)
3241.162Smrg				wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
3251.9Slukem		}
3261.9Slukem
3271.9Slukem		/^#/ {
3281.9Slukem			next;
3291.9Slukem		}
3301.9Slukem
3311.127Smatt		/^-/ {
3321.127Smatt			notwanted[substr($1, 2)] = 1;
3331.127Smatt			delete list [substr($1, 2)];
3341.127Smatt			next;
3351.127Smatt		}
3361.127Smatt				
3371.127Smatt
3381.9Slukem		NF > 2 && $3 != "-" {
3391.127Smatt			if (notwanted[$1] != "")
3401.127Smatt				next;
3411.9Slukem			split($3, keywords, ",")
3421.9Slukem			show = 1
3431.52Slukem			haveobs = 0
3441.167Smatt			iscompatfile = 0
3451.165Smatt			havekmod = 0
3461.165Smatt			iscompatdir = 0
3471.9Slukem			for (ki in keywords) {
3481.9Slukem				kw = keywords[ki]
3491.22Slukem				if (("manz" in wanted) &&
3501.22Slukem				    (kw == ".cat" || kw == ".man"))
3511.22Slukem					$1 = $1 ".gz"
3521.134Sjoerg				if (substr(kw, 1, 1) == "!") {
3531.134Sjoerg					kw = substr(kw, 2)
3541.59Sjmmv					if (kw in wanted)
3551.59Sjmmv						show = 0
3561.165Smatt				} else if (kw in compatdirkeywords) {
3571.165Smatt					iscompatdir = 1
3581.165Smatt				} else if (kw in compatfilekeywords) {
3591.167Smatt					iscompatfile = 1
3601.172Smatt				} else if (kw == "nocompatmodules") {
3611.172Smatt					havekmod = -1
3621.165Smatt				} else if (kw in ignoredkeywords) {
3631.165Smatt					# ignore
3641.167Smatt				} else if (! (kw in wanted)) {
3651.167Smatt					show = 0
3661.172Smatt				} else if (kw == "kmod" && havekmod == 0) {
3671.167Smatt					havekmod = 1
3681.59Sjmmv				}
3691.52Slukem				if (kw == "obsolete")
3701.52Slukem					haveobs = 1
3711.9Slukem			}
3721.184Snakayama			if (iscompatdir) {
3731.184Snakayama				for (d in cpaths) {
3741.184Snakayama					if (cpaths[d] == $1 "/")
3751.184Snakayama						next
3761.184Snakayama				}
3771.184Snakayama				cpaths[ncpaths++] = $1 "/"
3781.184Snakayama			}
3791.52Slukem			if (obsolete && ! haveobs)
3801.52Slukem				next
3811.165Smatt			if (!show)
3821.165Smatt				next
3831.165Smatt
3841.165Smatt			list[$1] = $0
3851.172Smatt			if (havekmod > 0 && substr($1,1,l_kmodpat) == kmodpat) {
3861.165Smatt				for (d in kmodarchdirs) {
3871.165Smatt					xd = "./stand/" kmodarchdirs[d]
3881.165Smatt					xfile = xd substr($1, l_kmodpat+1)
3891.165Smatt					tmp = xd substr($0, l_kmodpat+1)
3901.165Smatt					list[xfile] = tmp;
3911.165Smatt				}
3921.165Smatt				next
3931.165Smatt			}
3941.165Smatt
3951.167Smatt			if (!doingcompat || !(iscompatfile || iscompatdir))
3961.165Smatt				next
3971.165Smatt
3981.167Smatt			if (iscompatfile) {
3991.165Smatt				emitcompat[$1] = 1;
4001.168Smatt				next
4011.168Smatt			}
4021.165Smatt			for (d in compatarchdirs) {
4031.165Smatt				tmp = $0
4041.165Smatt				xfile = $1 "/" compatarchdirs[d]
4051.165Smatt				tmp = xfile substr(tmp, length($1) + 1)
4061.165Smatt				if (xfile in notwanted)
4071.165Smatt					continue;
4081.165Smatt				sub("compatdir","compat",tmp);
4091.165Smatt				sub("compattestdir","compat",tmp);
4101.165Smatt				list[xfile] = tmp
4111.165Smatt			}
4121.9Slukem			next
4131.9Slukem		}
4141.9Slukem
4151.9Slukem		{
4161.165Smatt			if ($1 in notwanted)
4171.127Smatt				next;
4181.9Slukem			if (! obsolete)
4191.127Smatt				list[$1] = $0
4201.127Smatt		}
4211.127Smatt
4221.127Smatt		END {
4231.127Smatt			for (i in list) {
4241.127Smatt				print list[i]
4251.165Smatt				if (! (i in emitcompat))
4261.165Smatt					continue;
4271.165Smatt				l_i = length(i)
4281.165Smatt				l = 0
4291.165Smatt				for (j in cpaths) {
4301.165Smatt					lx = length(cpaths[j])
4311.165Smatt					if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
4321.165Smatt						continue;
4331.165Smatt					}
4341.165Smatt					if (lx > l) {
4351.165Smatt						l = lx;
4361.165Smatt						cpath = cpaths[j];
4371.165Smatt					}
4381.165Smatt				}
4391.165Smatt				for (d in compatarchdirs) {
4401.165Smatt					tmp = list[i]
4411.165Smatt					extrapath = compatarchdirs[d] "/"
4421.165Smatt					xfile = cpath extrapath substr(i, l + 1)
4431.165Smatt					if (xfile in notwanted)
4441.165Smatt						continue;
4451.165Smatt					sub("compatfile","compat",tmp);
4461.165Smatt					sub("compattestfile","compat",tmp);
4471.165Smatt					tmp = xfile substr(tmp, l_i + 1)
4481.165Smatt					print tmp;
4491.165Smatt				}
4501.127Smatt			}
4511.9Slukem		}'
4521.9Slukem
4531.1Sdyoung}
4541.1Sdyoung
4551.1Sdyoung#
4561.1Sdyoung# list_set_lists setname
4571.1Sdyoung# 
4581.1Sdyoung# Print to stdout a list of files, one filename per line, which
4591.1Sdyoung# concatenate to create the packing list for setname. E.g.,
4601.1Sdyoung#
4611.1Sdyoung# 	.../lists/base/mi
4621.1Sdyoung# 	.../lists/base/rescue.mi
4631.1Sdyoung# 	.../lists/base/md.i386
4641.9Slukem#		[...]
4651.1Sdyoung#
4661.9Slukem# For a given setname $set, the following files may be selected from
4671.9Slukem# .../list/$set:
4681.9Slukem#	mi
4691.92Suebayasi#	mi.ext.*
4701.11Slukem#	ad.${MACHINE_ARCH}
4711.11Slukem# (or)	ad.${MACHINE_CPU}
4721.11Slukem#	ad.${MACHINE_CPU}.shl
4731.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
4741.11Slukem# (or)	md.${MACHINE}
4751.9Slukem#	stl.mi
4761.92Suebayasi#	stl.${stlib}
4771.9Slukem#	shl.mi
4781.92Suebayasi#	shl.mi.ext.*
4791.92Suebayasi#	shl.${shlib}
4801.92Suebayasi#	shl.${shlib}.ext.*
4811.77Stsutsui#	module.mi			if ${module} != no
4821.77Stsutsui#	module.${MACHINE}		if ${module} != no
4831.77Stsutsui#	module.ad.${MACHINE_ARCH}	if ${module} != no
4841.77Stsutsui# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
4851.9Slukem#	rescue.shl
4861.11Slukem#	rescue.${MACHINE}
4871.11Slukem#	rescue.ad.${MACHINE_ARCH}
4881.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
4891.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
4901.1Sdyoung#
4911.9Slukem# Environment:
4921.1Sdyoung# 	shlib
4931.1Sdyoung# 	stlib
4941.1Sdyoung#
4951.8Slukemlist_set_lists()
4961.8Slukem{
4971.1Sdyoung	setname=$1
4981.1Sdyoung
4991.111Suebayasi	list_set_lists_mi $setname
5001.113Suebayasi	list_set_lists_ad $setname
5011.111Suebayasi	list_set_lists_md $setname
5021.111Suebayasi	list_set_lists_stl $setname
5031.113Suebayasi	list_set_lists_shl $setname
5041.113Suebayasi	list_set_lists_module $setname
5051.111Suebayasi	list_set_lists_rescue $setname
5061.117Suebayasi	return 0
5071.111Suebayasi}
5081.110Suebayasi
5091.111Suebayasilist_set_lists_mi()
5101.111Suebayasi{
5111.111Suebayasi	setdir=$setsdir/lists/$1
5121.113Suebayasi	# always exist!
5131.9Slukem	echo $setdir/mi
5141.111Suebayasi}
5151.110Suebayasi
5161.111Suebayasilist_set_lists_ad()
5171.111Suebayasi{
5181.111Suebayasi	setdir=$setsdir/lists/$1
5191.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5201.113Suebayasi	list_set_lists_common_ad $1
5211.111Suebayasi}
5221.110Suebayasi
5231.111Suebayasilist_set_lists_md()
5241.111Suebayasi{
5251.111Suebayasi	setdir=$setsdir/lists/$1
5261.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
5271.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}
5281.111Suebayasi}
5291.110Suebayasi
5301.111Suebayasilist_set_lists_stl()
5311.111Suebayasi{
5321.111Suebayasi	setdir=$setsdir/lists/$1
5331.110Suebayasi	echo_if_exist $setdir/stl.mi
5341.110Suebayasi	echo_if_exist $setdir/stl.${stlib}
5351.111Suebayasi}
5361.110Suebayasi
5371.111Suebayasilist_set_lists_shl()
5381.111Suebayasi{
5391.111Suebayasi	setdir=$setsdir/lists/$1
5401.113Suebayasi	[ "$shlib" != "no" ] || return
5411.112Suebayasi	echo_if_exist $setdir/shl.mi
5421.112Suebayasi	echo_if_exist $setdir/shl.${shlib}
5431.111Suebayasi}
5441.110Suebayasi
5451.111Suebayasilist_set_lists_module()
5461.111Suebayasi{
5471.111Suebayasi	setdir=$setsdir/lists/$1
5481.113Suebayasi	[ "$module" != "no" ] || return
5491.112Suebayasi	echo_if_exist $setdir/module.mi
5501.112Suebayasi	echo_if_exist $setdir/module.${MACHINE}
5511.113Suebayasi	# XXX module never has .shl
5521.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5531.113Suebayasi	list_set_lists_common_ad $1 module
5541.111Suebayasi}
5551.1Sdyoung
5561.111Suebayasilist_set_lists_rescue()
5571.111Suebayasi{
5581.111Suebayasi	setdir=$setsdir/lists/$1
5591.110Suebayasi	echo_if_exist $setdir/rescue.mi
5601.110Suebayasi	echo_if_exist $setdir/rescue.${MACHINE}
5611.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5621.113Suebayasi	list_set_lists_common_ad $1 rescue
5631.111Suebayasi}
5641.111Suebayasi
5651.113Suebayasilist_set_lists_common_ad()
5661.111Suebayasi{
5671.113Suebayasi	setdir=$setsdir/lists/$1; _prefix=$2
5681.113Suebayasi
5691.113Suebayasi	[ -n "$_prefix" ] && prefix="$_prefix".
5701.113Suebayasi
5711.113Suebayasi	# Prefer a <prefix>.ad.${MACHINE_ARCH} over a
5721.113Suebayasi	# <prefix>.ad.${MACHINE_CPU}, since the arch-
5731.112Suebayasi	# specific one will be more specific than the
5741.112Suebayasi	# cpu-specific one.
5751.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
5761.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
5771.113Suebayasi	[ "$shlib" != "no" ] && \
5781.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
5791.5Sdyoung}
5801.5Sdyoung
5811.110Suebayasiecho_if_exist()
5821.110Suebayasi{
5831.110Suebayasi	[ -f $1 ] && echo $1
5841.110Suebayasi	return $?
5851.110Suebayasi}
5861.110Suebayasi
5871.110Suebayasiecho_if_exist_foreach()
5881.110Suebayasi{
5891.110Suebayasi	local _list=$1; shift
5901.110Suebayasi	for _suffix in $@; do
5911.110Suebayasi		echo_if_exist ${_list}.${_suffix}
5921.110Suebayasi	done
5931.110Suebayasi}
5941.110Suebayasi
5951.116Suebayasiprint_set_lists()
5961.116Suebayasi{
5971.116Suebayasi	for setname; do
5981.136Schristos		list=$(list_set_lists $setname)
5991.116Suebayasi		for l in $list; do
6001.116Suebayasi			echo $l
6011.116Suebayasi			if $verbose; then
6021.116Suebayasi				echo >&2 "DEBUG: list_set_files: $l"
6031.116Suebayasi			fi
6041.116Suebayasi		done
6051.118Suebayasi	done | ${XARGS} ${SED} ${SUBST}
6061.116Suebayasi}
6071.116Suebayasi
6081.9Slukem# arch_to_cpu mach
6091.9Slukem#
6101.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
6111.9Slukem# as determined by <bsd.own.mk>.
6121.9Slukem#
6131.8Slukemarch_to_cpu()
6141.8Slukem{
6151.182Suwe	MACHINE_ARCH=${1} MAKEFLAGS= \
6161.182Suwe	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
6171.182Suwe		-f ${NETBSDSRCDIR}/share/mk/bsd.own.mk \
6181.182Suwe		-V '${MACHINE_CPU}'
6191.1Sdyoung}
6201.46Sapb
6211.46Sapb# arch_to_endian mach
6221.46Sapb#
6231.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
6241.46Sapb# as determined by <bsd.endian.mk>.
6251.46Sapb#
6261.46Sapbarch_to_endian()
6271.46Sapb{
6281.182Suwe	MACHINE_ARCH=${1} MAKEFLAGS= \
6291.182Suwe	${MAKE} -m ${NETBSDSRCDIR}/share/mk \
6301.182Suwe		-f ${NETBSDSRCDIR}/share/mk/bsd.endian.mk \
6311.182Suwe		-V '${TARGET_ENDIANNESS}'
6321.46Sapb}
6331.117Suebayasi
6341.117Suebayasi#####
6351.117Suebayasi
6361.117Suebayasi# print_mkvars
6371.117Suebayasiprint_mkvars()
6381.117Suebayasi{
6391.117Suebayasi	for v in $MKVARS; do
6401.117Suebayasi		eval echo $v=\$$v
6411.117Suebayasi	done
6421.117Suebayasi}
6431.117Suebayasi
6441.117Suebayasi# print_set_lists_{base,x,ext}
6451.117Suebayasi# list_set_lists_{base,x,ext}
6461.117Suebayasi# list_set_files_{base,x,ext}
6471.117Suebayasifor func in print_set_lists list_set_lists list_set_files; do
6481.117Suebayasi	for x in base x ext; do
6491.117Suebayasi		if [ $x = base ]; then
6501.117Suebayasi			list=nlists
6511.117Suebayasi		else
6521.117Suebayasi			list=${x}lists
6531.117Suebayasi		fi
6541.117Suebayasi		eval ${func}_${x} \(\) \{ $func \$$list \; \}
6551.117Suebayasi	done
6561.117Suebayasidone
657