sets.subr revision 1.108
11.100Suebayasi#	$NetBSD: sets.subr,v 1.108 2009/12/10 15:51:24 uebayasi 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.11Slukem#	TOOLCHAIN_MISSING
231.11Slukem#	OBJECT_FMT
241.22Slukem# as well as:
251.22Slukem#
261.95Suebayasi
271.42Sapb#
281.42Sapb# The following variables refer to tools that are used when building sets:
291.42Sapb#
301.43Sapb: ${AWK:=awk}
311.42Sapb: ${CKSUM:=cksum}
321.43Sapb: ${COMM:=comm}
331.44Sapb: ${DATE:=date}
341.43Sapb: ${DB:=db}
351.43Sapb: ${EGREP:=egrep}
361.43Sapb: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
371.44Sapb: ${FGREP:=fgrep}
381.43Sapb: ${FIND:=find}
391.44Sapb: ${GREP:=grep}
401.43Sapb: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
411.99Sapb: ${HOSTNAME_CMD:=hostname}	# ${HOSTNAME} is special to bash(1)
421.42Sapb: ${HOST_SH:=sh}
431.43Sapb: ${IDENT:=ident}
441.43Sapb: ${JOIN:=join}
451.43Sapb: ${LS:=ls}
461.43Sapb: ${MAKE:=make}
471.42Sapb: ${MKTEMP:=mktemp}
481.43Sapb: ${MTREE:=mtree}
491.43Sapb: ${PASTE:=paste}
501.42Sapb: ${PAX:=pax}
511.43Sapb: ${PRINTF:=printf}
521.43Sapb: ${SED:=sed}
531.43Sapb: ${SORT:=sort}
541.44Sapb: ${STAT:=stat}
551.44Sapb: ${TSORT:=tsort}
561.43Sapb: ${UNAME:=uname}
571.43Sapb: ${WC:=wc}
581.43Sapb
591.45Sapb#
601.45Sapb# If printf is a shell builtin command, then we can
611.45Sapb# implement cheaper versions of basename and dirname
621.45Sapb# that do not involve any fork/exec overhead.
631.45Sapb# If printf is not builtin, approximate it using echo,
641.45Sapb# and hope there are no weird file names that cause
651.45Sapb# some versions of echo to do the wrong thing.
661.45Sapb# (Converting to this version of dirname speeded up the
671.45Sapb# syspkgdeps script by an order of magnitude, from 68
681.45Sapb# seconds to 6.3 seconds on one particular host.)
691.45Sapb#
701.45Sapb# Note that naive approximations for dirname
711.45Sapb# using ${foo%/*} do not do the right thing in cases
721.45Sapb# where the result should be "/" or ".".
731.45Sapb#
741.45Sapbcase "$(type printf)" in
751.45Sapb*builtin*)
761.45Sapb	basename ()
771.45Sapb	{
781.45Sapb		local bn
791.45Sapb		bn="${1##*/}"
801.45Sapb		bn="${bn%$2}"
811.45Sapb		printf "%s\n" "$bn"
821.45Sapb	}
831.45Sapb	dirname ()
841.45Sapb	{
851.45Sapb		local dn
861.45Sapb		case "$1" in
871.45Sapb		?*/*)	dn="${1%/*}" ;;
881.45Sapb		/*)	dn=/ ;;
891.45Sapb		*)	dn=. ;;
901.45Sapb		esac
911.45Sapb		printf "%s\n" "$dn"
921.45Sapb	}
931.45Sapb	;;
941.45Sapb*)
951.45Sapb	basename ()
961.45Sapb	{
971.45Sapb		local bn
981.45Sapb		bn="${1##*/}"
991.45Sapb		bn="${bn%$2}"
1001.45Sapb		echo "$bn"
1011.45Sapb	}
1021.45Sapb	dirname ()
1031.45Sapb	{
1041.45Sapb		local dn
1051.45Sapb		case "$1" in
1061.45Sapb		?*/*)	dn="${1%/*}" ;;
1071.45Sapb		/*)	dn=/ ;;
1081.45Sapb		*)	dn=. ;;
1091.45Sapb		esac
1101.45Sapb		echo "$dn"
1111.45Sapb	}
1121.45Sapb	;;
1131.45Sapbesac
1141.45Sapb
1151.108Suebayasi#####
1161.108Suebayasi
1171.9SlukemoIFS=$IFS
1181.9SlukemIFS="
1191.9Slukem"
1201.100Suebayasi
1211.108Suebayasifor x in $( ${MAKE} -B -f mkvars.mk mkvars ); do
1221.108Suebayasi	eval export $x
1231.9Slukemdone
1241.100Suebayasi
1251.9SlukemIFS=$oIFS
1261.9Slukem
1271.108SuebayasiMKVARS="$( ${MAKE} -B -f mkvars.mk mkvars | sed -e 's,=.*,,' | xargs )"
1281.100Suebayasi
1291.105Suebayasiif [ "$SETS_SUBR_DEBUG" = "dumpmkvars" ]; then
1301.105Suebayasi	for v in $MKVARS; do
1311.105Suebayasi		eval echo $v=\$$v
1321.105Suebayasi	done
1331.105Suebayasi	exit 0
1341.105Suebayasifi
1351.105Suebayasi
1361.105Suebayasi#####
1371.105Suebayasi
1381.34Serhsetsdir=${0%/*}
1391.9Slukemobsolete=0
1401.76Stsutsuimodule=yes
1411.91Sdyoungif [ "${MKKMOD}" = "no" ]; then
1421.91Sdyoung	module=no			# MODULEs are off.
1431.91Sdyoungelif [ "${MACHINE}" = "evbppc" ]; then
1441.76Stsutsui	module=no			# Turn off MODULEs for some ports.
1451.9Slukemfi
1461.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1471.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1481.9Slukem	shlib=elf
1491.9Slukemelse
1501.9Slukem	shlib=aout
1511.9Slukemfi
1521.9Slukemstlib=$shlib
1531.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1541.31Sjmcif [ "${MKPIC}" = "no" ]; then
1551.31Sjmc	shlib=no
1561.31Sjmcfi
1571.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1581.9Slukem	shlib=no			# Turn off shlibs for some ports.
1591.9Slukemfi
1601.86Sjnemethif [ "$module" != "no" ]; then
1611.86Sjnemeth	nlists="base comp etc games man misc modules tests text"
1621.86Sjnemethelse
1631.86Sjnemeth	nlists="base comp etc games man misc tests text"
1641.86Sjnemethfi
1651.86Sjnemethxlists="xbase xcomp xetc xfont xserver"
1661.92Suebayasiextlists="extbase extcomp extetc"
1671.9Slukem
1681.64SheOSRELEASE=`${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh`
1691.81SrmindMODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
1701.62SadSUBST="s#@MODULEDIR@#${MODULEDIR}#g"
1711.62SadSUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
1721.62SadSUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
1731.60Sad
1741.9Slukem#
1751.9Slukem# list_set_files setfile [...]
1761.1Sdyoung# 
1771.9Slukem# Produce a packing list for setfile(s).
1781.9Slukem# In each file, a record consists of a path and a System Package name,
1791.9Slukem# separated by whitespace. E.g.,
1801.9Slukem#
1811.100Suebayasi# 	# $NetBSD: sets.subr,v 1.108 2009/12/10 15:51:24 uebayasi Exp $
1821.9Slukem# 	.			base-sys-root	[keyword[,...]]
1831.9Slukem# 	./altroot		base-sys-root
1841.9Slukem# 	./bin			base-sys-root
1851.9Slukem# 	./bin/[			base-util-root
1861.9Slukem# 	./bin/cat		base-util-root
1871.9Slukem#		[...]
1881.9Slukem#
1891.9Slukem# A # in the first column marks a comment.
1901.9Slukem#
1911.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1921.52Slukem# be printed.  All other keywords must be present.
1931.9Slukem#
1941.9Slukem# The third field is an optional comma separated list of keywords to
1951.9Slukem# control if a record is printed; every keyword listed must be enabled
1961.9Slukem# for the record to be printed.  The following keywords are available:
1971.9Slukem#	dummy			dummy entry (ignored)
1981.13Slukem#	obsolete		file is obsolete, and only printed if 
1991.13Slukem#				${obsolete} != 0
2001.13Slukem#
2011.87Sskrll#	bfd			obsolete, use binutils.
2021.87Sskrll#	binutils		${MKBINUTILS} != no
2031.22Slukem#	catpages		${MKCATPAGES} != no
2041.71Smrg#	compat			${MKCOMPAT} != no
2051.22Slukem#	crypto			${MKCRYPTO} != no
2061.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
2071.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
2081.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
2091.22Slukem#	cvs			${MKCVS} != no
2101.53Slukem#	debug			${MKDEBUG} != no
2111.69Slukem#	debuglib		${MKDEBUGLIB} != no
2121.23Slukem#	doc			${MKDOC} != no
2131.67Slukem#	dynamicroot		${MKDYNAMICROOT} != no
2141.92Suebayasi#	extsrc			${MKEXTSRC} != no
2151.52Slukem#	gcc			${MKGCC} != no
2161.36Smatt#	gcccmds			${MKGCCCMDS} != no
2171.32Sscw#	gdb			${MKGDB} != no
2181.22Slukem#	hesiod			${MKHESIOD} != no
2191.68Slukem#	html			${MKHTML} != no
2201.67Slukem#	inet6			${MKINET6} != no
2211.23Slukem#	info			${MKINFO} != no
2221.39Speter#	ipfilter		${MKIPFILTER} != no
2231.51Smrg#	iscsi			${MKISCSI} != no
2241.22Slukem#	kerberos		${MKKERBEROS} != no
2251.85Sdyoung#	kmod			${MKKMOD} != no
2261.67Slukem#	ldap			${MKLDAP} != no
2271.22Slukem#	lint			${MKLINT} != no
2281.78Sagc#	lvm			${MKLVM} != no
2291.22Slukem#	man			${MKMAN} != no
2301.67Slukem#	manpages		${MKMANPAGES} != no
2311.22Slukem#	manz			${MKMANZ} != no
2321.88Stsarna#	mdns			${MKMDNS} != no
2331.23Slukem#	nls			${MKNLS} != no
2341.66Sdyoung#	nvi			${MKNVI} != no
2351.37She#	pam			${MKPAM} != no
2361.39Speter#	pf			${MKPF} != no
2371.67Slukem#	pic			${MKPIC} != no
2381.22Slukem#	postfix			${MKPOSTFIX} != no
2391.22Slukem#	profile			${MKPROFILE} != no
2401.24Slukem#	share			${MKSHARE} != no
2411.22Slukem#	skey			${MKSKEY} != no
2421.73Smrg#	x11			${MKX11} != no && ${X11FLAVOUR} != "Xorg"
2431.73Smrg#	xorg			${MKX11} != no && ${X11FLAVOUR} == "Xorg"
2441.22Slukem#	yp			${MKYP} != no
2451.89Shaad#	zfs			${MKZFS} != no
2461.22Slukem#
2471.87Sskrll#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
2481.52Slukem#	gcc=<n>			<n> = value of ${HAVE_GCC}
2491.52Slukem#	gdb=<n>			<n> = value of ${HAVE_GDB}
2501.52Slukem#
2511.41Slukem#	use_inet6		${USE_INET6} != no
2521.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2531.41Slukem#	use_yp			${USE_YP} != no
2541.41Slukem#
2551.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2561.22Slukem#				  automatically append ".gz" to the filename
2571.22Slukem#
2581.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2591.22Slukem#				  automatically append ".gz" to the filename
2601.1Sdyoung#
2611.8Slukemlist_set_files()
2621.8Slukem{
2631.83Sapb	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
2641.65She		verbose=false
2651.65She	else
2661.65She		verbose=true
2671.65She	fi
2681.1Sdyoung	for setname; do
2691.65She		list=`list_set_lists $setname`
2701.65She		for l in $list; do
2711.65She			echo $l
2721.65She			if $verbose; then
2731.82Sapb				echo >&2 "DEBUG: list_set_files: $l"
2741.65She			fi
2751.65She		done
2761.62Sad	done | xargs cat | ${SED} ${SUBST} | \
2771.43Sapb	${AWK} -v obsolete=${obsolete} '
2781.9Slukem		BEGIN {
2791.52Slukem			if (obsolete)
2801.52Slukem				wanted["obsolete"] = 1
2811.52Slukem		
2821.100Suebayasi			split("'"${MKVARS}"'", needvars)
2831.52Slukem			for (vi in needvars) {
2841.52Slukem				nv = needvars[vi]
2851.52Slukem				kw = tolower(nv)
2861.52Slukem				sub(/^mk/, "", kw)
2871.52Slukem				if (ENVIRON[nv] != "no")
2881.52Slukem					wanted[kw] = 1 
2891.52Slukem			}
2901.52Slukem
2911.52Slukem			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
2921.90Sdyoung				if ("binutils" in wanted)
2931.90Sdyoung					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
2941.90Sdyoung				if ("gcc" in wanted)
2951.90Sdyoung					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
2961.90Sdyoung				if ("gdb" in wanted)
2971.90Sdyoung					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
2981.9Slukem			}
2991.52Slukem			if (("man" in wanted) && ("catpages" in wanted))
3001.52Slukem				wanted[".cat"] = 1
3011.52Slukem			if (("man" in wanted) && ("manpages" in wanted))
3021.52Slukem				wanted[".man"] = 1
3031.9Slukem		}
3041.9Slukem
3051.9Slukem		/^#/ {
3061.9Slukem			next;
3071.9Slukem		}
3081.9Slukem
3091.9Slukem		NF > 2 && $3 != "-" {
3101.9Slukem			split($3, keywords, ",")
3111.9Slukem			show = 1
3121.52Slukem			haveobs = 0
3131.9Slukem			for (ki in keywords) {
3141.9Slukem				kw = keywords[ki]
3151.22Slukem				if (("manz" in wanted) &&
3161.22Slukem				    (kw == ".cat" || kw == ".man"))
3171.22Slukem					$1 = $1 ".gz"
3181.59Sjmmv				negated = match(kw, "! *")
3191.59Sjmmv				if (negated > 0) {
3201.59Sjmmv					kw = substr(kw, RSTART + RLENGTH)
3211.59Sjmmv					if (kw in wanted)
3221.59Sjmmv						show = 0
3231.59Sjmmv				} else {
3241.59Sjmmv					if (! (kw in wanted))
3251.59Sjmmv						show = 0
3261.59Sjmmv				}
3271.52Slukem				if (kw == "obsolete")
3281.52Slukem					haveobs = 1
3291.9Slukem			}
3301.52Slukem			if (obsolete && ! haveobs)
3311.52Slukem				next
3321.9Slukem			if (show)
3331.9Slukem				print
3341.9Slukem			next
3351.9Slukem		}
3361.9Slukem
3371.9Slukem		{
3381.9Slukem			if (! obsolete)
3391.9Slukem				print
3401.9Slukem		}'
3411.9Slukem
3421.1Sdyoung}
3431.1Sdyoung
3441.1Sdyoung#
3451.1Sdyoung# list_set_lists setname
3461.1Sdyoung# 
3471.1Sdyoung# Print to stdout a list of files, one filename per line, which
3481.1Sdyoung# concatenate to create the packing list for setname. E.g.,
3491.1Sdyoung#
3501.1Sdyoung# 	.../lists/base/mi
3511.1Sdyoung# 	.../lists/base/rescue.mi
3521.1Sdyoung# 	.../lists/base/md.i386
3531.9Slukem#		[...]
3541.1Sdyoung#
3551.9Slukem# For a given setname $set, the following files may be selected from
3561.9Slukem# .../list/$set:
3571.9Slukem#	mi
3581.92Suebayasi#	mi.ext.*
3591.11Slukem#	ad.${MACHINE_ARCH}
3601.11Slukem# (or)	ad.${MACHINE_CPU}
3611.11Slukem#	ad.${MACHINE_CPU}.shl
3621.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
3631.11Slukem# (or)	md.${MACHINE}
3641.9Slukem#	stl.mi
3651.92Suebayasi#	stl.${stlib}
3661.9Slukem#	shl.mi
3671.92Suebayasi#	shl.mi.ext.*
3681.92Suebayasi#	shl.${shlib}
3691.92Suebayasi#	shl.${shlib}.ext.*
3701.77Stsutsui#	module.mi			if ${module} != no
3711.77Stsutsui#	module.${MACHINE}		if ${module} != no
3721.77Stsutsui#	module.ad.${MACHINE_ARCH}	if ${module} != no
3731.77Stsutsui# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
3741.9Slukem#	rescue.shl
3751.11Slukem#	rescue.${MACHINE}
3761.11Slukem#	rescue.ad.${MACHINE_ARCH}
3771.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
3781.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
3791.1Sdyoung#
3801.9Slukem# Environment:
3811.1Sdyoung# 	shlib
3821.1Sdyoung# 	stlib
3831.1Sdyoung#
3841.8Slukemlist_set_lists()
3851.8Slukem{
3861.1Sdyoung	setname=$1
3871.1Sdyoung
3881.9Slukem	setdir=$setsdir/lists/$setname
3891.9Slukem	echo $setdir/mi
3901.92Suebayasi	for _extsrc_pkg in ${EXTSRCS}; do
3911.92Suebayasi		if [ -f $setdir/mi.ext.${_extsrc_pkg} ]; then
3921.92Suebayasi			echo $setdir/mi.ext.${_extsrc_pkg}
3931.92Suebayasi		fi
3941.92Suebayasi	done
3951.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3961.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
3971.1Sdyoung		# since the arch-specific one will be more specific than
3981.1Sdyoung		# the cpu-specific one.
3991.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
4001.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
4011.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
4021.11Slukem			echo $setdir/ad.${MACHINE_CPU}
4031.1Sdyoung		fi
4041.1Sdyoung		if [ "$shlib" != "no" -a \
4051.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
4061.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
4071.1Sdyoung		fi
4081.1Sdyoung	fi
4091.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
4101.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
4111.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
4121.11Slukem		echo $setdir/md.${MACHINE}
4131.1Sdyoung	fi
4141.9Slukem	if [ -f $setdir/stl.mi ]; then
4151.9Slukem		echo $setdir/stl.mi
4161.1Sdyoung	fi
4171.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
4181.9Slukem		echo $setdir/stl.${stlib}
4191.1Sdyoung	fi
4201.1Sdyoung	if [ "$shlib" != "no" ]; then
4211.9Slukem		if [ -f $setdir/shl.mi ]; then
4221.9Slukem			echo $setdir/shl.mi
4231.7Sdyoung		fi
4241.92Suebayasi		for _extsrc_pkg in ${EXTSRCS}; do
4251.92Suebayasi			if [ -f $setdir/shl.mi.ext.${_extsrc_pkg} ]; then
4261.92Suebayasi				echo $setdir/shl.mi.ext.${_extsrc_pkg}
4271.92Suebayasi			fi
4281.92Suebayasi		done
4291.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
4301.9Slukem			echo $setdir/shl.${shlib}
4311.7Sdyoung		fi
4321.92Suebayasi		for _extsrc_pkg in ${EXTSRCS}; do
4331.92Suebayasi			if [ -f $setdir/shl.${shlib}.ext.${_extsrc_pkg} ]; then
4341.92Suebayasi				echo $setdir/shl.${shlib}.ext.${_extsrc_pkg}
4351.92Suebayasi			fi
4361.92Suebayasi		done
4371.1Sdyoung	fi
4381.76Stsutsui	if [ "$module" != "no" ]; then
4391.76Stsutsui		if [ -f $setdir/module.mi ]; then
4401.76Stsutsui			echo $setdir/module.mi
4411.1Sdyoung		fi
4421.77Stsutsui		if [ -f $setdir/module.${MACHINE} ]; then
4431.77Stsutsui			echo $setdir/module.${MACHINE}
4441.77Stsutsui		fi
4451.77Stsutsui		if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
4461.77Stsutsui			# Prefer a module.ad.${MACHINE_ARCH} over a
4471.77Stsutsui			# module.ad.${MACHINE_CPU}, since the arch-
4481.77Stsutsui			# specific one will be more specific than the
4491.77Stsutsui			# cpu-specific one.
4501.77Stsutsui			if [ -f $setdir/module.ad.${MACHINE_ARCH} ]; then
4511.77Stsutsui				echo $setdir/module.ad.${MACHINE_ARCH}
4521.77Stsutsui			elif [ -f $setdir/module.ad.${MACHINE_CPU} ]; then
4531.77Stsutsui				echo $setdir/module.ad.${MACHINE_CPU}
4541.77Stsutsui			fi
4551.77Stsutsui		fi
4561.1Sdyoung	fi
4571.1Sdyoung
4581.9Slukem	if [ -f $setdir/rescue.mi ]; then
4591.9Slukem		echo $setdir/rescue.mi
4601.1Sdyoung	fi
4611.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
4621.11Slukem		echo $setdir/rescue.${MACHINE}
4631.1Sdyoung	fi
4641.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
4651.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
4661.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
4671.1Sdyoung		# specific one will be more specific than the
4681.1Sdyoung		# cpu-specific one.
4691.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
4701.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
4711.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
4721.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
4731.1Sdyoung		fi
4741.10Sjmc		if [ "$shlib" != "no" -a \
4751.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
4761.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
4771.10Sjmc		fi
4781.1Sdyoung	fi
4791.5Sdyoung}
4801.5Sdyoung
4811.9Slukem# arch_to_cpu mach
4821.9Slukem#
4831.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
4841.9Slukem# as determined by <bsd.own.mk>.
4851.9Slukem#
4861.8Slukemarch_to_cpu()
4871.8Slukem{
4881.56Sapb	MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
4891.5Sdyoung.include <bsd.own.mk>
4901.5Sdyoungall:
4911.5Sdyoung	@echo \${MACHINE_CPU}
4921.12SlukemEOMAKE
4931.1Sdyoung}
4941.46Sapb
4951.46Sapb# arch_to_endian mach
4961.46Sapb#
4971.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
4981.46Sapb# as determined by <bsd.endian.mk>.
4991.46Sapb#
5001.46Sapbarch_to_endian()
5011.46Sapb{
5021.56Sapb	MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
5031.46Sapb.include <bsd.endian.mk>
5041.46Sapball:
5051.46Sapb	@echo \${TARGET_ENDIANNESS}
5061.46SapbEOMAKE
5071.46Sapb}
508