sets.subr revision 1.28
11.28Slukem#	$NetBSD: sets.subr,v 1.28 2004/01/23 14:38:09 lukem 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.23Slukem	MKDOC		\
361.22Slukem	MKHESIOD	\
371.23Slukem	MKINFO		\
381.22Slukem	MKKERBEROS	\
391.22Slukem	MKKERBEROS4	\
401.22Slukem	MKLINT		\
411.22Slukem	MKMAN		\
421.22Slukem	MKMANZ		\
431.23Slukem	MKNLS		\
441.22Slukem	MKPOSTFIX	\
451.22Slukem	MKPROFILE	\
461.22Slukem	MKSENDMAIL	\
471.24Slukem	MKSHARE		\
481.22Slukem	MKSKEY		\
491.25Slukem	MKUUCP		\
501.22Slukem	MKYP		\
511.22Slukem"
521.12Slukem
531.9SlukemoIFS=$IFS
541.9SlukemIFS="
551.9Slukem"
561.9Slukemfor x in $(
571.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
581.9Slukem.include <bsd.own.mk>
591.9Slukemall:
601.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
611.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
621.12Slukem		${MKVARS}
631.12Slukem	@echo "export \$i=\${\$i}"
641.11Slukem.endfor
651.20Slukem.if (\${MKX11:Uno} != "no")
661.20Slukem	@echo x11_version=""
671.20Slukem.elif (\${USE_XF86_4:Uno} != "no")
681.9Slukem	@echo x11_version=4
691.9Slukem.else
701.9Slukem	@echo x11_version=3
711.9Slukem.endif
721.9Slukem
731.12SlukemEOMAKE
741.9Slukem); do
751.11Slukem#	echo 1>&2 "DEBUG: read $x"
761.9Slukem	eval $x
771.9Slukemdone
781.9SlukemIFS=$oIFS
791.9Slukem
801.9Slukemsetsdir=$(dirname $0)
811.9Slukemnlists="base comp etc games man misc text"
821.9Slukemcase $x11_version in
831.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
841.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
851.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
861.20Slukem*)	xlists="" ;;	# unknown!
871.9Slukemesac
881.9Slukemobsolete=0
891.9Slukemlkm=yes
901.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
911.9Slukem	lkm=no				# Turn off LKMs for some ports.
921.9Slukemfi
931.9Slukem# Determine lib type.
941.11Slukemif [ "${OBJECT_FMT}" = "ELF" ]; then
951.9Slukem	shlib=elf
961.9Slukemelse
971.9Slukem	shlib=aout
981.9Slukemfi
991.9Slukemstlib=$shlib
1001.11Slukemif [ "${MACHINE_CPU}" = "sh3" -o "${MACHINE_ARCH}" = "m68000" ]; then
1011.9Slukem	shlib=no			# Turn off shlibs for some ports.
1021.9Slukemfi
1031.9Slukem
1041.9Slukem
1051.9Slukem#
1061.9Slukem# list_set_files setfile [...]
1071.1Sdyoung# 
1081.9Slukem# Produce a packing list for setfile(s).
1091.9Slukem# In each file, a record consists of a path and a System Package name,
1101.9Slukem# separated by whitespace. E.g.,
1111.9Slukem#
1121.28Slukem# 	# $NetBSD: sets.subr,v 1.28 2004/01/23 14:38:09 lukem Exp $
1131.9Slukem# 	.			base-sys-root	[keyword[,...]]
1141.9Slukem# 	./altroot		base-sys-root
1151.9Slukem# 	./bin			base-sys-root
1161.9Slukem# 	./bin/[			base-util-root
1171.9Slukem# 	./bin/cat		base-util-root
1181.9Slukem#		[...]
1191.9Slukem#
1201.9Slukem# A # in the first column marks a comment.
1211.9Slukem#
1221.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1231.9Slukem# be printed.
1241.9Slukem#
1251.9Slukem# The third field is an optional comma separated list of keywords to
1261.9Slukem# control if a record is printed; every keyword listed must be enabled
1271.9Slukem# for the record to be printed.  The following keywords are available:
1281.9Slukem#	dummy			dummy entry (ignored)
1291.13Slukem#	obsolete		file is obsolete, and only printed if 
1301.13Slukem#				${obsolete} != 0
1311.13Slukem#
1321.22Slukem#	bfd			${MKBFD} != no
1331.22Slukem#	catpages		${MKCATPAGES} != no
1341.22Slukem#	crypto			${MKCRYPTO} != no
1351.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1361.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1371.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1381.22Slukem#	cvs			${MKCVS} != no
1391.23Slukem#	doc			${MKDOC} != no
1401.22Slukem#	hesiod			${MKHESIOD} != no
1411.23Slukem#	info			${MKINFO} != no
1421.22Slukem#	kerberos		${MKKERBEROS} != no
1431.22Slukem#	kerberos4		${MKKERBEROS4} != no
1441.22Slukem#	lint			${MKLINT} != no
1451.22Slukem#	man			${MKMAN} != no
1461.22Slukem#	manz			${MKMANZ} != no
1471.23Slukem#	nls			${MKNLS} != no
1481.22Slukem#	postfix			${MKPOSTFIX} != no
1491.22Slukem#	profile			${MKPROFILE} != no
1501.22Slukem#	sendmail		${MKSENDMAIL} != no
1511.24Slukem#	share			${MKSHARE} != no
1521.22Slukem#	skey			${MKSKEY} != no
1531.25Slukem#	uucp			${MKUUCP} != no
1541.22Slukem#	yp			${MKYP} != no
1551.22Slukem#
1561.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1571.22Slukem#				  automatically append ".gz" to the filename
1581.22Slukem#
1591.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1601.22Slukem#				  automatically append ".gz" to the filename
1611.1Sdyoung#
1621.8Slukemlist_set_files()
1631.8Slukem{
1641.1Sdyoung	for setname; do
1651.1Sdyoung		list_set_lists $setname
1661.9Slukem	done | xargs cat | \
1671.11Slukem	awk -v obsolete=${obsolete} '
1681.9Slukem		BEGIN {
1691.9Slukem			if (! obsolete) {
1701.12Slukem				split("'"${MKVARS}"'", needvars)
1711.9Slukem				for (vi in needvars) {
1721.9Slukem					nv = needvars[vi]
1731.12Slukem					kw = tolower(substr(nv, 3))
1741.12Slukem					if (ENVIRON[nv] != "no")
1751.12Slukem						wanted[kw] = 1 
1761.9Slukem				}
1771.22Slukem				if ("catpages" in wanted)
1781.22Slukem					wanted[".cat"] = 1
1791.22Slukem				if ("man" in wanted)
1801.22Slukem					wanted[".man"] = 1
1811.9Slukem			}
1821.9Slukem		}
1831.9Slukem
1841.9Slukem		/^#/ {
1851.9Slukem			next;
1861.9Slukem		}
1871.9Slukem
1881.9Slukem		NF > 2 && $3 != "-" {
1891.9Slukem			split($3, keywords, ",")
1901.9Slukem			show = 1
1911.9Slukem			for (ki in keywords) {
1921.9Slukem				kw = keywords[ki]
1931.9Slukem				if (kw == "obsolete") {
1941.9Slukem					if (obsolete)
1951.9Slukem						print
1961.9Slukem					next
1971.9Slukem				}
1981.22Slukem				if (("manz" in wanted) &&
1991.22Slukem				    (kw == ".cat" || kw == ".man"))
2001.22Slukem					$1 = $1 ".gz"
2011.9Slukem				if (! (kw in wanted))
2021.9Slukem					show = 0
2031.9Slukem			}
2041.9Slukem			if (show)
2051.9Slukem				print
2061.9Slukem			next
2071.9Slukem		}
2081.9Slukem
2091.9Slukem		{
2101.9Slukem			if (! obsolete)
2111.9Slukem				print
2121.9Slukem		}'
2131.9Slukem
2141.1Sdyoung}
2151.1Sdyoung
2161.1Sdyoung#
2171.1Sdyoung# list_set_lists setname
2181.1Sdyoung# 
2191.1Sdyoung# Print to stdout a list of files, one filename per line, which
2201.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2211.1Sdyoung#
2221.1Sdyoung# 	.../lists/base/mi
2231.1Sdyoung# 	.../lists/base/rescue.mi
2241.1Sdyoung# 	.../lists/base/md.i386
2251.9Slukem#		[...]
2261.1Sdyoung#
2271.9Slukem# For a given setname $set, the following files may be selected from
2281.9Slukem# .../list/$set:
2291.9Slukem#	mi
2301.11Slukem#	ad.${MACHINE_ARCH}
2311.11Slukem# (or)	ad.${MACHINE_CPU}
2321.11Slukem#	ad.${MACHINE_CPU}.shl
2331.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2341.11Slukem# (or)	md.${MACHINE}
2351.9Slukem#	stl.mi
2361.9Slukem#	stl.stlib
2371.9Slukem#	shl.mi
2381.9Slukem#	shl.shlib
2391.9Slukem#	lkm.mi			if ${lkm} != no
2401.9Slukem#	gcc.mi
2411.9Slukem#	gcc.shl
2421.9Slukem#	tc.mi
2431.9Slukem#	tc.shl
2441.9Slukem#	rescue.shl
2451.11Slukem#	rescue.${MACHINE}
2461.11Slukem#	rescue.ad.${MACHINE_ARCH}
2471.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2481.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2491.1Sdyoung#
2501.9Slukem# Environment:
2511.1Sdyoung# 	shlib
2521.1Sdyoung# 	stlib
2531.1Sdyoung#
2541.8Slukemlist_set_lists()
2551.8Slukem{
2561.1Sdyoung	setname=$1
2571.1Sdyoung
2581.9Slukem	setdir=$setsdir/lists/$setname
2591.9Slukem	echo $setdir/mi
2601.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2611.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
2621.1Sdyoung		# since the arch-specific one will be more specific than
2631.1Sdyoung		# the cpu-specific one.
2641.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
2651.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
2661.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
2671.11Slukem			echo $setdir/ad.${MACHINE_CPU}
2681.1Sdyoung		fi
2691.1Sdyoung		if [ "$shlib" != "no" -a \
2701.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
2711.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
2721.1Sdyoung		fi
2731.1Sdyoung	fi
2741.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
2751.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
2761.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
2771.11Slukem		echo $setdir/md.${MACHINE}
2781.1Sdyoung	fi
2791.9Slukem	if [ -f $setdir/stl.mi ]; then
2801.9Slukem		echo $setdir/stl.mi
2811.1Sdyoung	fi
2821.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
2831.9Slukem		echo $setdir/stl.${stlib}
2841.1Sdyoung	fi
2851.1Sdyoung	if [ "$shlib" != "no" ]; then
2861.9Slukem		if [ -f $setdir/shl.mi ]; then
2871.9Slukem			echo $setdir/shl.mi
2881.7Sdyoung		fi
2891.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
2901.9Slukem			echo $setdir/shl.${shlib}
2911.7Sdyoung		fi
2921.1Sdyoung	fi
2931.1Sdyoung	if [ "$lkm" != "no" ]; then
2941.9Slukem		if [ -f $setdir/lkm.mi ]; then
2951.9Slukem			echo $setdir/lkm.mi
2961.1Sdyoung		fi
2971.1Sdyoung	fi
2981.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
2991.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3001.9Slukem			if [ -f $setdir/gcc.mi ]; then
3011.9Slukem				echo $setdir/gcc.mi
3021.2Smrg			fi
3031.2Smrg			if [ "$shlib" != "no" ]; then
3041.9Slukem				if [ -f $setdir/gcc.shl ]; then
3051.9Slukem					echo $setdir/gcc.shl
3061.2Smrg				fi
3071.2Smrg			fi
3081.2Smrg		else
3091.9Slukem			if [ -f $setdir/tc.mi ]; then
3101.9Slukem				echo $setdir/tc.mi
3111.2Smrg			fi
3121.2Smrg			if [ "$shlib" != "no" ]; then
3131.9Slukem				if [ -f $setdir/tc.shl ]; then
3141.9Slukem					echo $setdir/tc.shl
3151.2Smrg				fi
3161.1Sdyoung			fi
3171.1Sdyoung		fi
3181.1Sdyoung	fi
3191.1Sdyoung
3201.9Slukem	if [ -f $setdir/rescue.mi ]; then
3211.9Slukem		echo $setdir/rescue.mi
3221.1Sdyoung	fi
3231.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3241.11Slukem		echo $setdir/rescue.${MACHINE}
3251.1Sdyoung	fi
3261.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3271.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3281.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3291.1Sdyoung		# specific one will be more specific than the
3301.1Sdyoung		# cpu-specific one.
3311.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3321.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3331.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3341.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3351.1Sdyoung		fi
3361.10Sjmc		if [ "$shlib" != "no" -a \
3371.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3381.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3391.10Sjmc		fi
3401.1Sdyoung	fi
3411.5Sdyoung}
3421.5Sdyoung
3431.9Slukem# arch_to_cpu mach
3441.9Slukem#
3451.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3461.9Slukem# as determined by <bsd.own.mk>.
3471.9Slukem#
3481.8Slukemarch_to_cpu()
3491.8Slukem{
3501.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3511.5Sdyoung.include <bsd.own.mk>
3521.5Sdyoungall:
3531.5Sdyoung	@echo \${MACHINE_CPU}
3541.12SlukemEOMAKE
3551.1Sdyoung}
356