sets.subr revision 1.162
11.162Smrg#	$NetBSD: sets.subr,v 1.162 2015/01/05 03:45:31 mrg 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.109Shefor x in $( ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
1241.108Suebayasi	eval export $x
1251.9Slukemdone
1261.100Suebayasi
1271.9SlukemIFS=$oIFS
1281.9Slukem
1291.118SuebayasiMKVARS="$( ${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.141Schristosif [ "${MKDEBUG}" = "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.162Smrg# 	# $NetBSD: sets.subr,v 1.162 2015/01/05 03:45:31 mrg 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.9Slukem# for the record to be printed.  The following keywords are available:
1981.9Slukem#	dummy			dummy entry (ignored)
1991.13Slukem#	obsolete		file is obsolete, and only printed if 
2001.13Slukem#				${obsolete} != 0
2011.13Slukem#
2021.125Snjoly#	atf			${MKATF} != no
2031.87Sskrll#	bfd			obsolete, use binutils.
2041.87Sskrll#	binutils		${MKBINUTILS} != no
2051.129Sjoerg#	bsdgrep			${MKBSDGREP} != no
2061.22Slukem#	catpages		${MKCATPAGES} != no
2071.71Smrg#	compat			${MKCOMPAT} != no
2081.161Senami#	compatmodules		${MKCOMPATMODULES} != no
2091.22Slukem#	crypto			${MKCRYPTO} != no
2101.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
2111.22Slukem#	cvs			${MKCVS} != no
2121.53Slukem#	debug			${MKDEBUG} != no
2131.69Slukem#	debuglib		${MKDEBUGLIB} != no
2141.23Slukem#	doc			${MKDOC} != no
2151.121Sdarran#	dtrace			${MKDTRACE} != no
2161.67Slukem#	dynamicroot		${MKDYNAMICROOT} != no
2171.92Suebayasi#	extsrc			${MKEXTSRC} != no
2181.52Slukem#	gcc			${MKGCC} != no
2191.36Smatt#	gcccmds			${MKGCCCMDS} != no
2201.32Sscw#	gdb			${MKGDB} != no
2211.22Slukem#	hesiod			${MKHESIOD} != no
2221.68Slukem#	html			${MKHTML} != no
2231.67Slukem#	inet6			${MKINET6} != no
2241.23Slukem#	info			${MKINFO} != no
2251.39Speter#	ipfilter		${MKIPFILTER} != no
2261.51Smrg#	iscsi			${MKISCSI} != no
2271.22Slukem#	kerberos		${MKKERBEROS} != no
2281.85Sdyoung#	kmod			${MKKMOD} != no
2291.144Sjmmv#	kyua			${MKKYUA} != no
2301.67Slukem#	ldap			${MKLDAP} != no
2311.22Slukem#	lint			${MKLINT} != no
2321.146Sjoerg#	libcxx			${MKLIBCXX} != no
2331.160Sjoerg#	libgcc_eh		${HAVE_LIBGCC_EH} != no
2341.147Sjoerg#	libstdcxx		${MKLIBSTDCXX} != no
2351.152Sjoerg#	lld			${MKLLD} != no
2361.153Sjoerg#	lldb			${MKLLDB} != no
2371.128Sjoerg#	llvm			${MKLLVM} != no
2381.78Sagc#	lvm			${MKLVM} != no
2391.135Sjoerg#	makemandb		${MKMAKEMANDB} != no
2401.22Slukem#	man			${MKMAN} != no
2411.67Slukem#	manpages		${MKMANPAGES} != no
2421.22Slukem#	manz			${MKMANZ} != no
2431.145Sjoerg#	mclinker		${MKMCLINKER} != no
2441.88Stsarna#	mdns			${MKMDNS} != no
2451.23Slukem#	nls			${MKNLS} != no
2461.66Sdyoung#	nvi			${MKNVI} != no
2471.37She#	pam			${MKPAM} != no
2481.120Splunky#	pcc			${MKPCC} != no
2491.39Speter#	pf			${MKPF} != no
2501.67Slukem#	pic			${MKPIC} != no
2511.157Stho#	picinstall		${MKPICINSTALL} != no
2521.22Slukem#	postfix			${MKPOSTFIX} != no
2531.22Slukem#	profile			${MKPROFILE} != no
2541.131Shaad#	perfuse			${MKPERFUSE} != no
2551.138Schristos#	rump			${MKRUMP} != no
2561.24Slukem#	share			${MKSHARE} != no
2571.22Slukem#	skey			${MKSKEY} != no
2581.140Salnsn#	sljit			${MKSLJIT} != no
2591.148Smatt#	softfloat		${MKSOFTFLOAT} != no
2601.122Stron#	solaris			${MKDTRACE} != no or ${MKZFS} != no
2611.143Snakayama#	ssp			${HAVE_SSP} != no
2621.139Schristos#	tpm			${MKTPM} != no
2631.73Smrg#	x11			${MKX11} != no && ${X11FLAVOUR} != "Xorg"
2641.73Smrg#	xorg			${MKX11} != no && ${X11FLAVOUR} == "Xorg"
2651.151Smrg#	xorg_server		${MKXORG_SERVER} != no
2661.22Slukem#	yp			${MKYP} != no
2671.89Shaad#	zfs			${MKZFS} != no
2681.22Slukem#
2691.148Smatt#	endian=<n>		<n> = value of ${TARGET_ENDIANNESS}
2701.87Sskrll#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
2711.52Slukem#	gcc=<n>			<n> = value of ${HAVE_GCC}
2721.52Slukem#	gdb=<n>			<n> = value of ${HAVE_GDB}
2731.52Slukem#
2741.41Slukem#	use_inet6		${USE_INET6} != no
2751.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2761.41Slukem#	use_yp			${USE_YP} != no
2771.41Slukem#
2781.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2791.22Slukem#				  automatically append ".gz" to the filename
2801.22Slukem#
2811.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2821.22Slukem#				  automatically append ".gz" to the filename
2831.1Sdyoung#
2841.8Slukemlist_set_files()
2851.8Slukem{
2861.83Sapb	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
2871.65She		verbose=false
2881.65She	else
2891.65She		verbose=true
2901.65She	fi
2911.116Suebayasi	print_set_lists "$@" | \
2921.43Sapb	${AWK} -v obsolete=${obsolete} '
2931.9Slukem		BEGIN {
2941.52Slukem			if (obsolete)
2951.52Slukem				wanted["obsolete"] = 1
2961.52Slukem		
2971.100Suebayasi			split("'"${MKVARS}"'", needvars)
2981.52Slukem			for (vi in needvars) {
2991.52Slukem				nv = needvars[vi]
3001.52Slukem				kw = tolower(nv)
3011.52Slukem				sub(/^mk/, "", kw)
3021.143Snakayama				sub(/^have_/, "", kw)
3031.148Smatt				sub(/^target_endianness/, "endian", kw)
3041.159Smatt				if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no")
3051.52Slukem					wanted[kw] = 1 
3061.52Slukem			}
3071.52Slukem
3081.52Slukem			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
3091.90Sdyoung				if ("binutils" in wanted)
3101.90Sdyoung					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
3111.90Sdyoung				if ("gcc" in wanted)
3121.90Sdyoung					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
3131.90Sdyoung				if ("gdb" in wanted)
3141.90Sdyoung					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
3151.9Slukem			}
3161.52Slukem			if (("man" in wanted) && ("catpages" in wanted))
3171.52Slukem				wanted[".cat"] = 1
3181.52Slukem			if (("man" in wanted) && ("manpages" in wanted))
3191.52Slukem				wanted[".man"] = 1
3201.148Smatt			if ("endian" in wanted)
3211.148Smatt				wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
3221.162Smrg			if ("machine" in wanted)
3231.162Smrg				wanted["machine=" "'"${MACHINE}"'"] = 1
3241.162Smrg			if ("machine_arch" in wanted)
3251.162Smrg				wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
3261.162Smrg			if ("machine_cpu" in wanted)
3271.162Smrg				wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
3281.9Slukem		}
3291.9Slukem
3301.9Slukem		/^#/ {
3311.9Slukem			next;
3321.9Slukem		}
3331.9Slukem
3341.127Smatt		/^-/ {
3351.127Smatt			notwanted[substr($1, 2)] = 1;
3361.127Smatt			delete list [substr($1, 2)];
3371.127Smatt			next;
3381.127Smatt		}
3391.127Smatt				
3401.127Smatt
3411.9Slukem		NF > 2 && $3 != "-" {
3421.127Smatt			if (notwanted[$1] != "")
3431.127Smatt				next;
3441.9Slukem			split($3, keywords, ",")
3451.9Slukem			show = 1
3461.52Slukem			haveobs = 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.59Sjmmv				} else {
3571.59Sjmmv					if (! (kw in wanted))
3581.59Sjmmv						show = 0
3591.59Sjmmv				}
3601.52Slukem				if (kw == "obsolete")
3611.52Slukem					haveobs = 1
3621.9Slukem			}
3631.52Slukem			if (obsolete && ! haveobs)
3641.52Slukem				next
3651.9Slukem			if (show)
3661.127Smatt				list[$1] = $0
3671.9Slukem			next
3681.9Slukem		}
3691.9Slukem
3701.9Slukem		{
3711.127Smatt			if (notwanted[$1] != "")
3721.127Smatt				next;
3731.9Slukem			if (! obsolete)
3741.127Smatt				list[$1] = $0
3751.127Smatt		}
3761.127Smatt
3771.127Smatt		END {
3781.127Smatt			for (i in list) {
3791.127Smatt				print list[i]
3801.127Smatt			}
3811.9Slukem		}'
3821.9Slukem
3831.1Sdyoung}
3841.1Sdyoung
3851.1Sdyoung#
3861.1Sdyoung# list_set_lists setname
3871.1Sdyoung# 
3881.1Sdyoung# Print to stdout a list of files, one filename per line, which
3891.1Sdyoung# concatenate to create the packing list for setname. E.g.,
3901.1Sdyoung#
3911.1Sdyoung# 	.../lists/base/mi
3921.1Sdyoung# 	.../lists/base/rescue.mi
3931.1Sdyoung# 	.../lists/base/md.i386
3941.9Slukem#		[...]
3951.1Sdyoung#
3961.9Slukem# For a given setname $set, the following files may be selected from
3971.9Slukem# .../list/$set:
3981.9Slukem#	mi
3991.92Suebayasi#	mi.ext.*
4001.11Slukem#	ad.${MACHINE_ARCH}
4011.11Slukem# (or)	ad.${MACHINE_CPU}
4021.11Slukem#	ad.${MACHINE_CPU}.shl
4031.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
4041.11Slukem# (or)	md.${MACHINE}
4051.9Slukem#	stl.mi
4061.92Suebayasi#	stl.${stlib}
4071.9Slukem#	shl.mi
4081.92Suebayasi#	shl.mi.ext.*
4091.92Suebayasi#	shl.${shlib}
4101.92Suebayasi#	shl.${shlib}.ext.*
4111.77Stsutsui#	module.mi			if ${module} != no
4121.77Stsutsui#	module.${MACHINE}		if ${module} != no
4131.77Stsutsui#	module.ad.${MACHINE_ARCH}	if ${module} != no
4141.77Stsutsui# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
4151.9Slukem#	rescue.shl
4161.11Slukem#	rescue.${MACHINE}
4171.11Slukem#	rescue.ad.${MACHINE_ARCH}
4181.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
4191.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
4201.1Sdyoung#
4211.9Slukem# Environment:
4221.1Sdyoung# 	shlib
4231.1Sdyoung# 	stlib
4241.1Sdyoung#
4251.8Slukemlist_set_lists()
4261.8Slukem{
4271.1Sdyoung	setname=$1
4281.1Sdyoung
4291.111Suebayasi	list_set_lists_mi $setname
4301.113Suebayasi	list_set_lists_ad $setname
4311.111Suebayasi	list_set_lists_md $setname
4321.111Suebayasi	list_set_lists_stl $setname
4331.113Suebayasi	list_set_lists_shl $setname
4341.113Suebayasi	list_set_lists_module $setname
4351.111Suebayasi	list_set_lists_rescue $setname
4361.117Suebayasi	return 0
4371.111Suebayasi}
4381.110Suebayasi
4391.111Suebayasilist_set_lists_mi()
4401.111Suebayasi{
4411.111Suebayasi	setdir=$setsdir/lists/$1
4421.113Suebayasi	# always exist!
4431.9Slukem	echo $setdir/mi
4441.111Suebayasi}
4451.110Suebayasi
4461.111Suebayasilist_set_lists_ad()
4471.111Suebayasi{
4481.111Suebayasi	setdir=$setsdir/lists/$1
4491.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
4501.113Suebayasi	list_set_lists_common_ad $1
4511.111Suebayasi}
4521.110Suebayasi
4531.111Suebayasilist_set_lists_md()
4541.111Suebayasi{
4551.111Suebayasi	setdir=$setsdir/lists/$1
4561.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
4571.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}
4581.111Suebayasi}
4591.110Suebayasi
4601.111Suebayasilist_set_lists_stl()
4611.111Suebayasi{
4621.111Suebayasi	setdir=$setsdir/lists/$1
4631.110Suebayasi	echo_if_exist $setdir/stl.mi
4641.110Suebayasi	echo_if_exist $setdir/stl.${stlib}
4651.111Suebayasi}
4661.110Suebayasi
4671.111Suebayasilist_set_lists_shl()
4681.111Suebayasi{
4691.111Suebayasi	setdir=$setsdir/lists/$1
4701.113Suebayasi	[ "$shlib" != "no" ] || return
4711.112Suebayasi	echo_if_exist $setdir/shl.mi
4721.112Suebayasi	echo_if_exist $setdir/shl.${shlib}
4731.111Suebayasi}
4741.110Suebayasi
4751.111Suebayasilist_set_lists_module()
4761.111Suebayasi{
4771.111Suebayasi	setdir=$setsdir/lists/$1
4781.113Suebayasi	[ "$module" != "no" ] || return
4791.112Suebayasi	echo_if_exist $setdir/module.mi
4801.112Suebayasi	echo_if_exist $setdir/module.${MACHINE}
4811.113Suebayasi	# XXX module never has .shl
4821.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
4831.113Suebayasi	list_set_lists_common_ad $1 module
4841.111Suebayasi}
4851.1Sdyoung
4861.111Suebayasilist_set_lists_rescue()
4871.111Suebayasi{
4881.111Suebayasi	setdir=$setsdir/lists/$1
4891.110Suebayasi	echo_if_exist $setdir/rescue.mi
4901.110Suebayasi	echo_if_exist $setdir/rescue.${MACHINE}
4911.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
4921.113Suebayasi	list_set_lists_common_ad $1 rescue
4931.111Suebayasi}
4941.111Suebayasi
4951.113Suebayasilist_set_lists_common_ad()
4961.111Suebayasi{
4971.113Suebayasi	setdir=$setsdir/lists/$1; _prefix=$2
4981.113Suebayasi
4991.113Suebayasi	[ -n "$_prefix" ] && prefix="$_prefix".
5001.113Suebayasi
5011.113Suebayasi	# Prefer a <prefix>.ad.${MACHINE_ARCH} over a
5021.113Suebayasi	# <prefix>.ad.${MACHINE_CPU}, since the arch-
5031.112Suebayasi	# specific one will be more specific than the
5041.112Suebayasi	# cpu-specific one.
5051.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
5061.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
5071.113Suebayasi	[ "$shlib" != "no" ] && \
5081.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
5091.5Sdyoung}
5101.5Sdyoung
5111.110Suebayasiecho_if_exist()
5121.110Suebayasi{
5131.110Suebayasi	[ -f $1 ] && echo $1
5141.110Suebayasi	return $?
5151.110Suebayasi}
5161.110Suebayasi
5171.110Suebayasiecho_if_exist_foreach()
5181.110Suebayasi{
5191.110Suebayasi	local _list=$1; shift
5201.110Suebayasi	for _suffix in $@; do
5211.110Suebayasi		echo_if_exist ${_list}.${_suffix}
5221.110Suebayasi	done
5231.110Suebayasi}
5241.110Suebayasi
5251.116Suebayasiprint_set_lists()
5261.116Suebayasi{
5271.116Suebayasi	for setname; do
5281.136Schristos		list=$(list_set_lists $setname)
5291.116Suebayasi		for l in $list; do
5301.116Suebayasi			echo $l
5311.116Suebayasi			if $verbose; then
5321.116Suebayasi				echo >&2 "DEBUG: list_set_files: $l"
5331.116Suebayasi			fi
5341.116Suebayasi		done
5351.118Suebayasi	done | ${XARGS} ${SED} ${SUBST}
5361.116Suebayasi}
5371.116Suebayasi
5381.9Slukem# arch_to_cpu mach
5391.9Slukem#
5401.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
5411.9Slukem# as determined by <bsd.own.mk>.
5421.9Slukem#
5431.8Slukemarch_to_cpu()
5441.8Slukem{
5451.56Sapb	MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
5461.5Sdyoung.include <bsd.own.mk>
5471.5Sdyoungall:
5481.5Sdyoung	@echo \${MACHINE_CPU}
5491.12SlukemEOMAKE
5501.1Sdyoung}
5511.46Sapb
5521.46Sapb# arch_to_endian mach
5531.46Sapb#
5541.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
5551.46Sapb# as determined by <bsd.endian.mk>.
5561.46Sapb#
5571.46Sapbarch_to_endian()
5581.46Sapb{
5591.56Sapb	MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
5601.46Sapb.include <bsd.endian.mk>
5611.46Sapball:
5621.46Sapb	@echo \${TARGET_ENDIANNESS}
5631.46SapbEOMAKE
5641.46Sapb}
5651.117Suebayasi
5661.117Suebayasi#####
5671.117Suebayasi
5681.117Suebayasi# print_mkvars
5691.117Suebayasiprint_mkvars()
5701.117Suebayasi{
5711.117Suebayasi	for v in $MKVARS; do
5721.117Suebayasi		eval echo $v=\$$v
5731.117Suebayasi	done
5741.117Suebayasi}
5751.117Suebayasi
5761.117Suebayasi# print_set_lists_{base,x,ext}
5771.117Suebayasi# list_set_lists_{base,x,ext}
5781.117Suebayasi# list_set_files_{base,x,ext}
5791.117Suebayasifor func in print_set_lists list_set_lists list_set_files; do
5801.117Suebayasi	for x in base x ext; do
5811.117Suebayasi		if [ $x = base ]; then
5821.117Suebayasi			list=nlists
5831.117Suebayasi		else
5841.117Suebayasi			list=${x}lists
5851.117Suebayasi		fi
5861.117Suebayasi		eval ${func}_${x} \(\) \{ $func \$$list \; \}
5871.117Suebayasi	done
5881.117Suebayasidone
589