sets.subr revision 1.38
11.38Slukem#	$NetBSD: sets.subr,v 1.38 2005/01/10 03:13:04 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.36Smatt	MKGCCCMDS	\
361.23Slukem	MKDOC		\
371.32Sscw	MKGDB		\
381.22Slukem	MKHESIOD	\
391.23Slukem	MKINFO		\
401.38Slukem	MKINET6		\
411.22Slukem	MKKERBEROS	\
421.22Slukem	MKKERBEROS4	\
431.22Slukem	MKLINT		\
441.22Slukem	MKMAN		\
451.33Sjmc	MKMANPAGES	\
461.22Slukem	MKMANZ		\
471.23Slukem	MKNLS		\
481.37She	MKPAM		\
491.30Smatt	MKPIC		\
501.22Slukem	MKPOSTFIX	\
511.22Slukem	MKPROFILE	\
521.22Slukem	MKSENDMAIL	\
531.24Slukem	MKSHARE		\
541.22Slukem	MKSKEY		\
551.25Slukem	MKUUCP		\
561.22Slukem	MKYP		\
571.22Slukem"
581.12Slukem
591.9SlukemoIFS=$IFS
601.9SlukemIFS="
611.9Slukem"
621.9Slukemfor x in $(
631.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
641.9Slukem.include <bsd.own.mk>
651.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
661.33SjmcMKMANPAGES=no
671.33Sjmc.else
681.33SjmcMKMANPAGES=yes
691.33Sjmc.endif
701.9Slukemall:
711.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
721.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
731.12Slukem		${MKVARS}
741.12Slukem	@echo "export \$i=\${\$i}"
751.11Slukem.endfor
761.20Slukem.if (\${MKX11:Uno} != "no")
771.20Slukem	@echo x11_version=""
781.35Stron.else
791.9Slukem	@echo x11_version=4
801.9Slukem.endif
811.9Slukem
821.12SlukemEOMAKE
831.9Slukem); do
841.11Slukem#	echo 1>&2 "DEBUG: read $x"
851.9Slukem	eval $x
861.9Slukemdone
871.9SlukemIFS=$oIFS
881.9Slukem
891.34Serhsetsdir=${0%/*}
901.9Slukemnlists="base comp etc games man misc text"
911.9Slukemcase $x11_version in
921.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
931.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
941.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
951.20Slukem*)	xlists="" ;;	# unknown!
961.9Slukemesac
971.9Slukemobsolete=0
981.9Slukemlkm=yes
991.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
1001.9Slukem	lkm=no				# Turn off LKMs for some ports.
1011.9Slukemfi
1021.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1031.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1041.9Slukem	shlib=elf
1051.9Slukemelse
1061.9Slukem	shlib=aout
1071.9Slukemfi
1081.9Slukemstlib=$shlib
1091.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1101.31Sjmcif [ "${MKPIC}" = "no" ]; then
1111.31Sjmc	shlib=no
1121.31Sjmcfi
1131.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1141.9Slukem	shlib=no			# Turn off shlibs for some ports.
1151.9Slukemfi
1161.9Slukem
1171.9Slukem#
1181.9Slukem# list_set_files setfile [...]
1191.1Sdyoung# 
1201.9Slukem# Produce a packing list for setfile(s).
1211.9Slukem# In each file, a record consists of a path and a System Package name,
1221.9Slukem# separated by whitespace. E.g.,
1231.9Slukem#
1241.38Slukem# 	# $NetBSD: sets.subr,v 1.38 2005/01/10 03:13:04 lukem Exp $
1251.9Slukem# 	.			base-sys-root	[keyword[,...]]
1261.9Slukem# 	./altroot		base-sys-root
1271.9Slukem# 	./bin			base-sys-root
1281.9Slukem# 	./bin/[			base-util-root
1291.9Slukem# 	./bin/cat		base-util-root
1301.9Slukem#		[...]
1311.9Slukem#
1321.9Slukem# A # in the first column marks a comment.
1331.9Slukem#
1341.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1351.9Slukem# be printed.
1361.9Slukem#
1371.9Slukem# The third field is an optional comma separated list of keywords to
1381.9Slukem# control if a record is printed; every keyword listed must be enabled
1391.9Slukem# for the record to be printed.  The following keywords are available:
1401.9Slukem#	dummy			dummy entry (ignored)
1411.13Slukem#	obsolete		file is obsolete, and only printed if 
1421.13Slukem#				${obsolete} != 0
1431.13Slukem#
1441.22Slukem#	bfd			${MKBFD} != no
1451.22Slukem#	catpages		${MKCATPAGES} != no
1461.22Slukem#	crypto			${MKCRYPTO} != no
1471.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1481.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1491.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1501.22Slukem#	cvs			${MKCVS} != no
1511.23Slukem#	doc			${MKDOC} != no
1521.36Smatt#	gcccmds			${MKGCCCMDS} != no
1531.32Sscw#	gdb			${MKGDB} != no
1541.22Slukem#	hesiod			${MKHESIOD} != no
1551.23Slukem#	info			${MKINFO} != no
1561.38Slukem#	inet6			${MKINET6} != no
1571.22Slukem#	kerberos		${MKKERBEROS} != no
1581.22Slukem#	kerberos4		${MKKERBEROS4} != no
1591.22Slukem#	lint			${MKLINT} != no
1601.22Slukem#	man			${MKMAN} != no
1611.22Slukem#	manz			${MKMANZ} != no
1621.23Slukem#	nls			${MKNLS} != no
1631.37She#	pam			${MKPAM} != no
1641.22Slukem#	postfix			${MKPOSTFIX} != no
1651.22Slukem#	profile			${MKPROFILE} != no
1661.22Slukem#	sendmail		${MKSENDMAIL} != no
1671.24Slukem#	share			${MKSHARE} != no
1681.22Slukem#	skey			${MKSKEY} != no
1691.25Slukem#	uucp			${MKUUCP} != no
1701.22Slukem#	yp			${MKYP} != no
1711.22Slukem#
1721.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1731.22Slukem#				  automatically append ".gz" to the filename
1741.22Slukem#
1751.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1761.22Slukem#				  automatically append ".gz" to the filename
1771.1Sdyoung#
1781.8Slukemlist_set_files()
1791.8Slukem{
1801.1Sdyoung	for setname; do
1811.1Sdyoung		list_set_lists $setname
1821.9Slukem	done | xargs cat | \
1831.11Slukem	awk -v obsolete=${obsolete} '
1841.9Slukem		BEGIN {
1851.9Slukem			if (! obsolete) {
1861.12Slukem				split("'"${MKVARS}"'", needvars)
1871.9Slukem				for (vi in needvars) {
1881.9Slukem					nv = needvars[vi]
1891.12Slukem					kw = tolower(substr(nv, 3))
1901.12Slukem					if (ENVIRON[nv] != "no")
1911.12Slukem						wanted[kw] = 1 
1921.9Slukem				}
1931.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
1941.22Slukem					wanted[".cat"] = 1
1951.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
1961.22Slukem					wanted[".man"] = 1
1971.9Slukem			}
1981.9Slukem		}
1991.9Slukem
2001.9Slukem		/^#/ {
2011.9Slukem			next;
2021.9Slukem		}
2031.9Slukem
2041.9Slukem		NF > 2 && $3 != "-" {
2051.9Slukem			split($3, keywords, ",")
2061.9Slukem			show = 1
2071.9Slukem			for (ki in keywords) {
2081.9Slukem				kw = keywords[ki]
2091.9Slukem				if (kw == "obsolete") {
2101.9Slukem					if (obsolete)
2111.9Slukem						print
2121.9Slukem					next
2131.9Slukem				}
2141.22Slukem				if (("manz" in wanted) &&
2151.22Slukem				    (kw == ".cat" || kw == ".man"))
2161.22Slukem					$1 = $1 ".gz"
2171.9Slukem				if (! (kw in wanted))
2181.9Slukem					show = 0
2191.9Slukem			}
2201.9Slukem			if (show)
2211.9Slukem				print
2221.9Slukem			next
2231.9Slukem		}
2241.9Slukem
2251.9Slukem		{
2261.9Slukem			if (! obsolete)
2271.9Slukem				print
2281.9Slukem		}'
2291.9Slukem
2301.1Sdyoung}
2311.1Sdyoung
2321.1Sdyoung#
2331.1Sdyoung# list_set_lists setname
2341.1Sdyoung# 
2351.1Sdyoung# Print to stdout a list of files, one filename per line, which
2361.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2371.1Sdyoung#
2381.1Sdyoung# 	.../lists/base/mi
2391.1Sdyoung# 	.../lists/base/rescue.mi
2401.1Sdyoung# 	.../lists/base/md.i386
2411.9Slukem#		[...]
2421.1Sdyoung#
2431.9Slukem# For a given setname $set, the following files may be selected from
2441.9Slukem# .../list/$set:
2451.9Slukem#	mi
2461.11Slukem#	ad.${MACHINE_ARCH}
2471.11Slukem# (or)	ad.${MACHINE_CPU}
2481.11Slukem#	ad.${MACHINE_CPU}.shl
2491.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2501.11Slukem# (or)	md.${MACHINE}
2511.9Slukem#	stl.mi
2521.9Slukem#	stl.stlib
2531.9Slukem#	shl.mi
2541.9Slukem#	shl.shlib
2551.9Slukem#	lkm.mi			if ${lkm} != no
2561.9Slukem#	gcc.mi
2571.9Slukem#	gcc.shl
2581.9Slukem#	tc.mi
2591.9Slukem#	tc.shl
2601.9Slukem#	rescue.shl
2611.11Slukem#	rescue.${MACHINE}
2621.11Slukem#	rescue.ad.${MACHINE_ARCH}
2631.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2641.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2651.1Sdyoung#
2661.9Slukem# Environment:
2671.1Sdyoung# 	shlib
2681.1Sdyoung# 	stlib
2691.1Sdyoung#
2701.8Slukemlist_set_lists()
2711.8Slukem{
2721.1Sdyoung	setname=$1
2731.1Sdyoung
2741.9Slukem	setdir=$setsdir/lists/$setname
2751.9Slukem	echo $setdir/mi
2761.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2771.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
2781.1Sdyoung		# since the arch-specific one will be more specific than
2791.1Sdyoung		# the cpu-specific one.
2801.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
2811.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
2821.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
2831.11Slukem			echo $setdir/ad.${MACHINE_CPU}
2841.1Sdyoung		fi
2851.1Sdyoung		if [ "$shlib" != "no" -a \
2861.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
2871.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
2881.1Sdyoung		fi
2891.1Sdyoung	fi
2901.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
2911.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
2921.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
2931.11Slukem		echo $setdir/md.${MACHINE}
2941.1Sdyoung	fi
2951.9Slukem	if [ -f $setdir/stl.mi ]; then
2961.9Slukem		echo $setdir/stl.mi
2971.1Sdyoung	fi
2981.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
2991.9Slukem		echo $setdir/stl.${stlib}
3001.1Sdyoung	fi
3011.1Sdyoung	if [ "$shlib" != "no" ]; then
3021.9Slukem		if [ -f $setdir/shl.mi ]; then
3031.9Slukem			echo $setdir/shl.mi
3041.7Sdyoung		fi
3051.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
3061.9Slukem			echo $setdir/shl.${shlib}
3071.7Sdyoung		fi
3081.1Sdyoung	fi
3091.1Sdyoung	if [ "$lkm" != "no" ]; then
3101.9Slukem		if [ -f $setdir/lkm.mi ]; then
3111.9Slukem			echo $setdir/lkm.mi
3121.1Sdyoung		fi
3131.1Sdyoung	fi
3141.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3151.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3161.9Slukem			if [ -f $setdir/gcc.mi ]; then
3171.9Slukem				echo $setdir/gcc.mi
3181.2Smrg			fi
3191.2Smrg			if [ "$shlib" != "no" ]; then
3201.9Slukem				if [ -f $setdir/gcc.shl ]; then
3211.9Slukem					echo $setdir/gcc.shl
3221.2Smrg				fi
3231.2Smrg			fi
3241.2Smrg		else
3251.9Slukem			if [ -f $setdir/tc.mi ]; then
3261.9Slukem				echo $setdir/tc.mi
3271.2Smrg			fi
3281.2Smrg			if [ "$shlib" != "no" ]; then
3291.9Slukem				if [ -f $setdir/tc.shl ]; then
3301.9Slukem					echo $setdir/tc.shl
3311.2Smrg				fi
3321.1Sdyoung			fi
3331.1Sdyoung		fi
3341.1Sdyoung	fi
3351.1Sdyoung
3361.9Slukem	if [ -f $setdir/rescue.mi ]; then
3371.9Slukem		echo $setdir/rescue.mi
3381.1Sdyoung	fi
3391.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3401.11Slukem		echo $setdir/rescue.${MACHINE}
3411.1Sdyoung	fi
3421.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3431.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3441.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3451.1Sdyoung		# specific one will be more specific than the
3461.1Sdyoung		# cpu-specific one.
3471.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3481.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3491.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3501.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3511.1Sdyoung		fi
3521.10Sjmc		if [ "$shlib" != "no" -a \
3531.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3541.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3551.10Sjmc		fi
3561.1Sdyoung	fi
3571.5Sdyoung}
3581.5Sdyoung
3591.9Slukem# arch_to_cpu mach
3601.9Slukem#
3611.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3621.9Slukem# as determined by <bsd.own.mk>.
3631.9Slukem#
3641.8Slukemarch_to_cpu()
3651.8Slukem{
3661.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3671.5Sdyoung.include <bsd.own.mk>
3681.5Sdyoungall:
3691.5Sdyoung	@echo \${MACHINE_CPU}
3701.12SlukemEOMAKE
3711.1Sdyoung}
372