sets.subr revision 1.177
11.177Smrg#	$NetBSD: sets.subr,v 1.177 2016/08/16 01:05:19 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.176SchristosMKVARS="$( ${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.177Smrg# 	# $NetBSD: sets.subr,v 1.177 2016/08/16 01:05:19 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.165Smatt#	compattests		${MKCOMPATTESTS} != no
2101.22Slukem#	crypto			${MKCRYPTO} != no
2111.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
2121.174Schristos#	ctf			${MKCTF} != no
2131.22Slukem#	cvs			${MKCVS} != no
2141.53Slukem#	debug			${MKDEBUG} != no
2151.69Slukem#	debuglib		${MKDEBUGLIB} != no
2161.23Slukem#	doc			${MKDOC} != no
2171.121Sdarran#	dtrace			${MKDTRACE} != no
2181.67Slukem#	dynamicroot		${MKDYNAMICROOT} != no
2191.92Suebayasi#	extsrc			${MKEXTSRC} != no
2201.52Slukem#	gcc			${MKGCC} != no
2211.36Smatt#	gcccmds			${MKGCCCMDS} != no
2221.32Sscw#	gdb			${MKGDB} != no
2231.22Slukem#	hesiod			${MKHESIOD} != no
2241.68Slukem#	html			${MKHTML} != no
2251.67Slukem#	inet6			${MKINET6} != no
2261.23Slukem#	info			${MKINFO} != no
2271.39Speter#	ipfilter		${MKIPFILTER} != no
2281.51Smrg#	iscsi			${MKISCSI} != no
2291.22Slukem#	kerberos		${MKKERBEROS} != no
2301.85Sdyoung#	kmod			${MKKMOD} != no
2311.144Sjmmv#	kyua			${MKKYUA} != no
2321.67Slukem#	ldap			${MKLDAP} != no
2331.22Slukem#	lint			${MKLINT} != no
2341.146Sjoerg#	libcxx			${MKLIBCXX} != no
2351.160Sjoerg#	libgcc_eh		${HAVE_LIBGCC_EH} != no
2361.147Sjoerg#	libstdcxx		${MKLIBSTDCXX} != no
2371.152Sjoerg#	lld			${MKLLD} != no
2381.153Sjoerg#	lldb			${MKLLDB} != no
2391.128Sjoerg#	llvm			${MKLLVM} != no
2401.78Sagc#	lvm			${MKLVM} != no
2411.135Sjoerg#	makemandb		${MKMAKEMANDB} != no
2421.22Slukem#	man			${MKMAN} != no
2431.67Slukem#	manpages		${MKMANPAGES} != no
2441.22Slukem#	manz			${MKMANZ} != no
2451.145Sjoerg#	mclinker		${MKMCLINKER} != no
2461.88Stsarna#	mdns			${MKMDNS} != no
2471.23Slukem#	nls			${MKNLS} != no
2481.66Sdyoung#	nvi			${MKNVI} != no
2491.37She#	pam			${MKPAM} != no
2501.120Splunky#	pcc			${MKPCC} != no
2511.39Speter#	pf			${MKPF} != no
2521.67Slukem#	pic			${MKPIC} != no
2531.157Stho#	picinstall		${MKPICINSTALL} != no
2541.169Smatt#	pigzgzip		${MKPIGZGZIP} != no
2551.22Slukem#	postfix			${MKPOSTFIX} != no
2561.22Slukem#	profile			${MKPROFILE} != no
2571.131Shaad#	perfuse			${MKPERFUSE} != no
2581.138Schristos#	rump			${MKRUMP} != no
2591.24Slukem#	share			${MKSHARE} != no
2601.22Slukem#	skey			${MKSKEY} != no
2611.140Salnsn#	sljit			${MKSLJIT} != no
2621.148Smatt#	softfloat		${MKSOFTFLOAT} != no
2631.174Schristos#	solaris			${MKDTRACE} != no or ${MKZFS} != no or ${MKCTF} != no
2641.143Snakayama#	ssp			${HAVE_SSP} != no
2651.139Schristos#	tpm			${MKTPM} != no
2661.173Smrg#	xorg			${MKX11} != no
2671.151Smrg#	xorg_server		${MKXORG_SERVER} != no
2681.22Slukem#	yp			${MKYP} != no
2691.89Shaad#	zfs			${MKZFS} != no
2701.22Slukem#
2711.148Smatt#	endian=<n>		<n> = value of ${TARGET_ENDIANNESS}
2721.87Sskrll#	binutils=<n>		<n> = value of ${HAVE_BINUTILS}
2731.52Slukem#	gcc=<n>			<n> = value of ${HAVE_GCC}
2741.52Slukem#	gdb=<n>			<n> = value of ${HAVE_GDB}
2751.177Smrg#	xorg_server_ver=<n>	<n> = value of ${HAVE_XORG_SERVER_VER}
2761.52Slukem#
2771.41Slukem#	use_inet6		${USE_INET6} != no
2781.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2791.41Slukem#	use_yp			${USE_YP} != no
2801.41Slukem#
2811.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2821.22Slukem#				  automatically append ".gz" to the filename
2831.22Slukem#
2841.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2851.22Slukem#				  automatically append ".gz" to the filename
2861.1Sdyoung#
2871.8Slukemlist_set_files()
2881.8Slukem{
2891.83Sapb	if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
2901.65She		verbose=false
2911.65She	else
2921.65She		verbose=true
2931.65She	fi
2941.116Suebayasi	print_set_lists "$@" | \
2951.43Sapb	${AWK} -v obsolete=${obsolete} '
2961.9Slukem		BEGIN {
2971.52Slukem			if (obsolete)
2981.52Slukem				wanted["obsolete"] = 1
2991.52Slukem		
3001.100Suebayasi			split("'"${MKVARS}"'", needvars)
3011.165Smatt			doingcompat = 0
3021.165Smatt			doingcompattests = 0
3031.165Smatt			ignoredkeywords["compatdir"] = 1
3041.165Smatt			ignoredkeywords["compatfile"] = 1
3051.165Smatt			ignoredkeywords["compattestdir"] = 1
3061.165Smatt			ignoredkeywords["compattestfile"] = 1
3071.170Smatt			ignoredkeywords["compatx11dir"] = 1
3081.170Smatt			ignoredkeywords["compatx11file"] = 1
3091.52Slukem			for (vi in needvars) {
3101.52Slukem				nv = needvars[vi]
3111.52Slukem				kw = tolower(nv)
3121.52Slukem				sub(/^mk/, "", kw)
3131.143Snakayama				sub(/^have_/, "", kw)
3141.148Smatt				sub(/^target_endianness/, "endian", kw)
3151.167Smatt				if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
3161.165Smatt					wanted[kw] = 1 
3171.167Smatt				}
3181.166Smatt			}
3191.166Smatt
3201.167Smatt			if ("compat" in wanted) {
3211.166Smatt				doingcompat = 1;
3221.166Smatt				split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
3231.166Smatt				compatdirkeywords["compatdir"] = 1
3241.166Smatt				compatfilekeywords["compatfile"] = 1
3251.166Smatt
3261.166Smatt				if (wanted["compattests"]) {
3271.165Smatt					doingcompattests = 1;
3281.165Smatt					compatdirkeywords["compattestdir"] = 1
3291.165Smatt					compatfilekeywords["compattestfile"] = 1
3301.166Smatt				}
3311.170Smatt				if (wanted["compatx11"]) {
3321.170Smatt					doingcompatx11 = 1;
3331.170Smatt					compatdirkeywords["compatx11dir"] = 1
3341.170Smatt					compatfilekeywords["compatx11file"] = 1
3351.170Smatt				}
3361.166Smatt			}
3371.166Smatt
3381.167Smatt			if (("kmod" in wanted) && ("compatmodules" in wanted)) {
3391.166Smatt				split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
3401.166Smatt				kmodpat = "./stand/" ENVIRON["MACHINE"]
3411.166Smatt				l_kmodpat = length(kmodpat)
3421.52Slukem			}
3431.52Slukem
3441.52Slukem			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
3451.90Sdyoung				if ("binutils" in wanted)
3461.90Sdyoung					wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
3471.90Sdyoung				if ("gcc" in wanted)
3481.90Sdyoung					wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
3491.90Sdyoung				if ("gdb" in wanted)
3501.90Sdyoung					wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
3511.9Slukem			}
3521.177Smrg			if ("'"${MKXORG_SERVER}"'" != "no") {
3531.177Smrg				if ("xorg_server_ver" in wanted) {
3541.177Smrg					wanted["xorg_server_ver=" "'"${HAVE_XORG_SERVER_VER}"'"] = 1
3551.177Smrg				}
3561.177Smrg			}
3571.52Slukem			if (("man" in wanted) && ("catpages" in wanted))
3581.52Slukem				wanted[".cat"] = 1
3591.52Slukem			if (("man" in wanted) && ("manpages" in wanted))
3601.52Slukem				wanted[".man"] = 1
3611.148Smatt			if ("endian" in wanted)
3621.148Smatt				wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
3631.162Smrg			if ("machine" in wanted)
3641.162Smrg				wanted["machine=" "'"${MACHINE}"'"] = 1
3651.162Smrg			if ("machine_arch" in wanted)
3661.162Smrg				wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
3671.162Smrg			if ("machine_cpu" in wanted)
3681.162Smrg				wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
3691.9Slukem		}
3701.9Slukem
3711.9Slukem		/^#/ {
3721.9Slukem			next;
3731.9Slukem		}
3741.9Slukem
3751.127Smatt		/^-/ {
3761.127Smatt			notwanted[substr($1, 2)] = 1;
3771.127Smatt			delete list [substr($1, 2)];
3781.127Smatt			next;
3791.127Smatt		}
3801.127Smatt				
3811.127Smatt
3821.9Slukem		NF > 2 && $3 != "-" {
3831.127Smatt			if (notwanted[$1] != "")
3841.127Smatt				next;
3851.9Slukem			split($3, keywords, ",")
3861.9Slukem			show = 1
3871.52Slukem			haveobs = 0
3881.167Smatt			iscompatfile = 0
3891.165Smatt			havekmod = 0
3901.165Smatt			iscompatdir = 0
3911.9Slukem			for (ki in keywords) {
3921.9Slukem				kw = keywords[ki]
3931.22Slukem				if (("manz" in wanted) &&
3941.22Slukem				    (kw == ".cat" || kw == ".man"))
3951.22Slukem					$1 = $1 ".gz"
3961.134Sjoerg				if (substr(kw, 1, 1) == "!") {
3971.134Sjoerg					kw = substr(kw, 2)
3981.59Sjmmv					if (kw in wanted)
3991.59Sjmmv						show = 0
4001.165Smatt				} else if (kw in compatdirkeywords) {
4011.165Smatt					iscompatdir = 1
4021.165Smatt				} else if (kw in compatfilekeywords) {
4031.167Smatt					iscompatfile = 1
4041.172Smatt				} else if (kw == "nocompatmodules") {
4051.172Smatt					havekmod = -1
4061.165Smatt				} else if (kw in ignoredkeywords) {
4071.165Smatt					# ignore
4081.167Smatt				} else if (! (kw in wanted)) {
4091.167Smatt					show = 0
4101.172Smatt				} else if (kw == "kmod" && havekmod == 0) {
4111.167Smatt					havekmod = 1
4121.59Sjmmv				}
4131.52Slukem				if (kw == "obsolete")
4141.52Slukem					haveobs = 1
4151.9Slukem			}
4161.52Slukem			if (obsolete && ! haveobs)
4171.52Slukem				next
4181.165Smatt			if (!show)
4191.165Smatt				next
4201.165Smatt
4211.165Smatt			list[$1] = $0
4221.172Smatt			if (havekmod > 0 && substr($1,1,l_kmodpat) == kmodpat) {
4231.165Smatt				for (d in kmodarchdirs) {
4241.165Smatt					xd = "./stand/" kmodarchdirs[d]
4251.165Smatt					xfile = xd substr($1, l_kmodpat+1)
4261.165Smatt					tmp = xd substr($0, l_kmodpat+1)
4271.165Smatt					list[xfile] = tmp;
4281.165Smatt				}
4291.165Smatt				next
4301.165Smatt			}
4311.165Smatt
4321.167Smatt			if (!doingcompat || !(iscompatfile || iscompatdir))
4331.165Smatt				next
4341.165Smatt
4351.167Smatt			if (iscompatfile) {
4361.165Smatt				emitcompat[$1] = 1;
4371.168Smatt				next
4381.168Smatt			}
4391.168Smatt			for (d in cpaths) {
4401.168Smatt				if (cpaths[d] == $1 "/")
4411.168Smatt					next
4421.165Smatt			}
4431.165Smatt			cpaths[ncpaths++] = $1 "/"
4441.165Smatt			for (d in compatarchdirs) {
4451.165Smatt				tmp = $0
4461.165Smatt				xfile = $1 "/" compatarchdirs[d]
4471.165Smatt				tmp = xfile substr(tmp, length($1) + 1)
4481.165Smatt				if (xfile in notwanted)
4491.165Smatt					continue;
4501.165Smatt				sub("compatdir","compat",tmp);
4511.165Smatt				sub("compattestdir","compat",tmp);
4521.165Smatt				list[xfile] = tmp
4531.165Smatt			}
4541.9Slukem			next
4551.9Slukem		}
4561.9Slukem
4571.9Slukem		{
4581.165Smatt			if ($1 in notwanted)
4591.127Smatt				next;
4601.9Slukem			if (! obsolete)
4611.127Smatt				list[$1] = $0
4621.127Smatt		}
4631.127Smatt
4641.127Smatt		END {
4651.127Smatt			for (i in list) {
4661.127Smatt				print list[i]
4671.165Smatt				if (! (i in emitcompat))
4681.165Smatt					continue;
4691.165Smatt				l_i = length(i)
4701.165Smatt				l = 0
4711.165Smatt				for (j in cpaths) {
4721.165Smatt					lx = length(cpaths[j])
4731.165Smatt					if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
4741.165Smatt						continue;
4751.165Smatt					}
4761.165Smatt					if (lx > l) {
4771.165Smatt						l = lx;
4781.165Smatt						cpath = cpaths[j];
4791.165Smatt					}
4801.165Smatt				}
4811.165Smatt				for (d in compatarchdirs) {
4821.165Smatt					tmp = list[i]
4831.165Smatt					extrapath = compatarchdirs[d] "/"
4841.165Smatt					xfile = cpath extrapath substr(i, l + 1)
4851.165Smatt					if (xfile in notwanted)
4861.165Smatt						continue;
4871.165Smatt					sub("compatfile","compat",tmp);
4881.165Smatt					sub("compattestfile","compat",tmp);
4891.165Smatt					tmp = xfile substr(tmp, l_i + 1)
4901.165Smatt					print tmp;
4911.165Smatt				}
4921.127Smatt			}
4931.9Slukem		}'
4941.9Slukem
4951.1Sdyoung}
4961.1Sdyoung
4971.1Sdyoung#
4981.1Sdyoung# list_set_lists setname
4991.1Sdyoung# 
5001.1Sdyoung# Print to stdout a list of files, one filename per line, which
5011.1Sdyoung# concatenate to create the packing list for setname. E.g.,
5021.1Sdyoung#
5031.1Sdyoung# 	.../lists/base/mi
5041.1Sdyoung# 	.../lists/base/rescue.mi
5051.1Sdyoung# 	.../lists/base/md.i386
5061.9Slukem#		[...]
5071.1Sdyoung#
5081.9Slukem# For a given setname $set, the following files may be selected from
5091.9Slukem# .../list/$set:
5101.9Slukem#	mi
5111.92Suebayasi#	mi.ext.*
5121.11Slukem#	ad.${MACHINE_ARCH}
5131.11Slukem# (or)	ad.${MACHINE_CPU}
5141.11Slukem#	ad.${MACHINE_CPU}.shl
5151.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
5161.11Slukem# (or)	md.${MACHINE}
5171.9Slukem#	stl.mi
5181.92Suebayasi#	stl.${stlib}
5191.9Slukem#	shl.mi
5201.92Suebayasi#	shl.mi.ext.*
5211.92Suebayasi#	shl.${shlib}
5221.92Suebayasi#	shl.${shlib}.ext.*
5231.77Stsutsui#	module.mi			if ${module} != no
5241.77Stsutsui#	module.${MACHINE}		if ${module} != no
5251.77Stsutsui#	module.ad.${MACHINE_ARCH}	if ${module} != no
5261.77Stsutsui# (or)	module.ad.${MACHINE_CPU}	if ${module} != no
5271.9Slukem#	rescue.shl
5281.11Slukem#	rescue.${MACHINE}
5291.11Slukem#	rescue.ad.${MACHINE_ARCH}
5301.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
5311.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
5321.1Sdyoung#
5331.9Slukem# Environment:
5341.1Sdyoung# 	shlib
5351.1Sdyoung# 	stlib
5361.1Sdyoung#
5371.8Slukemlist_set_lists()
5381.8Slukem{
5391.1Sdyoung	setname=$1
5401.1Sdyoung
5411.111Suebayasi	list_set_lists_mi $setname
5421.113Suebayasi	list_set_lists_ad $setname
5431.111Suebayasi	list_set_lists_md $setname
5441.111Suebayasi	list_set_lists_stl $setname
5451.113Suebayasi	list_set_lists_shl $setname
5461.113Suebayasi	list_set_lists_module $setname
5471.111Suebayasi	list_set_lists_rescue $setname
5481.117Suebayasi	return 0
5491.111Suebayasi}
5501.110Suebayasi
5511.111Suebayasilist_set_lists_mi()
5521.111Suebayasi{
5531.111Suebayasi	setdir=$setsdir/lists/$1
5541.113Suebayasi	# always exist!
5551.9Slukem	echo $setdir/mi
5561.111Suebayasi}
5571.110Suebayasi
5581.111Suebayasilist_set_lists_ad()
5591.111Suebayasi{
5601.111Suebayasi	setdir=$setsdir/lists/$1
5611.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5621.113Suebayasi	list_set_lists_common_ad $1
5631.111Suebayasi}
5641.110Suebayasi
5651.111Suebayasilist_set_lists_md()
5661.111Suebayasi{
5671.111Suebayasi	setdir=$setsdir/lists/$1
5681.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
5691.110Suebayasi	echo_if_exist $setdir/md.${MACHINE}
5701.111Suebayasi}
5711.110Suebayasi
5721.111Suebayasilist_set_lists_stl()
5731.111Suebayasi{
5741.111Suebayasi	setdir=$setsdir/lists/$1
5751.110Suebayasi	echo_if_exist $setdir/stl.mi
5761.110Suebayasi	echo_if_exist $setdir/stl.${stlib}
5771.111Suebayasi}
5781.110Suebayasi
5791.111Suebayasilist_set_lists_shl()
5801.111Suebayasi{
5811.111Suebayasi	setdir=$setsdir/lists/$1
5821.113Suebayasi	[ "$shlib" != "no" ] || return
5831.112Suebayasi	echo_if_exist $setdir/shl.mi
5841.112Suebayasi	echo_if_exist $setdir/shl.${shlib}
5851.111Suebayasi}
5861.110Suebayasi
5871.111Suebayasilist_set_lists_module()
5881.111Suebayasi{
5891.111Suebayasi	setdir=$setsdir/lists/$1
5901.113Suebayasi	[ "$module" != "no" ] || return
5911.112Suebayasi	echo_if_exist $setdir/module.mi
5921.112Suebayasi	echo_if_exist $setdir/module.${MACHINE}
5931.113Suebayasi	# XXX module never has .shl
5941.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
5951.113Suebayasi	list_set_lists_common_ad $1 module
5961.111Suebayasi}
5971.1Sdyoung
5981.111Suebayasilist_set_lists_rescue()
5991.111Suebayasi{
6001.111Suebayasi	setdir=$setsdir/lists/$1
6011.110Suebayasi	echo_if_exist $setdir/rescue.mi
6021.110Suebayasi	echo_if_exist $setdir/rescue.${MACHINE}
6031.113Suebayasi	[ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
6041.113Suebayasi	list_set_lists_common_ad $1 rescue
6051.111Suebayasi}
6061.111Suebayasi
6071.113Suebayasilist_set_lists_common_ad()
6081.111Suebayasi{
6091.113Suebayasi	setdir=$setsdir/lists/$1; _prefix=$2
6101.113Suebayasi
6111.113Suebayasi	[ -n "$_prefix" ] && prefix="$_prefix".
6121.113Suebayasi
6131.113Suebayasi	# Prefer a <prefix>.ad.${MACHINE_ARCH} over a
6141.113Suebayasi	# <prefix>.ad.${MACHINE_CPU}, since the arch-
6151.112Suebayasi	# specific one will be more specific than the
6161.112Suebayasi	# cpu-specific one.
6171.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
6181.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
6191.113Suebayasi	[ "$shlib" != "no" ] && \
6201.113Suebayasi	echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
6211.5Sdyoung}
6221.5Sdyoung
6231.110Suebayasiecho_if_exist()
6241.110Suebayasi{
6251.110Suebayasi	[ -f $1 ] && echo $1
6261.110Suebayasi	return $?
6271.110Suebayasi}
6281.110Suebayasi
6291.110Suebayasiecho_if_exist_foreach()
6301.110Suebayasi{
6311.110Suebayasi	local _list=$1; shift
6321.110Suebayasi	for _suffix in $@; do
6331.110Suebayasi		echo_if_exist ${_list}.${_suffix}
6341.110Suebayasi	done
6351.110Suebayasi}
6361.110Suebayasi
6371.116Suebayasiprint_set_lists()
6381.116Suebayasi{
6391.116Suebayasi	for setname; do
6401.136Schristos		list=$(list_set_lists $setname)
6411.116Suebayasi		for l in $list; do
6421.116Suebayasi			echo $l
6431.116Suebayasi			if $verbose; then
6441.116Suebayasi				echo >&2 "DEBUG: list_set_files: $l"
6451.116Suebayasi			fi
6461.116Suebayasi		done
6471.118Suebayasi	done | ${XARGS} ${SED} ${SUBST}
6481.116Suebayasi}
6491.116Suebayasi
6501.9Slukem# arch_to_cpu mach
6511.9Slukem#
6521.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
6531.9Slukem# as determined by <bsd.own.mk>.
6541.9Slukem#
6551.8Slukemarch_to_cpu()
6561.8Slukem{
6571.56Sapb	MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
6581.5Sdyoung.include <bsd.own.mk>
6591.5Sdyoungall:
6601.5Sdyoung	@echo \${MACHINE_CPU}
6611.12SlukemEOMAKE
6621.1Sdyoung}
6631.46Sapb
6641.46Sapb# arch_to_endian mach
6651.46Sapb#
6661.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
6671.46Sapb# as determined by <bsd.endian.mk>.
6681.46Sapb#
6691.46Sapbarch_to_endian()
6701.46Sapb{
6711.56Sapb	MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
6721.46Sapb.include <bsd.endian.mk>
6731.46Sapball:
6741.46Sapb	@echo \${TARGET_ENDIANNESS}
6751.46SapbEOMAKE
6761.46Sapb}
6771.117Suebayasi
6781.117Suebayasi#####
6791.117Suebayasi
6801.117Suebayasi# print_mkvars
6811.117Suebayasiprint_mkvars()
6821.117Suebayasi{
6831.117Suebayasi	for v in $MKVARS; do
6841.117Suebayasi		eval echo $v=\$$v
6851.117Suebayasi	done
6861.117Suebayasi}
6871.117Suebayasi
6881.117Suebayasi# print_set_lists_{base,x,ext}
6891.117Suebayasi# list_set_lists_{base,x,ext}
6901.117Suebayasi# list_set_files_{base,x,ext}
6911.117Suebayasifor func in print_set_lists list_set_lists list_set_files; do
6921.117Suebayasi	for x in base x ext; do
6931.117Suebayasi		if [ $x = base ]; then
6941.117Suebayasi			list=nlists
6951.117Suebayasi		else
6961.117Suebayasi			list=${x}lists
6971.117Suebayasi		fi
6981.117Suebayasi		eval ${func}_${x} \(\) \{ $func \$$list \; \}
6991.117Suebayasi	done
7001.117Suebayasidone
701