sets.subr revision 1.35
11.35Stron#	$NetBSD: sets.subr,v 1.35 2005/01/07 18:56:40 tron 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.33Sjmc	MKMANPAGES	\
441.22Slukem	MKMANZ		\
451.23Slukem	MKNLS		\
461.30Smatt	MKPIC		\
471.22Slukem	MKPOSTFIX	\
481.22Slukem	MKPROFILE	\
491.22Slukem	MKSENDMAIL	\
501.24Slukem	MKSHARE		\
511.22Slukem	MKSKEY		\
521.25Slukem	MKUUCP		\
531.22Slukem	MKYP		\
541.22Slukem"
551.12Slukem
561.9SlukemoIFS=$IFS
571.9SlukemIFS="
581.9Slukem"
591.9Slukemfor x in $(
601.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
611.9Slukem.include <bsd.own.mk>
621.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
631.33SjmcMKMANPAGES=no
641.33Sjmc.else
651.33SjmcMKMANPAGES=yes
661.33Sjmc.endif
671.9Slukemall:
681.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
691.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
701.12Slukem		${MKVARS}
711.12Slukem	@echo "export \$i=\${\$i}"
721.11Slukem.endfor
731.20Slukem.if (\${MKX11:Uno} != "no")
741.20Slukem	@echo x11_version=""
751.35Stron.else
761.9Slukem	@echo x11_version=4
771.9Slukem.endif
781.9Slukem
791.12SlukemEOMAKE
801.9Slukem); do
811.11Slukem#	echo 1>&2 "DEBUG: read $x"
821.9Slukem	eval $x
831.9Slukemdone
841.9SlukemIFS=$oIFS
851.9Slukem
861.34Serhsetsdir=${0%/*}
871.9Slukemnlists="base comp etc games man misc text"
881.9Slukemcase $x11_version in
891.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
901.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
911.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
921.20Slukem*)	xlists="" ;;	# unknown!
931.9Slukemesac
941.9Slukemobsolete=0
951.9Slukemlkm=yes
961.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
971.9Slukem	lkm=no				# Turn off LKMs for some ports.
981.9Slukemfi
991.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1001.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1011.9Slukem	shlib=elf
1021.9Slukemelse
1031.9Slukem	shlib=aout
1041.9Slukemfi
1051.9Slukemstlib=$shlib
1061.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1071.31Sjmcif [ "${MKPIC}" = "no" ]; then
1081.31Sjmc	shlib=no
1091.31Sjmcfi
1101.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1111.9Slukem	shlib=no			# Turn off shlibs for some ports.
1121.9Slukemfi
1131.9Slukem
1141.9Slukem#
1151.9Slukem# list_set_files setfile [...]
1161.1Sdyoung# 
1171.9Slukem# Produce a packing list for setfile(s).
1181.9Slukem# In each file, a record consists of a path and a System Package name,
1191.9Slukem# separated by whitespace. E.g.,
1201.9Slukem#
1211.35Stron# 	# $NetBSD: sets.subr,v 1.35 2005/01/07 18:56:40 tron Exp $
1221.9Slukem# 	.			base-sys-root	[keyword[,...]]
1231.9Slukem# 	./altroot		base-sys-root
1241.9Slukem# 	./bin			base-sys-root
1251.9Slukem# 	./bin/[			base-util-root
1261.9Slukem# 	./bin/cat		base-util-root
1271.9Slukem#		[...]
1281.9Slukem#
1291.9Slukem# A # in the first column marks a comment.
1301.9Slukem#
1311.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1321.9Slukem# be printed.
1331.9Slukem#
1341.9Slukem# The third field is an optional comma separated list of keywords to
1351.9Slukem# control if a record is printed; every keyword listed must be enabled
1361.9Slukem# for the record to be printed.  The following keywords are available:
1371.9Slukem#	dummy			dummy entry (ignored)
1381.13Slukem#	obsolete		file is obsolete, and only printed if 
1391.13Slukem#				${obsolete} != 0
1401.13Slukem#
1411.22Slukem#	bfd			${MKBFD} != no
1421.22Slukem#	catpages		${MKCATPAGES} != no
1431.22Slukem#	crypto			${MKCRYPTO} != no
1441.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1451.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1461.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1471.22Slukem#	cvs			${MKCVS} != no
1481.23Slukem#	doc			${MKDOC} != no
1491.32Sscw#	gdb			${MKGDB} != no
1501.22Slukem#	hesiod			${MKHESIOD} != no
1511.23Slukem#	info			${MKINFO} != no
1521.22Slukem#	kerberos		${MKKERBEROS} != no
1531.22Slukem#	kerberos4		${MKKERBEROS4} != no
1541.22Slukem#	lint			${MKLINT} != no
1551.22Slukem#	man			${MKMAN} != no
1561.22Slukem#	manz			${MKMANZ} != no
1571.23Slukem#	nls			${MKNLS} != no
1581.22Slukem#	postfix			${MKPOSTFIX} != no
1591.22Slukem#	profile			${MKPROFILE} != no
1601.22Slukem#	sendmail		${MKSENDMAIL} != no
1611.24Slukem#	share			${MKSHARE} != no
1621.22Slukem#	skey			${MKSKEY} != no
1631.25Slukem#	uucp			${MKUUCP} != no
1641.22Slukem#	yp			${MKYP} != no
1651.22Slukem#
1661.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1671.22Slukem#				  automatically append ".gz" to the filename
1681.22Slukem#
1691.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1701.22Slukem#				  automatically append ".gz" to the filename
1711.1Sdyoung#
1721.8Slukemlist_set_files()
1731.8Slukem{
1741.1Sdyoung	for setname; do
1751.1Sdyoung		list_set_lists $setname
1761.9Slukem	done | xargs cat | \
1771.11Slukem	awk -v obsolete=${obsolete} '
1781.9Slukem		BEGIN {
1791.9Slukem			if (! obsolete) {
1801.12Slukem				split("'"${MKVARS}"'", needvars)
1811.9Slukem				for (vi in needvars) {
1821.9Slukem					nv = needvars[vi]
1831.12Slukem					kw = tolower(substr(nv, 3))
1841.12Slukem					if (ENVIRON[nv] != "no")
1851.12Slukem						wanted[kw] = 1 
1861.9Slukem				}
1871.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
1881.22Slukem					wanted[".cat"] = 1
1891.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
1901.22Slukem					wanted[".man"] = 1
1911.9Slukem			}
1921.9Slukem		}
1931.9Slukem
1941.9Slukem		/^#/ {
1951.9Slukem			next;
1961.9Slukem		}
1971.9Slukem
1981.9Slukem		NF > 2 && $3 != "-" {
1991.9Slukem			split($3, keywords, ",")
2001.9Slukem			show = 1
2011.9Slukem			for (ki in keywords) {
2021.9Slukem				kw = keywords[ki]
2031.9Slukem				if (kw == "obsolete") {
2041.9Slukem					if (obsolete)
2051.9Slukem						print
2061.9Slukem					next
2071.9Slukem				}
2081.22Slukem				if (("manz" in wanted) &&
2091.22Slukem				    (kw == ".cat" || kw == ".man"))
2101.22Slukem					$1 = $1 ".gz"
2111.9Slukem				if (! (kw in wanted))
2121.9Slukem					show = 0
2131.9Slukem			}
2141.9Slukem			if (show)
2151.9Slukem				print
2161.9Slukem			next
2171.9Slukem		}
2181.9Slukem
2191.9Slukem		{
2201.9Slukem			if (! obsolete)
2211.9Slukem				print
2221.9Slukem		}'
2231.9Slukem
2241.1Sdyoung}
2251.1Sdyoung
2261.1Sdyoung#
2271.1Sdyoung# list_set_lists setname
2281.1Sdyoung# 
2291.1Sdyoung# Print to stdout a list of files, one filename per line, which
2301.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2311.1Sdyoung#
2321.1Sdyoung# 	.../lists/base/mi
2331.1Sdyoung# 	.../lists/base/rescue.mi
2341.1Sdyoung# 	.../lists/base/md.i386
2351.9Slukem#		[...]
2361.1Sdyoung#
2371.9Slukem# For a given setname $set, the following files may be selected from
2381.9Slukem# .../list/$set:
2391.9Slukem#	mi
2401.11Slukem#	ad.${MACHINE_ARCH}
2411.11Slukem# (or)	ad.${MACHINE_CPU}
2421.11Slukem#	ad.${MACHINE_CPU}.shl
2431.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2441.11Slukem# (or)	md.${MACHINE}
2451.9Slukem#	stl.mi
2461.9Slukem#	stl.stlib
2471.9Slukem#	shl.mi
2481.9Slukem#	shl.shlib
2491.9Slukem#	lkm.mi			if ${lkm} != no
2501.9Slukem#	gcc.mi
2511.9Slukem#	gcc.shl
2521.9Slukem#	tc.mi
2531.9Slukem#	tc.shl
2541.9Slukem#	rescue.shl
2551.11Slukem#	rescue.${MACHINE}
2561.11Slukem#	rescue.ad.${MACHINE_ARCH}
2571.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2581.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2591.1Sdyoung#
2601.9Slukem# Environment:
2611.1Sdyoung# 	shlib
2621.1Sdyoung# 	stlib
2631.1Sdyoung#
2641.8Slukemlist_set_lists()
2651.8Slukem{
2661.1Sdyoung	setname=$1
2671.1Sdyoung
2681.9Slukem	setdir=$setsdir/lists/$setname
2691.9Slukem	echo $setdir/mi
2701.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2711.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
2721.1Sdyoung		# since the arch-specific one will be more specific than
2731.1Sdyoung		# the cpu-specific one.
2741.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
2751.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
2761.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
2771.11Slukem			echo $setdir/ad.${MACHINE_CPU}
2781.1Sdyoung		fi
2791.1Sdyoung		if [ "$shlib" != "no" -a \
2801.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
2811.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
2821.1Sdyoung		fi
2831.1Sdyoung	fi
2841.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
2851.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
2861.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
2871.11Slukem		echo $setdir/md.${MACHINE}
2881.1Sdyoung	fi
2891.9Slukem	if [ -f $setdir/stl.mi ]; then
2901.9Slukem		echo $setdir/stl.mi
2911.1Sdyoung	fi
2921.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
2931.9Slukem		echo $setdir/stl.${stlib}
2941.1Sdyoung	fi
2951.1Sdyoung	if [ "$shlib" != "no" ]; then
2961.9Slukem		if [ -f $setdir/shl.mi ]; then
2971.9Slukem			echo $setdir/shl.mi
2981.7Sdyoung		fi
2991.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
3001.9Slukem			echo $setdir/shl.${shlib}
3011.7Sdyoung		fi
3021.1Sdyoung	fi
3031.1Sdyoung	if [ "$lkm" != "no" ]; then
3041.9Slukem		if [ -f $setdir/lkm.mi ]; then
3051.9Slukem			echo $setdir/lkm.mi
3061.1Sdyoung		fi
3071.1Sdyoung	fi
3081.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3091.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3101.9Slukem			if [ -f $setdir/gcc.mi ]; then
3111.9Slukem				echo $setdir/gcc.mi
3121.2Smrg			fi
3131.2Smrg			if [ "$shlib" != "no" ]; then
3141.9Slukem				if [ -f $setdir/gcc.shl ]; then
3151.9Slukem					echo $setdir/gcc.shl
3161.2Smrg				fi
3171.2Smrg			fi
3181.2Smrg		else
3191.9Slukem			if [ -f $setdir/tc.mi ]; then
3201.9Slukem				echo $setdir/tc.mi
3211.2Smrg			fi
3221.2Smrg			if [ "$shlib" != "no" ]; then
3231.9Slukem				if [ -f $setdir/tc.shl ]; then
3241.9Slukem					echo $setdir/tc.shl
3251.2Smrg				fi
3261.1Sdyoung			fi
3271.1Sdyoung		fi
3281.1Sdyoung	fi
3291.1Sdyoung
3301.9Slukem	if [ -f $setdir/rescue.mi ]; then
3311.9Slukem		echo $setdir/rescue.mi
3321.1Sdyoung	fi
3331.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3341.11Slukem		echo $setdir/rescue.${MACHINE}
3351.1Sdyoung	fi
3361.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3371.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3381.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3391.1Sdyoung		# specific one will be more specific than the
3401.1Sdyoung		# cpu-specific one.
3411.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3421.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3431.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3441.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3451.1Sdyoung		fi
3461.10Sjmc		if [ "$shlib" != "no" -a \
3471.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3481.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3491.10Sjmc		fi
3501.1Sdyoung	fi
3511.5Sdyoung}
3521.5Sdyoung
3531.9Slukem# arch_to_cpu mach
3541.9Slukem#
3551.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3561.9Slukem# as determined by <bsd.own.mk>.
3571.9Slukem#
3581.8Slukemarch_to_cpu()
3591.8Slukem{
3601.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3611.5Sdyoung.include <bsd.own.mk>
3621.5Sdyoungall:
3631.5Sdyoung	@echo \${MACHINE_CPU}
3641.12SlukemEOMAKE
3651.1Sdyoung}
366