sets.subr revision 1.10
11.10Sjmc#	$NetBSD: sets.subr,v 1.10 2003/12/29 20:54:58 jmc Exp $
21.1Sdyoung#
31.9Slukem
41.9Slukem#
51.9Slukem# Set environment variables containing defaults for sets.subr
61.9Slukem# functions and callers:
71.9Slukem#	setsdir			path to src/distrib/sets
81.9Slukem#	nlists			list of base sets
91.9Slukem#	xlists			list of x11 sets
101.9Slukem#	obsolete		controls if obsolete files are selected instead
111.9Slukem#	have_gcc3		<bsd.own.mk> ${HAVE_GCC3}
121.9Slukem#	lkm			if != "no", enable LKM sets
131.9Slukem#	machine			<bsd.own.mk> ${MACHINE}
141.9Slukem#	machine_arch		<bsd.own.mk> ${MACHINE_ARCH}
151.9Slukem#	machine_cpu		<bsd.own.mk> ${MACHINE_CPU}
161.9Slukem#	mkkerberos		<bsd.own.mk> ${MKKERBEROS}
171.9Slukem#	mkkerberos4		<bsd.own.mk> ${MKKERBEROS4}
181.9Slukem#	mklint			<bsd.own.mk> ${MKLINT}
191.9Slukem#	object_fmt		<bsd.own.mk> ${OBJECT_FMT}
201.9Slukem#	shlib			shared library format (a.out, elf, or "")
211.9Slukem#	stlib			static library format (a.out, elf)
221.9Slukem#	toolchain_missing	<bsd.own.mk> ${TOOLCHAIN_MISSING}
231.9Slukem#	use_tools_toolchain	<bsd.own.mk> ${USE_TOOLS_TOOLCHAIN}
241.9Slukem#	x11_version		version of XF86 (3 or 4)
251.9Slukem
261.9SlukemoIFS=$IFS
271.9SlukemIFS="
281.9Slukem"
291.9Slukemfor x in $(
301.9Slukem${MAKE:-make} -B -f- all <<EOF
311.9Slukem.include <bsd.own.mk>
321.9Slukemall:
331.9Slukem	@echo have_gcc3=\${HAVE_GCC3}
341.9Slukem	@echo machine=\${MACHINE}
351.9Slukem	@echo machine_arch=\${MACHINE_ARCH}
361.9Slukem	@echo machine_cpu=\${MACHINE_CPU}
371.9Slukem	@echo mkkerberos4=\${MKKERBEROS4}
381.9Slukem	@echo mkkerberos=\${MKKERBEROS}
391.9Slukem	@echo mklint=\${MKLINT}
401.9Slukem	@echo object_fmt=\${OBJECT_FMT}
411.9Slukem	@echo toolchain_missing=\${TOOLCHAIN_MISSING}
421.9Slukem	@echo use_tools_toolchain=\${USE_TOOLS_TOOLCHAIN}
431.9Slukem.if defined(USE_XF86_4) && (\${USE_XF86_4} != no)
441.9Slukem	@echo x11_version=4
451.9Slukem.else
461.9Slukem	@echo x11_version=3
471.9Slukem.endif
481.9Slukem
491.9SlukemEOF
501.9Slukem); do
511.9Slukem	eval $x
521.9Slukemdone
531.9SlukemIFS=$oIFS
541.9Slukem
551.9Slukemsetsdir=$(dirname $0)
561.9Slukemnlists="base comp etc games man misc text"
571.9Slukemcase $x11_version in
581.9Slukem3) xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
591.9Slukem4) xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
601.9Slukem*) xlists="xbase xcomp xcontrib xfont xmisc xserver" ;;
611.9Slukemesac
621.9Slukemobsolete=0
631.9Slukemlkm=yes
641.9Slukemif [ "$machine" = "evbppc" ]; then
651.9Slukem	lkm=no				# Turn off LKMs for some ports.
661.9Slukemfi
671.9Slukem# Determine lib type.
681.9Slukemif [ "$object_fmt" = "ELF" ]; then
691.9Slukem	shlib=elf
701.9Slukemelse
711.9Slukem	shlib=aout
721.9Slukemfi
731.9Slukemstlib=$shlib
741.9Slukemif [ "$machine_cpu" = "sh3" -o "$machine_arch" = "m68000" ]; then
751.9Slukem	shlib=no			# Turn off shlibs for some ports.
761.9Slukemfi
771.9Slukem
781.9Slukem
791.9Slukem#
801.9Slukem# list_set_files setfile [...]
811.1Sdyoung# 
821.9Slukem# Produce a packing list for setfile(s).
831.9Slukem# In each file, a record consists of a path and a System Package name,
841.9Slukem# separated by whitespace. E.g.,
851.9Slukem#
861.10Sjmc# 	# $NetBSD: sets.subr,v 1.10 2003/12/29 20:54:58 jmc Exp $
871.9Slukem# 	.			base-sys-root	[keyword[,...]]
881.9Slukem# 	./altroot		base-sys-root
891.9Slukem# 	./bin			base-sys-root
901.9Slukem# 	./bin/[			base-util-root
911.9Slukem# 	./bin/cat		base-util-root
921.9Slukem#		[...]
931.9Slukem#
941.9Slukem# A # in the first column marks a comment.
951.9Slukem#
961.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
971.9Slukem# be printed.
981.9Slukem#
991.9Slukem# The third field is an optional comma separated list of keywords to
1001.9Slukem# control if a record is printed; every keyword listed must be enabled
1011.9Slukem# for the record to be printed.  The following keywords are available:
1021.9Slukem#	dummy			dummy entry (ignored)
1031.9Slukem#	kerberos4		<bsd.own.mk> ${MKKERBEROS4} != no
1041.9Slukem#	kerberos		<bsd.own.mk> ${MKKERBEROS} != no
1051.9Slukem#	lint			<bsd.own.mk> ${MKLINT} != no
1061.9Slukem#	obsolete		file is obsolete, and only printed if 
1071.9Slukem#				${obsolete} != 0
1081.1Sdyoung#
1091.8Slukemlist_set_files()
1101.8Slukem{
1111.1Sdyoung	for setname; do
1121.1Sdyoung		list_set_lists $setname
1131.9Slukem	done | xargs cat | \
1141.9Slukem	env \
1151.9Slukem	    MKKERBEROS4=${mkkerberos4} \
1161.9Slukem	    MKKERBEROS=${mkkerberos} \
1171.9Slukem	    MKLINT=${mklint} \
1181.9Slukem	    awk -v obsolete=${obsolete} '
1191.9Slukem		BEGIN {
1201.9Slukem			if (! obsolete) {
1211.9Slukem				split("kerberos4 kerberos lint",
1221.9Slukem				    needvars)
1231.9Slukem				for (vi in needvars) {
1241.9Slukem					nv = needvars[vi]
1251.9Slukem					if (ENVIRON["MK" toupper(nv)] != "no")
1261.9Slukem						wanted[nv] = 1 
1271.9Slukem				}
1281.9Slukem			}
1291.9Slukem		}
1301.9Slukem
1311.9Slukem		/^#/ {
1321.9Slukem			next;
1331.9Slukem		}
1341.9Slukem
1351.9Slukem		NF > 2 && $3 != "-" {
1361.9Slukem			split($3, keywords, ",")
1371.9Slukem			show = 1
1381.9Slukem			for (ki in keywords) {
1391.9Slukem				kw = keywords[ki]
1401.9Slukem				if (kw == "obsolete") {
1411.9Slukem					if (obsolete)
1421.9Slukem						print
1431.9Slukem					next
1441.9Slukem				}
1451.9Slukem				if (! (kw in wanted))
1461.9Slukem					show = 0
1471.9Slukem			}
1481.9Slukem			if (show)
1491.9Slukem				print
1501.9Slukem			next
1511.9Slukem		}
1521.9Slukem
1531.9Slukem		{
1541.9Slukem			if (! obsolete)
1551.9Slukem				print
1561.9Slukem		}'
1571.9Slukem
1581.1Sdyoung}
1591.1Sdyoung
1601.1Sdyoung#
1611.1Sdyoung# list_set_lists setname
1621.1Sdyoung# 
1631.1Sdyoung# Print to stdout a list of files, one filename per line, which
1641.1Sdyoung# concatenate to create the packing list for setname. E.g.,
1651.1Sdyoung#
1661.1Sdyoung# 	.../lists/base/mi
1671.1Sdyoung# 	.../lists/base/rescue.mi
1681.1Sdyoung# 	.../lists/base/md.i386
1691.9Slukem#		[...]
1701.1Sdyoung#
1711.9Slukem# For a given setname $set, the following files may be selected from
1721.9Slukem# .../list/$set:
1731.9Slukem#	mi
1741.9Slukem#	ad.${machine_arch}
1751.9Slukem# (or)	ad.${machine_cpu}
1761.9Slukem#	ad.${machine_cpu}.shl
1771.9Slukem#	md.${machine}.${machine_arch}
1781.9Slukem# (or)	md.${machine}
1791.9Slukem#	stl.mi
1801.9Slukem#	stl.stlib
1811.9Slukem#	shl.mi
1821.9Slukem#	shl.shlib
1831.9Slukem#	lkm.mi			if ${lkm} != no
1841.9Slukem#	gcc.mi
1851.9Slukem#	gcc.shl
1861.9Slukem#	tc.mi
1871.9Slukem#	tc.shl
1881.9Slukem#	rescue.shl
1891.9Slukem#	rescue.${machine}
1901.9Slukem#	rescue.ad.${machine_arch}
1911.9Slukem# (or)	rescue.ad.${machine_cpu}
1921.10Sjmc# 	rescue.ad.${machine_cpu}.shl
1931.1Sdyoung#
1941.9Slukem# Environment:
1951.1Sdyoung# 	shlib
1961.1Sdyoung# 	stlib
1971.1Sdyoung#
1981.8Slukemlist_set_lists()
1991.8Slukem{
2001.1Sdyoung	setname=$1
2011.1Sdyoung
2021.9Slukem	setdir=$setsdir/lists/$setname
2031.9Slukem	echo $setdir/mi
2041.1Sdyoung	if [ "$machine" != "$machine_arch" ]; then
2051.1Sdyoung		# Prefer an ad.${machine_arch} over an ad.${machine_cpu},
2061.1Sdyoung		# since the arch-specific one will be more specific than
2071.1Sdyoung		# the cpu-specific one.
2081.9Slukem		if [ -f $setdir/ad.${machine_arch} ]; then
2091.9Slukem			echo $setdir/ad.${machine_arch}
2101.9Slukem		elif [ -f $setdir/ad.${machine_cpu} ]; then
2111.9Slukem			echo $setdir/ad.${machine_cpu}
2121.1Sdyoung		fi
2131.1Sdyoung		if [ "$shlib" != "no" -a \
2141.9Slukem		     -f $setdir/ad.${machine_cpu}.shl ]; then
2151.9Slukem			echo $setdir/ad.${machine_cpu}.shl
2161.1Sdyoung		fi
2171.1Sdyoung	fi
2181.9Slukem	if [ -f $setdir/md.${machine}.${machine_arch} ]; then
2191.9Slukem		echo $setdir/md.${machine}.${machine_arch}
2201.9Slukem	elif [ -f $setdir/md.${machine} ]; then
2211.9Slukem		echo $setdir/md.${machine}
2221.1Sdyoung	fi
2231.9Slukem	if [ -f $setdir/stl.mi ]; then
2241.9Slukem		echo $setdir/stl.mi
2251.1Sdyoung	fi
2261.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
2271.9Slukem		echo $setdir/stl.${stlib}
2281.1Sdyoung	fi
2291.1Sdyoung	if [ "$shlib" != "no" ]; then
2301.9Slukem		if [ -f $setdir/shl.mi ]; then
2311.9Slukem			echo $setdir/shl.mi
2321.7Sdyoung		fi
2331.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
2341.9Slukem			echo $setdir/shl.${shlib}
2351.7Sdyoung		fi
2361.1Sdyoung	fi
2371.1Sdyoung	if [ "$lkm" != "no" ]; then
2381.9Slukem		if [ -f $setdir/lkm.mi ]; then
2391.9Slukem			echo $setdir/lkm.mi
2401.1Sdyoung		fi
2411.1Sdyoung	fi
2421.1Sdyoung	if [ "$toolchain_missing" != "yes" ]; then
2431.6Stsutsui		if [ "$have_gcc3" = "yes" ]; then
2441.9Slukem			if [ -f $setdir/gcc.mi ]; then
2451.9Slukem				echo $setdir/gcc.mi
2461.2Smrg			fi
2471.2Smrg			if [ "$shlib" != "no" ]; then
2481.9Slukem				if [ -f $setdir/gcc.shl ]; then
2491.9Slukem					echo $setdir/gcc.shl
2501.2Smrg				fi
2511.2Smrg			fi
2521.2Smrg		else
2531.9Slukem			if [ -f $setdir/tc.mi ]; then
2541.9Slukem				echo $setdir/tc.mi
2551.2Smrg			fi
2561.2Smrg			if [ "$shlib" != "no" ]; then
2571.9Slukem				if [ -f $setdir/tc.shl ]; then
2581.9Slukem					echo $setdir/tc.shl
2591.2Smrg				fi
2601.1Sdyoung			fi
2611.1Sdyoung		fi
2621.1Sdyoung	fi
2631.1Sdyoung
2641.9Slukem	if [ -f $setdir/rescue.mi ]; then
2651.9Slukem		echo $setdir/rescue.mi
2661.1Sdyoung	fi
2671.9Slukem	if [ -f $setdir/rescue.${machine} ]; then
2681.9Slukem		echo $setdir/rescue.${machine}
2691.1Sdyoung	fi
2701.1Sdyoung	if [ "$machine" != "$machine_arch" ]; then
2711.1Sdyoung		# Prefer a rescue.ad.${machine_arch} over a
2721.1Sdyoung		# rescue.ad.${machine_cpu}, since the arch-
2731.1Sdyoung		# specific one will be more specific than the
2741.1Sdyoung		# cpu-specific one.
2751.9Slukem		if [ -f $setdir/rescue.ad.${machine_arch} ]; then
2761.9Slukem			echo $setdir/rescue.ad.${machine_arch}
2771.9Slukem		elif [ -f $setdir/rescue.ad.${machine_cpu} ]; then
2781.9Slukem			echo $setdir/rescue.ad.${machine_cpu}
2791.1Sdyoung		fi
2801.10Sjmc		if [ "$shlib" != "no" -a \
2811.10Sjmc		     -f $setdir/rescue.ad.${machine_cpu}.shl ]; then
2821.10Sjmc			echo $setdir/rescue.ad.${machine_cpu}.shl
2831.10Sjmc		fi
2841.1Sdyoung	fi
2851.5Sdyoung}
2861.5Sdyoung
2871.9Slukem# arch_to_cpu mach
2881.9Slukem#
2891.9Slukem# Print the $MACHINE_CPU for $MACHINE_ARCH=mach,
2901.9Slukem# as determined by <bsd.own.mk>.
2911.9Slukem#
2921.8Slukemarch_to_cpu()
2931.8Slukem{
2941.9Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOF
2951.5Sdyoung.include <bsd.own.mk>
2961.5Sdyoungall:
2971.5Sdyoung	@echo \${MACHINE_CPU}
2981.5SdyoungEOF
2991.1Sdyoung}
300