sets.subr revision 1.180
11.180Schristos#	$NetBSD: sets.subr,v 1.180 2017/11/22 21:31:20 christos 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.11Slukem#	TOOLCHAIN_MISSING
241.11Slukem#	OBJECT_FMT
251.22Slukem# as well as:
261.22Slukem#
271.95Suebayasi
281.42Sapb#
291.42Sapb# The following variables refer to tools that are used when building sets:
301.42Sapb#
311.43Sapb: ${AWK:=awk}
321.42Sapb: ${CKSUM:=cksum}
331.43Sapb: ${COMM:=comm}
341.44Sapb: ${DATE:=date}
351.43Sapb: ${DB:=db}
361.43Sapb: ${EGREP:=egrep}
371.43Sapb: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
381.44Sapb: ${FGREP:=fgrep}
391.43Sapb: ${FIND:=find}
401.44Sapb: ${GREP:=grep}
411.43Sapb: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
421.99Sapb: ${HOSTNAME_CMD:=hostname}	# ${HOSTNAME} is special to bash(1)
431.42Sapb: ${HOST_SH:=sh}
441.43Sapb: ${IDENT:=ident}
451.43Sapb: ${JOIN:=join}
461.43Sapb: ${LS:=ls}
471.43Sapb: ${MAKE:=make}
481.42Sapb: ${MKTEMP:=mktemp}
491.43Sapb: ${MTREE:=mtree}
501.43Sapb: ${PASTE:=paste}
511.42Sapb: ${PAX:=pax}
521.43Sapb: ${PRINTF:=printf}
531.43Sapb: ${SED:=sed}
541.43Sapb: ${SORT:=sort}
551.44Sapb: ${STAT:=stat}
561.44Sapb: ${TSORT:=tsort}
571.43Sapb: ${UNAME:=uname}
581.43Sapb: ${WC:=wc}
591.118Suebayasi: ${XARGS:=xargs}
601.43Sapb
611.45Sapb#
621.45Sapb# If printf is a shell builtin command, then we can
631.45Sapb# implement cheaper versions of basename and dirname
641.45Sapb# that do not involve any fork/exec overhead.
651.45Sapb# If printf is not builtin, approximate it using echo,
661.45Sapb# and hope there are no weird file names that cause
671.45Sapb# some versions of echo to do the wrong thing.
681.45Sapb# (Converting to this version of dirname speeded up the
691.45Sapb# syspkgdeps script by an order of magnitude, from 68
701.45Sapb# seconds to 6.3 seconds on one particular host.)
711.45Sapb#
721.45Sapb# Note that naive approximations for dirname
731.45Sapb# using ${foo%/*} do not do the right thing in cases
741.45Sapb# where the result should be "/" or ".".
751.45Sapb#
761.45Sapbcase "$(type printf)" in
771.45Sapb*builtin*)
781.45Sapb	basename ()
791.45Sapb	{
801.45Sapb		local bn
811.45Sapb		bn="${1##*/}"
821.45Sapb		bn="${bn%$2}"
831.45Sapb		printf "%s\n" "$bn"
841.45Sapb	}
851.45Sapb	dirname ()
861.45Sapb	{
871.45Sapb		local dn
881.45Sapb		case "$1" in
891.45Sapb		?*/*)	dn="${1%/*}" ;;
901.45Sapb		/*)	dn=/ ;;
911.45Sapb		*)	dn=. ;;
921.45Sapb		esac
931.45Sapb		printf "%s\n" "$dn"
941.45Sapb	}
951.45Sapb	;;
961.45Sapb*)
971.45Sapb	basename ()
981.45Sapb	{
991.45Sapb		local bn
1001.45Sapb		bn="${1##*/}"
1011.45Sapb		bn="${bn%$2}"
1021.45Sapb		echo "$bn"
1031.45Sapb	}
1041.45Sapb	dirname ()
1051.45Sapb	{
1061.45Sapb		local dn
1071.45Sapb		case "$1" in
1081.45Sapb		?*/*)	dn="${1%/*}" ;;
1091.45Sapb		/*)	dn=/ ;;
1101.45Sapb		*)	dn=. ;;
1111.45Sapb		esac
1121.45Sapb		echo "$dn"
1131.45Sapb	}
1141.45Sapb	;;
1151.45Sapbesac
1161.45Sapb
1171.108Suebayasi#####
1181.108Suebayasi
1191.9SlukemoIFS=$IFS
1201.9SlukemIFS="
1211.9Slukem"
1221.100Suebayasi
1231.180Schristosfor x in $( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
1241.108Suebayasi	eval export $x
1251.9Slukemdone
1261.100Suebayasi
1271.9SlukemIFS=$oIFS
1281.9Slukem
1291.180SchristosMKVARS="$( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )"
1301.100Suebayasi
1311.105Suebayasi#####
1321.105Suebayasi
1331.117Suebayasisetsdir=${rundir}
1341.9Slukemobsolete=0
1351.91Sdyoungif [ "${MKKMOD}" = "no" ]; then
1361.91Sdyoung	module=no			# MODULEs are off.
1371.125Snjoly	modset=""
1381.125Snjolyelse
1391.125Snjoly	module=yes
1401.125Snjoly	modset="modules"
1411.125Snjolyfi
1421.125Snjolyif [ "${MKATF}" = "no" ]; then
1431.125Snjoly	testset=""
1441.125Snjolyelse
1451.125Snjoly	testset="tests"
1461.9Slukemfi
1471.171Smattif [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then
1481.141Schristos	debugset=""
1491.142Schristos	xdebugset=""
1501.141Schristoselse
1511.141Schristos	debugset="debug"
1521.142Schristos	xdebugset="xdebug"
1531.141Schristosfi
1541.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1551.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1561.9Slukem	shlib=elf
1571.9Slukemelse
1581.9Slukem	shlib=aout
1591.9Slukemfi
1601.9Slukemstlib=$shlib
1611.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1621.31Sjmcif [ "${MKPIC}" = "no" ]; then
1631.31Sjmc	shlib=no
1641.31Sjmcfi
1651.141Schristosnlists="base comp $debugset etc games man misc $modset $testset text"
1661.142Schristosxlists="xbase xcomp $xdebugset xetc xfont xserver"
1671.92Suebayasiextlists="extbase extcomp extetc"
1681.9Slukem
1691.136SchristosOSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
1701.81SrmindMODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
1711.62SadSUBST="s#@MODULEDIR@#${MODULEDIR}#g"
1721.62SadSUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
1731.62SadSUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
1741.60Sad
1751.9Slukem#
1761.9Slukem# list_set_files setfile [...]
1771.1Sdyoung# 
1781.9Slukem# Produce a packing list for setfile(s).
1791.9Slukem# In each file, a record consists of a path and a System Package name,
1801.9Slukem# separated by whitespace. E.g.,
1811.9Slukem#
1821.180Schristos# 	# $NetBSD: sets.subr,v 1.180 2017/11/22 21:31:20 christos Exp $
1831.9Slukem# 	.			base-sys-root	[keyword[,...]]
1841.9Slukem# 	./altroot		base-sys-root
1851.9Slukem# 	./bin			base-sys-root
1861.9Slukem# 	./bin/[			base-util-root
1871.9Slukem# 	./bin/cat		base-util-root
1881.9Slukem#		[...]
1891.9Slukem#
1901.9Slukem# A # in the first column marks a comment.
1911.9Slukem#
1921.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1931.52Slukem# be printed.  All other keywords must be present.
1941.9Slukem#
1951.9Slukem# The third field is an optional comma separated list of keywords to
1961.9Slukem# control if a record is printed; every keyword listed must be enabled
1971.179Schristos# for the record to be printed. The list of all avalaible make variables
1981.179Schristos# that can be turned on or off can be found by running in this directory:
1991.179Schristos#
2001.179Schristos#	make -f mkvars.mk mkvarsyesno
2011.179Schristos#
2021.179Schristos# These MK<NAME> variables can be used as selectors in the sets as <name>.
2031.179Schristos# 
2041.179Schristos# The following extra keywords are also available, listed by:
2051.179Schristos#
2061.179Schristos#	make -f mkvars.mk mkextravars
2071.13Slukem#
2081.179Schristos# These are:
2091.179Schristos#    1. The HAVE_<name>:
2101.179Schristos#	ssp			${HAVE_SSP} != no
2111.160Sjoerg#	libgcc_eh		${HAVE_LIBGCC_EH} != no
2121.87Sskrll#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
2131.52Slukem#	gcc=<n>			<n> = value of ${HAVE_GCC}
2141.52Slukem#	gdb=<n>			<n> = value of ${HAVE_GDB}
2151.177Smrg#	xorg_server_ver=<n>	<n> = value of ${HAVE_XORG_SERVER_VER}
2161.52Slukem#
2171.179Schristos#    2. The USE_<name>:
2181.41Slukem#	use_inet6		${USE_INET6} != no
2191.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2201.179Schristos#	use_ldap		${USE_LDAP} != no
2211.41Slukem#	use_yp			${USE_YP} != no
2221.41Slukem#
2231.179Schristos#    3. Finally:
2241.179Schristos#	dummy			dummy entry (ignored)
2251.179Schristos#	obsolete		file is obsolete, and only printed if 
2261.179Schristos#				${obsolete} != 0
2271.179Schristos#
2281.179Schristos#	solaris			${MKDTRACE} != no or ${MKZFS} != no or ${MKCTF} != no
2291.179Schristos#
2301.179Schristos#
2311.179Schristos#	endian=<n>		<n> = value of ${TARGET_ENDIANNESS}
2321.179Schristos#
2331.179Schristos#
2341.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2351.22Slukem#				  automatically append ".gz" to the filename
2361.22Slukem#
2371.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2381.22Slukem#				  automatically append ".gz" to the filename
2391.1Sdyoung#
2401.8Slukemlist_set_files()
2411.8Slukem{
2421.83Sapb	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
2431.65She		verbose=false
2441.65She	else
2451.65She		verbose=true
2461.65She	fi
2471.116Suebayasi	print_set_lists "$@" | \
2481.43Sapb	${AWK} -v obsolete=${obsolete} '
2491.9Slukem		BEGIN {
2501.52Slukem			if (obsolete)
2511.52Slukem				wanted["obsolete"] = 1
2521.52Slukem		
2531.100Suebayasi			split("'"${MKVARS}"'", needvars)
2541.165Smatt			doingcompat = 0
2551.165Smatt			doingcompattests = 0
2561.165Smatt			ignoredkeywords["compatdir"] = 1
2571.165Smatt			ignoredkeywords["compatfile"] = 1
2581.165Smatt			ignoredkeywords["compattestdir"] = 1
2591.165Smatt			ignoredkeywords["compattestfile"] = 1
2601.170Smatt			ignoredkeywords["compatx11dir"] = 1
2611.170Smatt			ignoredkeywords["compatx11file"] = 1
2621.52Slukem			for (vi in needvars) {
2631.52Slukem				nv = needvars[vi]
2641.52Slukem				kw = tolower(nv)
2651.52Slukem				sub(/^mk/, "", kw)
2661.143Snakayama				sub(/^have_/, "", kw)
2671.148Smatt				sub(/^target_endianness/, "endian", kw)
2681.167Smatt				if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
2691.165Smatt					wanted[kw] = 1 
2701.167Smatt				}
2711.166Smatt			}
2721.166Smatt
2731.167Smatt			if ("compat" in wanted) {
2741.166Smatt				doingcompat = 1;
2751.166Smatt				split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
2761.166Smatt				compatdirkeywords["compatdir"] = 1
2771.166Smatt				compatfilekeywords["compatfile"] = 1
2781.166Smatt
2791.166Smatt				if (wanted["compattests"]) {
2801.165Smatt					doingcompattests = 1;
2811.165Smatt					compatdirkeywords["compattestdir"] = 1
2821.165Smatt					compatfilekeywords["compattestfile"] = 1
2831.166Smatt				}
2841.170Smatt				if (wanted["compatx11"]) {
2851.170Smatt					doingcompatx11 = 1;
2861.170Smatt					compatdirkeywords["compatx11dir"] = 1
2871.170Smatt					compatfilekeywords["compatx11file"] = 1
2881.170Smatt				}
2891.166Smatt			}
2901.166Smatt
2911.167Smatt			if (("kmod" in wanted) && ("compatmodules" in wanted)) {
2921.166Smatt				split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
2931.166Smatt				kmodpat = "./stand/" ENVIRON["MACHINE"]
2941.166Smatt				l_kmodpat = length(kmodpat)
2951.52Slukem			}
2961.52Slukem
2971.52Slukem			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
2981.90Sdyoung				if ("binutils" in wanted)
2991.90Sdyoung					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
3001.90Sdyoung				if ("gcc" in wanted)
3011.90Sdyoung					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
3021.90Sdyoung				if ("gdb" in wanted)
3031.90Sdyoung					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
3041.9Slukem			}
3051.178Smrg			if ("xorg_server_ver" in wanted) {
3061.178Smrg				wanted["xorg_server_ver=" "'"${HAVE_XORG_SERVER_VER}"'"] = 1
3071.177Smrg			}
3081.52Slukem			if (("man" in wanted) && ("catpages" in wanted))
3091.52Slukem				wanted[".cat"] = 1
3101.52Slukem			if (("man" in wanted) && ("manpages" in wanted))
3111.52Slukem				wanted[".man"] = 1
3121.148Smatt			if ("endian" in wanted)
3131.148Smatt				wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
3141.162Smrg			if ("machine" in wanted)
3151.162Smrg				wanted["machine=" "'"${MACHINE}"'"] = 1
3161.162Smrg			if ("machine_arch" in wanted)
3171.162Smrg				wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
3181.162Smrg			if ("machine_cpu" in wanted)
3191.162Smrg				wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
3201.9Slukem		}
3211.9Slukem
3221.9Slukem		/^#/ {
3231.9Slukem			next;
3241.9Slukem		}
3251.9Slukem
3261.127Smatt		/^-/ {
3271.127Smatt			notwanted[substr($1, 2)] = 1;
3281.127Smatt			delete list [substr($1, 2)];
3291.127Smatt			next;
3301.127Smatt		}
3311.127Smatt				
3321.127Smatt
3331.9Slukem		NF > 2 && $3 != "-" {
3341.127Smatt			if (notwanted[$1] != "")
3351.127Smatt				next;
3361.9Slukem			split($3, keywords, ",")
3371.9Slukem			show = 1
3381.52Slukem			haveobs = 0
3391.167Smatt			iscompatfile = 0
3401.165Smatt			havekmod = 0
3411.165Smatt			iscompatdir = 0
3421.9Slukem			for (ki in keywords) {
3431.9Slukem				kw = keywords[ki]
3441.22Slukem				if (("manz" in wanted) &&
3451.22Slukem				    (kw == ".cat" || kw == ".man"))
3461.22Slukem					$1 = $1 ".gz"
3471.134Sjoerg				if (substr(kw, 1, 1) == "!") {
3481.134Sjoerg					kw = substr(kw, 2)
3491.59Sjmmv					if (kw in wanted)
3501.59Sjmmv						show = 0
3511.165Smatt				} else if (kw in compatdirkeywords) {
3521.165Smatt					iscompatdir = 1
3531.165Smatt				} else if (kw in compatfilekeywords) {
3541.167Smatt					iscompatfile = 1
3551.172Smatt				} else if (kw == "nocompatmodules") {
3561.172Smatt					havekmod = -1
3571.165Smatt				} else if (kw in ignoredkeywords) {
3581.165Smatt					# ignore
3591.167Smatt				} else if (! (kw in wanted)) {
3601.167Smatt					show = 0
3611.172Smatt				} else if (kw == "kmod" && havekmod == 0) {
3621.167Smatt					havekmod = 1
3631.59Sjmmv				}
3641.52Slukem				if (kw == "obsolete")
3651.52Slukem					haveobs = 1
3661.9Slukem			}
3671.52Slukem			if (obsolete && ! haveobs)
3681.52Slukem				next
3691.165Smatt			if (!show)
3701.165Smatt				next
3711.165Smatt
3721.165Smatt			list[$1] = $0
3731.172Smatt			if (havekmod > 0 && substr($1,1,l_kmodpat) == kmodpat) {
3741.165Smatt				for (d in kmodarchdirs) {
3751.165Smatt					xd = "./stand/" kmodarchdirs[d]
3761.165Smatt					xfile = xd substr($1, l_kmodpat+1)
3771.165Smatt					tmp = xd substr($0, l_kmodpat+1)
3781.165Smatt					list[xfile] = tmp;
3791.165Smatt				}
3801.165Smatt				next
3811.165Smatt			}
3821.165Smatt
3831.167Smatt			if (!doingcompat || !(iscompatfile || iscompatdir))
3841.165Smatt				next
3851.165Smatt
3861.167Smatt			if (iscompatfile) {
3871.165Smatt				emitcompat[$1] = 1;
3881.168Smatt				next
3891.168Smatt			}
3901.168Smatt			for (d in cpaths) {
3911.168Smatt				if (cpaths[d] == $1 "/")
3921.168Smatt					next
3931.165Smatt			}
3941.165Smatt			cpaths[ncpaths++] = $1 "/"
3951.165Smatt			for (d in compatarchdirs) {
3961.165Smatt				tmp = $0
3971.165Smatt				xfile = $1 "/" compatarchdirs[d]
3981.165Smatt				tmp = xfile substr(tmp, length($1) + 1)
3991.165Smatt				if (xfile in notwanted)
4001.165Smatt					continue;
4011.165Smatt				sub("compatdir","compat",tmp);
4021.165Smatt				sub("compattestdir","compat",tmp);
4031.165Smatt				list[xfile] = tmp
4041.165Smatt			}
4051.9Slukem			next
4061.9Slukem		}
4071.9Slukem
4081.9Slukem		{
4091.165Smatt			if ($1 in notwanted)
4101.127Smatt				next;
4111.9Slukem			if (! obsolete)
4121.127Smatt				list[$1] = $0
4131.127Smatt		}
4141.127Smatt
4151.127Smatt		END {
4161.127Smatt			for (i in list) {
4171.127Smatt				print list[i]
4181.165Smatt				if (! (i in emitcompat))
4191.165Smatt					continue;
4201.165Smatt				l_i = length(i)
4211.165Smatt				l = 0
4221.165Smatt				for (j in cpaths) {
4231.165Smatt					lx = length(cpaths[j])
4241.165Smatt					if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
4251.165Smatt						continue;
4261.165Smatt					}
4271.165Smatt					if (lx > l) {
4281.165Smatt						l = lx;
4291.165Smatt						cpath = cpaths[j];
4301.165Smatt					}
4311.165Smatt				}
4321.165Smatt				for (d in compatarchdirs) {
4331.165Smatt					tmp = list[i]
4341.165Smatt					extrapath = compatarchdirs[d] "/"
4351.165Smatt					xfile = cpath extrapath substr(i, l + 1)
4361.165Smatt					if (xfile in notwanted)
4371.165Smatt						continue;
4381.165Smatt					sub("compatfile","compat",tmp);
4391.165Smatt					sub("compattestfile","compat",tmp);
4401.165Smatt					tmp = xfile substr(tmp, l_i + 1)
4411.165Smatt					print tmp;
4421.165Smatt				}
4431.127Smatt			}
4441.9Slukem		}'
4451.9Slukem
4461.1Sdyoung}
4471.1Sdyoung
4481.1Sdyoung#
4491.1Sdyoung# list_set_lists setname
4501.1Sdyoung# 
4511.1Sdyoung# Print to stdout a list of files, one filename per line, which
4521.1Sdyoung# concatenate to create the packing list for setname. E.g.,
4531.1Sdyoung#
4541.1Sdyoung# 	.../lists/base/mi
4551.1Sdyoung# 	.../lists/base/rescue.mi
4561.1Sdyoung# 	.../lists/base/md.i386
4571.9Slukem#		[...]
4581.1Sdyoung#
4591.9Slukem# For a given setname $set, the following files may be selected from
4601.9Slukem# .../list/$set:
4611.9Slukem#	mi
4621.92Suebayasi#	mi.ext.*
4631.11Slukem#	ad.${MACHINE_ARCH}
4641.11Slukem# (or)	ad.${MACHINE_CPU}
4651.11Slukem#	ad.${MACHINE_CPU}.shl
4661.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
4671.11Slukem# (or)	md.${MACHINE}
4681.9Slukem#	stl.mi
4691.92Suebayasi#	stl.${stlib}
4701.9Slukem#	shl.mi
4711.92Suebayasi#	shl.mi.ext.*
4721.92Suebayasi#	shl.${shlib}
4731.92Suebayasi#	shl.${shlib}.ext.*
4741.77Stsutsui#	module.mi			if ${module} != no
4751.77Stsutsui#	module.${MACHINE}		if ${module} != no
4761.77Stsutsui#	module.ad.${MACHINE_ARCH}	if ${module} != no
4771.77Stsutsui# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
4781.9Slukem#	rescue.shl
4791.11Slukem#	rescue.${MACHINE}
4801.11Slukem#	rescue.ad.${MACHINE_ARCH}
4811.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
4821.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
4831.1Sdyoung#
4841.9Slukem# Environment:
4851.1Sdyoung# 	shlib
4861.1Sdyoung# 	stlib
4871.1Sdyoung#
4881.8Slukemlist_set_lists()
4891.8Slukem{
4901.1Sdyoung	setname=$1
4911.1Sdyoung
4921.111Suebayasi	list_set_lists_mi $setname
4931.113Suebayasi	list_set_lists_ad $setname
4941.111Suebayasi	list_set_lists_md $setname
4951.111Suebayasi	list_set_lists_stl $setname
4961.113Suebayasi	list_set_lists_shl $setname
4971.113Suebayasi	list_set_lists_module $setname
4981.111Suebayasi	list_set_lists_rescue $setname
4991.117Suebayasi	return 0
5001.111Suebayasi}
5011.110Suebayasi
5021.111Suebayasilist_set_lists_mi()
5031.111Suebayasi{
5041.111Suebayasi	setdir=$setsdir/lists/$1
5051.113Suebayasi	# always exist!
5061.9Slukem	echo $setdir/mi
5071.111Suebayasi}
5081.110Suebayasi
5091.111Suebayasilist_set_lists_ad()
5101.111Suebayasi{
5111.111Suebayasi	setdir=$setsdir/lists/$1
5121.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5131.113Suebayasi	list_set_lists_common_ad $1
5141.111Suebayasi}
5151.110Suebayasi
5161.111Suebayasilist_set_lists_md()
5171.111Suebayasi{
5181.111Suebayasi	setdir=$setsdir/lists/$1
5191.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
5201.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}
5211.111Suebayasi}
5221.110Suebayasi
5231.111Suebayasilist_set_lists_stl()
5241.111Suebayasi{
5251.111Suebayasi	setdir=$setsdir/lists/$1
5261.110Suebayasi	echo_if_exist $setdir/stl.mi
5271.110Suebayasi	echo_if_exist $setdir/stl.${stlib}
5281.111Suebayasi}
5291.110Suebayasi
5301.111Suebayasilist_set_lists_shl()
5311.111Suebayasi{
5321.111Suebayasi	setdir=$setsdir/lists/$1
5331.113Suebayasi	[ "$shlib" != "no" ] || return
5341.112Suebayasi	echo_if_exist $setdir/shl.mi
5351.112Suebayasi	echo_if_exist $setdir/shl.${shlib}
5361.111Suebayasi}
5371.110Suebayasi
5381.111Suebayasilist_set_lists_module()
5391.111Suebayasi{
5401.111Suebayasi	setdir=$setsdir/lists/$1
5411.113Suebayasi	[ "$module" != "no" ] || return
5421.112Suebayasi	echo_if_exist $setdir/module.mi
5431.112Suebayasi	echo_if_exist $setdir/module.${MACHINE}
5441.113Suebayasi	# XXX module never has .shl
5451.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5461.113Suebayasi	list_set_lists_common_ad $1 module
5471.111Suebayasi}
5481.1Sdyoung
5491.111Suebayasilist_set_lists_rescue()
5501.111Suebayasi{
5511.111Suebayasi	setdir=$setsdir/lists/$1
5521.110Suebayasi	echo_if_exist $setdir/rescue.mi
5531.110Suebayasi	echo_if_exist $setdir/rescue.${MACHINE}
5541.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5551.113Suebayasi	list_set_lists_common_ad $1 rescue
5561.111Suebayasi}
5571.111Suebayasi
5581.113Suebayasilist_set_lists_common_ad()
5591.111Suebayasi{
5601.113Suebayasi	setdir=$setsdir/lists/$1; _prefix=$2
5611.113Suebayasi
5621.113Suebayasi	[ -n "$_prefix" ] && prefix="$_prefix".
5631.113Suebayasi
5641.113Suebayasi	# Prefer a <prefix>.ad.${MACHINE_ARCH} over a
5651.113Suebayasi	# <prefix>.ad.${MACHINE_CPU}, since the arch-
5661.112Suebayasi	# specific one will be more specific than the
5671.112Suebayasi	# cpu-specific one.
5681.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
5691.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
5701.113Suebayasi	[ "$shlib" != "no" ] && \
5711.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
5721.5Sdyoung}
5731.5Sdyoung
5741.110Suebayasiecho_if_exist()
5751.110Suebayasi{
5761.110Suebayasi	[ -f $1 ] && echo $1
5771.110Suebayasi	return $?
5781.110Suebayasi}
5791.110Suebayasi
5801.110Suebayasiecho_if_exist_foreach()
5811.110Suebayasi{
5821.110Suebayasi	local _list=$1; shift
5831.110Suebayasi	for _suffix in $@; do
5841.110Suebayasi		echo_if_exist ${_list}.${_suffix}
5851.110Suebayasi	done
5861.110Suebayasi}
5871.110Suebayasi
5881.116Suebayasiprint_set_lists()
5891.116Suebayasi{
5901.116Suebayasi	for setname; do
5911.136Schristos		list=$(list_set_lists $setname)
5921.116Suebayasi		for l in $list; do
5931.116Suebayasi			echo $l
5941.116Suebayasi			if $verbose; then
5951.116Suebayasi				echo >&2 "DEBUG: list_set_files: $l"
5961.116Suebayasi			fi
5971.116Suebayasi		done
5981.118Suebayasi	done | ${XARGS} ${SED} ${SUBST}
5991.116Suebayasi}
6001.116Suebayasi
6011.9Slukem# arch_to_cpu mach
6021.9Slukem#
6031.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
6041.9Slukem# as determined by <bsd.own.mk>.
6051.9Slukem#
6061.8Slukemarch_to_cpu()
6071.8Slukem{
6081.180Schristos	MAKEVERBOSE= MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
6091.5Sdyoung.include <bsd.own.mk>
6101.5Sdyoungall:
6111.5Sdyoung	@echo \${MACHINE_CPU}
6121.12SlukemEOMAKE
6131.1Sdyoung}
6141.46Sapb
6151.46Sapb# arch_to_endian mach
6161.46Sapb#
6171.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
6181.46Sapb# as determined by <bsd.endian.mk>.
6191.46Sapb#
6201.46Sapbarch_to_endian()
6211.46Sapb{
6221.180Schristos	MAKEVERBOSE= MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
6231.46Sapb.include <bsd.endian.mk>
6241.46Sapball:
6251.46Sapb	@echo \${TARGET_ENDIANNESS}
6261.46SapbEOMAKE
6271.46Sapb}
6281.117Suebayasi
6291.117Suebayasi#####
6301.117Suebayasi
6311.117Suebayasi# print_mkvars
6321.117Suebayasiprint_mkvars()
6331.117Suebayasi{
6341.117Suebayasi	for v in $MKVARS; do
6351.117Suebayasi		eval echo $v=\$$v
6361.117Suebayasi	done
6371.117Suebayasi}
6381.117Suebayasi
6391.117Suebayasi# print_set_lists_{base,x,ext}
6401.117Suebayasi# list_set_lists_{base,x,ext}
6411.117Suebayasi# list_set_files_{base,x,ext}
6421.117Suebayasifor func in print_set_lists list_set_lists list_set_files; do
6431.117Suebayasi	for x in base x ext; do
6441.117Suebayasi		if [ $x = base ]; then
6451.117Suebayasi			list=nlists
6461.117Suebayasi		else
6471.117Suebayasi			list=${x}lists
6481.117Suebayasi		fi
6491.117Suebayasi		eval ${func}_${x} \(\) \{ $func \$$list \; \}
6501.117Suebayasi	done
6511.117Suebayasidone
652