sets.subr revision 1.32
11.32Sscw#	$NetBSD: sets.subr,v 1.32 2004/03/17 20:32:02 scw 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.32Sscw	MKGDB		\
371.22Slukem	MKHESIOD	\
381.23Slukem	MKINFO		\
391.22Slukem	MKKERBEROS	\
401.22Slukem	MKKERBEROS4	\
411.22Slukem	MKLINT		\
421.22Slukem	MKMAN		\
431.22Slukem	MKMANZ		\
441.23Slukem	MKNLS		\
451.30Smatt	MKPIC		\
461.22Slukem	MKPOSTFIX	\
471.22Slukem	MKPROFILE	\
481.22Slukem	MKSENDMAIL	\
491.24Slukem	MKSHARE		\
501.22Slukem	MKSKEY		\
511.25Slukem	MKUUCP		\
521.22Slukem	MKYP		\
531.22Slukem"
541.12Slukem
551.9SlukemoIFS=$IFS
561.9SlukemIFS="
571.9Slukem"
581.9Slukemfor x in $(
591.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
601.9Slukem.include <bsd.own.mk>
611.9Slukemall:
621.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
631.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
641.12Slukem		${MKVARS}
651.12Slukem	@echo "export \$i=\${\$i}"
661.11Slukem.endfor
671.20Slukem.if (\${MKX11:Uno} != "no")
681.20Slukem	@echo x11_version=""
691.20Slukem.elif (\${USE_XF86_4:Uno} != "no")
701.9Slukem	@echo x11_version=4
711.9Slukem.else
721.9Slukem	@echo x11_version=3
731.9Slukem.endif
741.9Slukem
751.12SlukemEOMAKE
761.9Slukem); do
771.11Slukem#	echo 1>&2 "DEBUG: read $x"
781.9Slukem	eval $x
791.9Slukemdone
801.9SlukemIFS=$oIFS
811.9Slukem
821.9Slukemsetsdir=$(dirname $0)
831.9Slukemnlists="base comp etc games man misc text"
841.9Slukemcase $x11_version in
851.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
861.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
871.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
881.20Slukem*)	xlists="" ;;	# unknown!
891.9Slukemesac
901.9Slukemobsolete=0
911.9Slukemlkm=yes
921.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
931.9Slukem	lkm=no				# Turn off LKMs for some ports.
941.9Slukemfi
951.31Sjmc# Determine lib type. Do this first so stlib also gets set.
961.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
971.9Slukem	shlib=elf
981.9Slukemelse
991.9Slukem	shlib=aout
1001.9Slukemfi
1011.9Slukemstlib=$shlib
1021.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1031.31Sjmcif [ "${MKPIC}" = "no" ]; then
1041.31Sjmc	shlib=no
1051.31Sjmcfi
1061.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1071.9Slukem	shlib=no			# Turn off shlibs for some ports.
1081.9Slukemfi
1091.9Slukem
1101.9Slukem#
1111.9Slukem# list_set_files setfile [...]
1121.1Sdyoung# 
1131.9Slukem# Produce a packing list for setfile(s).
1141.9Slukem# In each file, a record consists of a path and a System Package name,
1151.9Slukem# separated by whitespace. E.g.,
1161.9Slukem#
1171.32Sscw# 	# $NetBSD: sets.subr,v 1.32 2004/03/17 20:32:02 scw Exp $
1181.9Slukem# 	.			base-sys-root	[keyword[,...]]
1191.9Slukem# 	./altroot		base-sys-root
1201.9Slukem# 	./bin			base-sys-root
1211.9Slukem# 	./bin/[			base-util-root
1221.9Slukem# 	./bin/cat		base-util-root
1231.9Slukem#		[...]
1241.9Slukem#
1251.9Slukem# A # in the first column marks a comment.
1261.9Slukem#
1271.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1281.9Slukem# be printed.
1291.9Slukem#
1301.9Slukem# The third field is an optional comma separated list of keywords to
1311.9Slukem# control if a record is printed; every keyword listed must be enabled
1321.9Slukem# for the record to be printed.  The following keywords are available:
1331.9Slukem#	dummy			dummy entry (ignored)
1341.13Slukem#	obsolete		file is obsolete, and only printed if 
1351.13Slukem#				${obsolete} != 0
1361.13Slukem#
1371.22Slukem#	bfd			${MKBFD} != no
1381.22Slukem#	catpages		${MKCATPAGES} != no
1391.22Slukem#	crypto			${MKCRYPTO} != no
1401.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1411.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1421.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1431.22Slukem#	cvs			${MKCVS} != no
1441.23Slukem#	doc			${MKDOC} != no
1451.32Sscw#	gdb			${MKGDB} != no
1461.22Slukem#	hesiod			${MKHESIOD} != no
1471.23Slukem#	info			${MKINFO} != no
1481.22Slukem#	kerberos		${MKKERBEROS} != no
1491.22Slukem#	kerberos4		${MKKERBEROS4} != no
1501.22Slukem#	lint			${MKLINT} != no
1511.22Slukem#	man			${MKMAN} != no
1521.22Slukem#	manz			${MKMANZ} != no
1531.23Slukem#	nls			${MKNLS} != no
1541.22Slukem#	postfix			${MKPOSTFIX} != no
1551.22Slukem#	profile			${MKPROFILE} != no
1561.22Slukem#	sendmail		${MKSENDMAIL} != no
1571.24Slukem#	share			${MKSHARE} != no
1581.22Slukem#	skey			${MKSKEY} != no
1591.25Slukem#	uucp			${MKUUCP} != no
1601.22Slukem#	yp			${MKYP} != no
1611.22Slukem#
1621.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1631.22Slukem#				  automatically append ".gz" to the filename
1641.22Slukem#
1651.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1661.22Slukem#				  automatically append ".gz" to the filename
1671.1Sdyoung#
1681.8Slukemlist_set_files()
1691.8Slukem{
1701.1Sdyoung	for setname; do
1711.1Sdyoung		list_set_lists $setname
1721.9Slukem	done | xargs cat | \
1731.11Slukem	awk -v obsolete=${obsolete} '
1741.9Slukem		BEGIN {
1751.9Slukem			if (! obsolete) {
1761.12Slukem				split("'"${MKVARS}"'", needvars)
1771.9Slukem				for (vi in needvars) {
1781.9Slukem					nv = needvars[vi]
1791.12Slukem					kw = tolower(substr(nv, 3))
1801.12Slukem					if (ENVIRON[nv] != "no")
1811.12Slukem						wanted[kw] = 1 
1821.9Slukem				}
1831.22Slukem				if ("catpages" in wanted)
1841.22Slukem					wanted[".cat"] = 1
1851.22Slukem				if ("man" in wanted)
1861.22Slukem					wanted[".man"] = 1
1871.9Slukem			}
1881.9Slukem		}
1891.9Slukem
1901.9Slukem		/^#/ {
1911.9Slukem			next;
1921.9Slukem		}
1931.9Slukem
1941.9Slukem		NF > 2 && $3 != "-" {
1951.9Slukem			split($3, keywords, ",")
1961.9Slukem			show = 1
1971.9Slukem			for (ki in keywords) {
1981.9Slukem				kw = keywords[ki]
1991.9Slukem				if (kw == "obsolete") {
2001.9Slukem					if (obsolete)
2011.9Slukem						print
2021.9Slukem					next
2031.9Slukem				}
2041.22Slukem				if (("manz" in wanted) &&
2051.22Slukem				    (kw == ".cat" || kw == ".man"))
2061.22Slukem					$1 = $1 ".gz"
2071.9Slukem				if (! (kw in wanted))
2081.9Slukem					show = 0
2091.9Slukem			}
2101.9Slukem			if (show)
2111.9Slukem				print
2121.9Slukem			next
2131.9Slukem		}
2141.9Slukem
2151.9Slukem		{
2161.9Slukem			if (! obsolete)
2171.9Slukem				print
2181.9Slukem		}'
2191.9Slukem
2201.1Sdyoung}
2211.1Sdyoung
2221.1Sdyoung#
2231.1Sdyoung# list_set_lists setname
2241.1Sdyoung# 
2251.1Sdyoung# Print to stdout a list of files, one filename per line, which
2261.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2271.1Sdyoung#
2281.1Sdyoung# 	.../lists/base/mi
2291.1Sdyoung# 	.../lists/base/rescue.mi
2301.1Sdyoung# 	.../lists/base/md.i386
2311.9Slukem#		[...]
2321.1Sdyoung#
2331.9Slukem# For a given setname $set, the following files may be selected from
2341.9Slukem# .../list/$set:
2351.9Slukem#	mi
2361.11Slukem#	ad.${MACHINE_ARCH}
2371.11Slukem# (or)	ad.${MACHINE_CPU}
2381.11Slukem#	ad.${MACHINE_CPU}.shl
2391.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2401.11Slukem# (or)	md.${MACHINE}
2411.9Slukem#	stl.mi
2421.9Slukem#	stl.stlib
2431.9Slukem#	shl.mi
2441.9Slukem#	shl.shlib
2451.9Slukem#	lkm.mi			if ${lkm} != no
2461.9Slukem#	gcc.mi
2471.9Slukem#	gcc.shl
2481.9Slukem#	tc.mi
2491.9Slukem#	tc.shl
2501.9Slukem#	rescue.shl
2511.11Slukem#	rescue.${MACHINE}
2521.11Slukem#	rescue.ad.${MACHINE_ARCH}
2531.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2541.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2551.1Sdyoung#
2561.9Slukem# Environment:
2571.1Sdyoung# 	shlib
2581.1Sdyoung# 	stlib
2591.1Sdyoung#
2601.8Slukemlist_set_lists()
2611.8Slukem{
2621.1Sdyoung	setname=$1
2631.1Sdyoung
2641.9Slukem	setdir=$setsdir/lists/$setname
2651.9Slukem	echo $setdir/mi
2661.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2671.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
2681.1Sdyoung		# since the arch-specific one will be more specific than
2691.1Sdyoung		# the cpu-specific one.
2701.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
2711.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
2721.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
2731.11Slukem			echo $setdir/ad.${MACHINE_CPU}
2741.1Sdyoung		fi
2751.1Sdyoung		if [ "$shlib" != "no" -a \
2761.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
2771.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
2781.1Sdyoung		fi
2791.1Sdyoung	fi
2801.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
2811.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
2821.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
2831.11Slukem		echo $setdir/md.${MACHINE}
2841.1Sdyoung	fi
2851.9Slukem	if [ -f $setdir/stl.mi ]; then
2861.9Slukem		echo $setdir/stl.mi
2871.1Sdyoung	fi
2881.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
2891.9Slukem		echo $setdir/stl.${stlib}
2901.1Sdyoung	fi
2911.1Sdyoung	if [ "$shlib" != "no" ]; then
2921.9Slukem		if [ -f $setdir/shl.mi ]; then
2931.9Slukem			echo $setdir/shl.mi
2941.7Sdyoung		fi
2951.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
2961.9Slukem			echo $setdir/shl.${shlib}
2971.7Sdyoung		fi
2981.1Sdyoung	fi
2991.1Sdyoung	if [ "$lkm" != "no" ]; then
3001.9Slukem		if [ -f $setdir/lkm.mi ]; then
3011.9Slukem			echo $setdir/lkm.mi
3021.1Sdyoung		fi
3031.1Sdyoung	fi
3041.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3051.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3061.9Slukem			if [ -f $setdir/gcc.mi ]; then
3071.9Slukem				echo $setdir/gcc.mi
3081.2Smrg			fi
3091.2Smrg			if [ "$shlib" != "no" ]; then
3101.9Slukem				if [ -f $setdir/gcc.shl ]; then
3111.9Slukem					echo $setdir/gcc.shl
3121.2Smrg				fi
3131.2Smrg			fi
3141.2Smrg		else
3151.9Slukem			if [ -f $setdir/tc.mi ]; then
3161.9Slukem				echo $setdir/tc.mi
3171.2Smrg			fi
3181.2Smrg			if [ "$shlib" != "no" ]; then
3191.9Slukem				if [ -f $setdir/tc.shl ]; then
3201.9Slukem					echo $setdir/tc.shl
3211.2Smrg				fi
3221.1Sdyoung			fi
3231.1Sdyoung		fi
3241.1Sdyoung	fi
3251.1Sdyoung
3261.9Slukem	if [ -f $setdir/rescue.mi ]; then
3271.9Slukem		echo $setdir/rescue.mi
3281.1Sdyoung	fi
3291.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3301.11Slukem		echo $setdir/rescue.${MACHINE}
3311.1Sdyoung	fi
3321.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3331.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3341.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3351.1Sdyoung		# specific one will be more specific than the
3361.1Sdyoung		# cpu-specific one.
3371.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3381.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3391.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3401.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3411.1Sdyoung		fi
3421.10Sjmc		if [ "$shlib" != "no" -a \
3431.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3441.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3451.10Sjmc		fi
3461.1Sdyoung	fi
3471.5Sdyoung}
3481.5Sdyoung
3491.9Slukem# arch_to_cpu mach
3501.9Slukem#
3511.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3521.9Slukem# as determined by <bsd.own.mk>.
3531.9Slukem#
3541.8Slukemarch_to_cpu()
3551.8Slukem{
3561.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3571.5Sdyoung.include <bsd.own.mk>
3581.5Sdyoungall:
3591.5Sdyoung	@echo \${MACHINE_CPU}
3601.12SlukemEOMAKE
3611.1Sdyoung}
362