sets.subr revision 1.46
11.46Sapb#	$NetBSD: sets.subr,v 1.46 2006/01/08 10:25:33 apb 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.9Slukem#	obsolete		controls if obsolete files are selected instead
101.9Slukem#	lkm			if != "no", enable LKM sets
111.9Slukem#	shlib			shared library format (a.out, elf, or "")
121.9Slukem#	stlib			static library format (a.out, elf)
131.20Slukem#	x11_version		version of XFree86. one of:
141.20Slukem#				   ""	cross built from src/x11
151.20Slukem#				   3	XFree86 3.x from xsrc/xc
161.20Slukem#				   4	XFree86 4.x from xsrc/xfree/xc
171.11Slukem#
181.11Slukem# The following <bsd.own.mk> variables are exported to the environment:
191.11Slukem#	MACHINE	
201.11Slukem#	MACHINE_ARCH
211.11Slukem#	MACHINE_CPU
221.11Slukem#	HAVE_GCC3
231.11Slukem#	TOOLCHAIN_MISSING
241.11Slukem#	OBJECT_FMT
251.22Slukem# as well as:
261.22Slukem#
271.22SlukemMKVARS="\
281.22Slukem	MKBFD		\
291.22Slukem	MKCATPAGES	\
301.22Slukem	MKCRYPTO	\
311.22Slukem	MKCRYPTO_IDEA	\
321.22Slukem	MKCRYPTO_MDC2	\
331.22Slukem	MKCRYPTO_RC5	\
341.22Slukem	MKCVS		\
351.36Smatt	MKGCCCMDS	\
361.23Slukem	MKDOC		\
371.32Sscw	MKGDB		\
381.22Slukem	MKHESIOD	\
391.23Slukem	MKINFO		\
401.39Speter	MKIPFILTER	\
411.38Slukem	MKINET6		\
421.22Slukem	MKKERBEROS	\
431.22Slukem	MKKERBEROS4	\
441.22Slukem	MKLINT		\
451.22Slukem	MKMAN		\
461.33Sjmc	MKMANPAGES	\
471.22Slukem	MKMANZ		\
481.23Slukem	MKNLS		\
491.37She	MKPAM		\
501.39Speter	MKPF		\
511.30Smatt	MKPIC		\
521.22Slukem	MKPOSTFIX	\
531.22Slukem	MKPROFILE	\
541.22Slukem	MKSENDMAIL	\
551.24Slukem	MKSHARE		\
561.22Slukem	MKSKEY		\
571.25Slukem	MKUUCP		\
581.40Stron	MKX11		\
591.22Slukem	MKYP		\
601.41Slukem	USE_INET6	\
611.41Slukem	USE_KERBEROS	\
621.41Slukem	USE_YP		\
631.22Slukem"
641.42Sapb#
651.42Sapb# The following variables refer to tools that are used when building sets:
661.42Sapb#
671.43Sapb: ${AWK:=awk}
681.42Sapb: ${CKSUM:=cksum}
691.43Sapb: ${COMM:=comm}
701.44Sapb: ${DATE:=date}
711.43Sapb: ${DB:=db}
721.43Sapb: ${EGREP:=egrep}
731.43Sapb: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
741.44Sapb: ${FGREP:=fgrep}
751.43Sapb: ${FIND:=find}
761.44Sapb: ${GREP:=grep}
771.43Sapb: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
781.44Sapb: ${HOSTNAME:=hostname}
791.42Sapb: ${HOST_SH:=sh}
801.43Sapb: ${IDENT:=ident}
811.43Sapb: ${JOIN:=join}
821.43Sapb: ${LS:=ls}
831.43Sapb: ${MAKE:=make}
841.42Sapb: ${MKTEMP:=mktemp}
851.43Sapb: ${MTREE:=mtree}
861.43Sapb: ${PASTE:=paste}
871.42Sapb: ${PAX:=pax}
881.43Sapb: ${PKG_CREATE:=pkg_create}
891.43Sapb: ${PRINTF:=printf}
901.43Sapb: ${SED:=sed}
911.43Sapb: ${SORT:=sort}
921.44Sapb: ${STAT:=stat}
931.44Sapb: ${TSORT:=tsort}
941.43Sapb: ${UNAME:=uname}
951.43Sapb: ${WC:=wc}
961.43Sapb
971.45Sapb#
981.45Sapb# If printf is a shell builtin command, then we can
991.45Sapb# implement cheaper versions of basename and dirname
1001.45Sapb# that do not involve any fork/exec overhead.
1011.45Sapb# If printf is not builtin, approximate it using echo,
1021.45Sapb# and hope there are no weird file names that cause
1031.45Sapb# some versions of echo to do the wrong thing.
1041.45Sapb# (Converting to this version of dirname speeded up the
1051.45Sapb# syspkgdeps script by an order of magnitude, from 68
1061.45Sapb# seconds to 6.3 seconds on one particular host.)
1071.45Sapb#
1081.45Sapb# Note that naive approximations for dirname
1091.45Sapb# using ${foo%/*} do not do the right thing in cases
1101.45Sapb# where the result should be "/" or ".".
1111.45Sapb#
1121.45Sapbcase "$(type printf)" in
1131.45Sapb*builtin*)
1141.45Sapb	basename ()
1151.45Sapb	{
1161.45Sapb		local bn
1171.45Sapb		bn="${1##*/}"
1181.45Sapb		bn="${bn%$2}"
1191.45Sapb		printf "%s\n" "$bn"
1201.45Sapb	}
1211.45Sapb	dirname ()
1221.45Sapb	{
1231.45Sapb		local dn
1241.45Sapb		case "$1" in
1251.45Sapb		?*/*)	dn="${1%/*}" ;;
1261.45Sapb		/*)	dn=/ ;;
1271.45Sapb		*)	dn=. ;;
1281.45Sapb		esac
1291.45Sapb		printf "%s\n" "$dn"
1301.45Sapb	}
1311.45Sapb	;;
1321.45Sapb*)
1331.45Sapb	basename ()
1341.45Sapb	{
1351.45Sapb		local bn
1361.45Sapb		bn="${1##*/}"
1371.45Sapb		bn="${bn%$2}"
1381.45Sapb		echo "$bn"
1391.45Sapb	}
1401.45Sapb	dirname ()
1411.45Sapb	{
1421.45Sapb		local dn
1431.45Sapb		case "$1" in
1441.45Sapb		?*/*)	dn="${1%/*}" ;;
1451.45Sapb		/*)	dn=/ ;;
1461.45Sapb		*)	dn=. ;;
1471.45Sapb		esac
1481.45Sapb		echo "$dn"
1491.45Sapb	}
1501.45Sapb	;;
1511.45Sapbesac
1521.45Sapb
1531.9SlukemoIFS=$IFS
1541.9SlukemIFS="
1551.9Slukem"
1561.9Slukemfor x in $(
1571.43Sapb${MAKE} -B -f- all <<EOMAKE
1581.9Slukem.include <bsd.own.mk>
1591.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
1601.33SjmcMKMANPAGES=no
1611.33Sjmc.else
1621.33SjmcMKMANPAGES=yes
1631.33Sjmc.endif
1641.9Slukemall:
1651.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
1661.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
1671.12Slukem		${MKVARS}
1681.12Slukem	@echo "export \$i=\${\$i}"
1691.11Slukem.endfor
1701.20Slukem.if (\${MKX11:Uno} != "no")
1711.20Slukem	@echo x11_version=""
1721.35Stron.else
1731.9Slukem	@echo x11_version=4
1741.9Slukem.endif
1751.9Slukem
1761.12SlukemEOMAKE
1771.9Slukem); do
1781.11Slukem#	echo 1>&2 "DEBUG: read $x"
1791.9Slukem	eval $x
1801.9Slukemdone
1811.9SlukemIFS=$oIFS
1821.9Slukem
1831.34Serhsetsdir=${0%/*}
1841.9Slukemnlists="base comp etc games man misc text"
1851.9Slukemcase $x11_version in
1861.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
1871.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
1881.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
1891.20Slukem*)	xlists="" ;;	# unknown!
1901.9Slukemesac
1911.9Slukemobsolete=0
1921.9Slukemlkm=yes
1931.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
1941.9Slukem	lkm=no				# Turn off LKMs for some ports.
1951.9Slukemfi
1961.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1971.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1981.9Slukem	shlib=elf
1991.9Slukemelse
2001.9Slukem	shlib=aout
2011.9Slukemfi
2021.9Slukemstlib=$shlib
2031.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
2041.31Sjmcif [ "${MKPIC}" = "no" ]; then
2051.31Sjmc	shlib=no
2061.31Sjmcfi
2071.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
2081.9Slukem	shlib=no			# Turn off shlibs for some ports.
2091.9Slukemfi
2101.9Slukem
2111.9Slukem#
2121.9Slukem# list_set_files setfile [...]
2131.1Sdyoung# 
2141.9Slukem# Produce a packing list for setfile(s).
2151.9Slukem# In each file, a record consists of a path and a System Package name,
2161.9Slukem# separated by whitespace. E.g.,
2171.9Slukem#
2181.46Sapb# 	# $NetBSD: sets.subr,v 1.46 2006/01/08 10:25:33 apb Exp $
2191.9Slukem# 	.			base-sys-root	[keyword[,...]]
2201.9Slukem# 	./altroot		base-sys-root
2211.9Slukem# 	./bin			base-sys-root
2221.9Slukem# 	./bin/[			base-util-root
2231.9Slukem# 	./bin/cat		base-util-root
2241.9Slukem#		[...]
2251.9Slukem#
2261.9Slukem# A # in the first column marks a comment.
2271.9Slukem#
2281.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
2291.9Slukem# be printed.
2301.9Slukem#
2311.9Slukem# The third field is an optional comma separated list of keywords to
2321.9Slukem# control if a record is printed; every keyword listed must be enabled
2331.9Slukem# for the record to be printed.  The following keywords are available:
2341.9Slukem#	dummy			dummy entry (ignored)
2351.13Slukem#	obsolete		file is obsolete, and only printed if 
2361.13Slukem#				${obsolete} != 0
2371.13Slukem#
2381.22Slukem#	bfd			${MKBFD} != no
2391.22Slukem#	catpages		${MKCATPAGES} != no
2401.22Slukem#	crypto			${MKCRYPTO} != no
2411.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
2421.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
2431.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
2441.22Slukem#	cvs			${MKCVS} != no
2451.23Slukem#	doc			${MKDOC} != no
2461.36Smatt#	gcccmds			${MKGCCCMDS} != no
2471.32Sscw#	gdb			${MKGDB} != no
2481.22Slukem#	hesiod			${MKHESIOD} != no
2491.23Slukem#	info			${MKINFO} != no
2501.39Speter#	ipfilter		${MKIPFILTER} != no
2511.38Slukem#	inet6			${MKINET6} != no
2521.22Slukem#	kerberos		${MKKERBEROS} != no
2531.22Slukem#	kerberos4		${MKKERBEROS4} != no
2541.22Slukem#	lint			${MKLINT} != no
2551.22Slukem#	man			${MKMAN} != no
2561.22Slukem#	manz			${MKMANZ} != no
2571.23Slukem#	nls			${MKNLS} != no
2581.37She#	pam			${MKPAM} != no
2591.39Speter#	pf			${MKPF} != no
2601.22Slukem#	postfix			${MKPOSTFIX} != no
2611.22Slukem#	profile			${MKPROFILE} != no
2621.22Slukem#	sendmail		${MKSENDMAIL} != no
2631.24Slukem#	share			${MKSHARE} != no
2641.22Slukem#	skey			${MKSKEY} != no
2651.25Slukem#	uucp			${MKUUCP} != no
2661.22Slukem#	yp			${MKYP} != no
2671.22Slukem#
2681.41Slukem#	use_inet6		${USE_INET6} != no
2691.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2701.41Slukem#	use_yp			${USE_YP} != no
2711.41Slukem#
2721.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2731.22Slukem#				  automatically append ".gz" to the filename
2741.22Slukem#
2751.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2761.22Slukem#				  automatically append ".gz" to the filename
2771.1Sdyoung#
2781.8Slukemlist_set_files()
2791.8Slukem{
2801.1Sdyoung	for setname; do
2811.1Sdyoung		list_set_lists $setname
2821.9Slukem	done | xargs cat | \
2831.43Sapb	${AWK} -v obsolete=${obsolete} '
2841.9Slukem		BEGIN {
2851.9Slukem			if (! obsolete) {
2861.12Slukem				split("'"${MKVARS}"'", needvars)
2871.9Slukem				for (vi in needvars) {
2881.9Slukem					nv = needvars[vi]
2891.41Slukem					kw = tolower(nv)
2901.41Slukem					sub(/^mk/, "", kw)
2911.12Slukem					if (ENVIRON[nv] != "no")
2921.12Slukem						wanted[kw] = 1 
2931.9Slukem				}
2941.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
2951.22Slukem					wanted[".cat"] = 1
2961.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
2971.22Slukem					wanted[".man"] = 1
2981.9Slukem			}
2991.9Slukem		}
3001.9Slukem
3011.9Slukem		/^#/ {
3021.9Slukem			next;
3031.9Slukem		}
3041.9Slukem
3051.9Slukem		NF > 2 && $3 != "-" {
3061.9Slukem			split($3, keywords, ",")
3071.9Slukem			show = 1
3081.9Slukem			for (ki in keywords) {
3091.9Slukem				kw = keywords[ki]
3101.9Slukem				if (kw == "obsolete") {
3111.9Slukem					if (obsolete)
3121.9Slukem						print
3131.9Slukem					next
3141.9Slukem				}
3151.22Slukem				if (("manz" in wanted) &&
3161.22Slukem				    (kw == ".cat" || kw == ".man"))
3171.22Slukem					$1 = $1 ".gz"
3181.9Slukem				if (! (kw in wanted))
3191.9Slukem					show = 0
3201.9Slukem			}
3211.9Slukem			if (show)
3221.9Slukem				print
3231.9Slukem			next
3241.9Slukem		}
3251.9Slukem
3261.9Slukem		{
3271.9Slukem			if (! obsolete)
3281.9Slukem				print
3291.9Slukem		}'
3301.9Slukem
3311.1Sdyoung}
3321.1Sdyoung
3331.1Sdyoung#
3341.1Sdyoung# list_set_lists setname
3351.1Sdyoung# 
3361.1Sdyoung# Print to stdout a list of files, one filename per line, which
3371.1Sdyoung# concatenate to create the packing list for setname. E.g.,
3381.1Sdyoung#
3391.1Sdyoung# 	.../lists/base/mi
3401.1Sdyoung# 	.../lists/base/rescue.mi
3411.1Sdyoung# 	.../lists/base/md.i386
3421.9Slukem#		[...]
3431.1Sdyoung#
3441.9Slukem# For a given setname $set, the following files may be selected from
3451.9Slukem# .../list/$set:
3461.9Slukem#	mi
3471.11Slukem#	ad.${MACHINE_ARCH}
3481.11Slukem# (or)	ad.${MACHINE_CPU}
3491.11Slukem#	ad.${MACHINE_CPU}.shl
3501.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
3511.11Slukem# (or)	md.${MACHINE}
3521.9Slukem#	stl.mi
3531.9Slukem#	stl.stlib
3541.9Slukem#	shl.mi
3551.9Slukem#	shl.shlib
3561.9Slukem#	lkm.mi			if ${lkm} != no
3571.9Slukem#	gcc.mi
3581.9Slukem#	gcc.shl
3591.9Slukem#	tc.mi
3601.9Slukem#	tc.shl
3611.9Slukem#	rescue.shl
3621.11Slukem#	rescue.${MACHINE}
3631.11Slukem#	rescue.ad.${MACHINE_ARCH}
3641.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
3651.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
3661.1Sdyoung#
3671.9Slukem# Environment:
3681.1Sdyoung# 	shlib
3691.1Sdyoung# 	stlib
3701.1Sdyoung#
3711.8Slukemlist_set_lists()
3721.8Slukem{
3731.1Sdyoung	setname=$1
3741.1Sdyoung
3751.9Slukem	setdir=$setsdir/lists/$setname
3761.9Slukem	echo $setdir/mi
3771.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3781.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
3791.1Sdyoung		# since the arch-specific one will be more specific than
3801.1Sdyoung		# the cpu-specific one.
3811.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
3821.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
3831.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
3841.11Slukem			echo $setdir/ad.${MACHINE_CPU}
3851.1Sdyoung		fi
3861.1Sdyoung		if [ "$shlib" != "no" -a \
3871.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
3881.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
3891.1Sdyoung		fi
3901.1Sdyoung	fi
3911.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
3921.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
3931.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
3941.11Slukem		echo $setdir/md.${MACHINE}
3951.1Sdyoung	fi
3961.9Slukem	if [ -f $setdir/stl.mi ]; then
3971.9Slukem		echo $setdir/stl.mi
3981.1Sdyoung	fi
3991.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
4001.9Slukem		echo $setdir/stl.${stlib}
4011.1Sdyoung	fi
4021.1Sdyoung	if [ "$shlib" != "no" ]; then
4031.9Slukem		if [ -f $setdir/shl.mi ]; then
4041.9Slukem			echo $setdir/shl.mi
4051.7Sdyoung		fi
4061.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
4071.9Slukem			echo $setdir/shl.${shlib}
4081.7Sdyoung		fi
4091.1Sdyoung	fi
4101.1Sdyoung	if [ "$lkm" != "no" ]; then
4111.9Slukem		if [ -f $setdir/lkm.mi ]; then
4121.9Slukem			echo $setdir/lkm.mi
4131.1Sdyoung		fi
4141.1Sdyoung	fi
4151.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
4161.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
4171.9Slukem			if [ -f $setdir/gcc.mi ]; then
4181.9Slukem				echo $setdir/gcc.mi
4191.2Smrg			fi
4201.2Smrg			if [ "$shlib" != "no" ]; then
4211.9Slukem				if [ -f $setdir/gcc.shl ]; then
4221.9Slukem					echo $setdir/gcc.shl
4231.2Smrg				fi
4241.2Smrg			fi
4251.2Smrg		else
4261.9Slukem			if [ -f $setdir/tc.mi ]; then
4271.9Slukem				echo $setdir/tc.mi
4281.2Smrg			fi
4291.2Smrg			if [ "$shlib" != "no" ]; then
4301.9Slukem				if [ -f $setdir/tc.shl ]; then
4311.9Slukem					echo $setdir/tc.shl
4321.2Smrg				fi
4331.1Sdyoung			fi
4341.1Sdyoung		fi
4351.1Sdyoung	fi
4361.1Sdyoung
4371.9Slukem	if [ -f $setdir/rescue.mi ]; then
4381.9Slukem		echo $setdir/rescue.mi
4391.1Sdyoung	fi
4401.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
4411.11Slukem		echo $setdir/rescue.${MACHINE}
4421.1Sdyoung	fi
4431.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
4441.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
4451.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
4461.1Sdyoung		# specific one will be more specific than the
4471.1Sdyoung		# cpu-specific one.
4481.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
4491.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
4501.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
4511.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
4521.1Sdyoung		fi
4531.10Sjmc		if [ "$shlib" != "no" -a \
4541.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
4551.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
4561.10Sjmc		fi
4571.1Sdyoung	fi
4581.5Sdyoung}
4591.5Sdyoung
4601.9Slukem# arch_to_cpu mach
4611.9Slukem#
4621.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
4631.9Slukem# as determined by <bsd.own.mk>.
4641.9Slukem#
4651.8Slukemarch_to_cpu()
4661.8Slukem{
4671.43Sapb	MACHINE_ARCH=${1} ${MAKE} -f- all <<EOMAKE
4681.5Sdyoung.include <bsd.own.mk>
4691.5Sdyoungall:
4701.5Sdyoung	@echo \${MACHINE_CPU}
4711.12SlukemEOMAKE
4721.1Sdyoung}
4731.46Sapb
4741.46Sapb# arch_to_endian mach
4751.46Sapb#
4761.46Sapb# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
4771.46Sapb# as determined by <bsd.endian.mk>.
4781.46Sapb#
4791.46Sapbarch_to_endian()
4801.46Sapb{
4811.46Sapb	MACHINE_ARCH=${1} ${MAKE} -f- all <<EOMAKE
4821.46Sapb.include <bsd.endian.mk>
4831.46Sapball:
4841.46Sapb	@echo \${TARGET_ENDIANNESS}
4851.46SapbEOMAKE
4861.46Sapb}
487