sets.subr revision 1.41
11.41Slukem#	$NetBSD: sets.subr,v 1.41 2005/05/01 07:06: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.36Smatt	MKGCCCMDS	\
361.23Slukem	MKDOC		\
371.32Sscw	MKGDB		\
381.22Slukem	MKHESIOD	\
391.23Slukem	MKINFO		\
401.39Speter	MKIPFILTER	\
411.38Slukem	MKINET6		\
421.22Slukem	MKKERBEROS	\
431.22Slukem	MKKERBEROS4	\
441.22Slukem	MKLINT		\
451.22Slukem	MKMAN		\
461.33Sjmc	MKMANPAGES	\
471.22Slukem	MKMANZ		\
481.23Slukem	MKNLS		\
491.37She	MKPAM		\
501.39Speter	MKPF		\
511.30Smatt	MKPIC		\
521.22Slukem	MKPOSTFIX	\
531.22Slukem	MKPROFILE	\
541.22Slukem	MKSENDMAIL	\
551.24Slukem	MKSHARE		\
561.22Slukem	MKSKEY		\
571.25Slukem	MKUUCP		\
581.40Stron	MKX11		\
591.22Slukem	MKYP		\
601.41Slukem	USE_INET6	\
611.41Slukem	USE_KERBEROS	\
621.41Slukem	USE_YP		\
631.22Slukem"
641.12Slukem
651.9SlukemoIFS=$IFS
661.9SlukemIFS="
671.9Slukem"
681.9Slukemfor x in $(
691.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
701.9Slukem.include <bsd.own.mk>
711.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
721.33SjmcMKMANPAGES=no
731.33Sjmc.else
741.33SjmcMKMANPAGES=yes
751.33Sjmc.endif
761.9Slukemall:
771.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
781.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
791.12Slukem		${MKVARS}
801.12Slukem	@echo "export \$i=\${\$i}"
811.11Slukem.endfor
821.20Slukem.if (\${MKX11:Uno} != "no")
831.20Slukem	@echo x11_version=""
841.35Stron.else
851.9Slukem	@echo x11_version=4
861.9Slukem.endif
871.9Slukem
881.12SlukemEOMAKE
891.9Slukem); do
901.11Slukem#	echo 1>&2 "DEBUG: read $x"
911.9Slukem	eval $x
921.9Slukemdone
931.9SlukemIFS=$oIFS
941.9Slukem
951.34Serhsetsdir=${0%/*}
961.9Slukemnlists="base comp etc games man misc text"
971.9Slukemcase $x11_version in
981.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
991.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
1001.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
1011.20Slukem*)	xlists="" ;;	# unknown!
1021.9Slukemesac
1031.9Slukemobsolete=0
1041.9Slukemlkm=yes
1051.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
1061.9Slukem	lkm=no				# Turn off LKMs for some ports.
1071.9Slukemfi
1081.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1091.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1101.9Slukem	shlib=elf
1111.9Slukemelse
1121.9Slukem	shlib=aout
1131.9Slukemfi
1141.9Slukemstlib=$shlib
1151.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1161.31Sjmcif [ "${MKPIC}" = "no" ]; then
1171.31Sjmc	shlib=no
1181.31Sjmcfi
1191.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1201.9Slukem	shlib=no			# Turn off shlibs for some ports.
1211.9Slukemfi
1221.9Slukem
1231.9Slukem#
1241.9Slukem# list_set_files setfile [...]
1251.1Sdyoung# 
1261.9Slukem# Produce a packing list for setfile(s).
1271.9Slukem# In each file, a record consists of a path and a System Package name,
1281.9Slukem# separated by whitespace. E.g.,
1291.9Slukem#
1301.41Slukem# 	# $NetBSD: sets.subr,v 1.41 2005/05/01 07:06:09 lukem Exp $
1311.9Slukem# 	.			base-sys-root	[keyword[,...]]
1321.9Slukem# 	./altroot		base-sys-root
1331.9Slukem# 	./bin			base-sys-root
1341.9Slukem# 	./bin/[			base-util-root
1351.9Slukem# 	./bin/cat		base-util-root
1361.9Slukem#		[...]
1371.9Slukem#
1381.9Slukem# A # in the first column marks a comment.
1391.9Slukem#
1401.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1411.9Slukem# be printed.
1421.9Slukem#
1431.9Slukem# The third field is an optional comma separated list of keywords to
1441.9Slukem# control if a record is printed; every keyword listed must be enabled
1451.9Slukem# for the record to be printed.  The following keywords are available:
1461.9Slukem#	dummy			dummy entry (ignored)
1471.13Slukem#	obsolete		file is obsolete, and only printed if 
1481.13Slukem#				${obsolete} != 0
1491.13Slukem#
1501.22Slukem#	bfd			${MKBFD} != no
1511.22Slukem#	catpages		${MKCATPAGES} != no
1521.22Slukem#	crypto			${MKCRYPTO} != no
1531.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1541.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1551.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1561.22Slukem#	cvs			${MKCVS} != no
1571.23Slukem#	doc			${MKDOC} != no
1581.36Smatt#	gcccmds			${MKGCCCMDS} != no
1591.32Sscw#	gdb			${MKGDB} != no
1601.22Slukem#	hesiod			${MKHESIOD} != no
1611.23Slukem#	info			${MKINFO} != no
1621.39Speter#	ipfilter		${MKIPFILTER} != no
1631.38Slukem#	inet6			${MKINET6} != no
1641.22Slukem#	kerberos		${MKKERBEROS} != no
1651.22Slukem#	kerberos4		${MKKERBEROS4} != no
1661.22Slukem#	lint			${MKLINT} != no
1671.22Slukem#	man			${MKMAN} != no
1681.22Slukem#	manz			${MKMANZ} != no
1691.23Slukem#	nls			${MKNLS} != no
1701.37She#	pam			${MKPAM} != no
1711.39Speter#	pf			${MKPF} != no
1721.22Slukem#	postfix			${MKPOSTFIX} != no
1731.22Slukem#	profile			${MKPROFILE} != no
1741.22Slukem#	sendmail		${MKSENDMAIL} != no
1751.24Slukem#	share			${MKSHARE} != no
1761.22Slukem#	skey			${MKSKEY} != no
1771.25Slukem#	uucp			${MKUUCP} != no
1781.22Slukem#	yp			${MKYP} != no
1791.22Slukem#
1801.41Slukem#	use_inet6		${USE_INET6} != no
1811.41Slukem#	use_kerberos		${USE_KERBEROS} != no
1821.41Slukem#	use_yp			${USE_YP} != no
1831.41Slukem#
1841.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1851.22Slukem#				  automatically append ".gz" to the filename
1861.22Slukem#
1871.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1881.22Slukem#				  automatically append ".gz" to the filename
1891.1Sdyoung#
1901.8Slukemlist_set_files()
1911.8Slukem{
1921.1Sdyoung	for setname; do
1931.1Sdyoung		list_set_lists $setname
1941.9Slukem	done | xargs cat | \
1951.11Slukem	awk -v obsolete=${obsolete} '
1961.9Slukem		BEGIN {
1971.9Slukem			if (! obsolete) {
1981.12Slukem				split("'"${MKVARS}"'", needvars)
1991.9Slukem				for (vi in needvars) {
2001.9Slukem					nv = needvars[vi]
2011.41Slukem					kw = tolower(nv)
2021.41Slukem					sub(/^mk/, "", kw)
2031.12Slukem					if (ENVIRON[nv] != "no")
2041.12Slukem						wanted[kw] = 1 
2051.9Slukem				}
2061.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
2071.22Slukem					wanted[".cat"] = 1
2081.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
2091.22Slukem					wanted[".man"] = 1
2101.9Slukem			}
2111.9Slukem		}
2121.9Slukem
2131.9Slukem		/^#/ {
2141.9Slukem			next;
2151.9Slukem		}
2161.9Slukem
2171.9Slukem		NF > 2 && $3 != "-" {
2181.9Slukem			split($3, keywords, ",")
2191.9Slukem			show = 1
2201.9Slukem			for (ki in keywords) {
2211.9Slukem				kw = keywords[ki]
2221.9Slukem				if (kw == "obsolete") {
2231.9Slukem					if (obsolete)
2241.9Slukem						print
2251.9Slukem					next
2261.9Slukem				}
2271.22Slukem				if (("manz" in wanted) &&
2281.22Slukem				    (kw == ".cat" || kw == ".man"))
2291.22Slukem					$1 = $1 ".gz"
2301.9Slukem				if (! (kw in wanted))
2311.9Slukem					show = 0
2321.9Slukem			}
2331.9Slukem			if (show)
2341.9Slukem				print
2351.9Slukem			next
2361.9Slukem		}
2371.9Slukem
2381.9Slukem		{
2391.9Slukem			if (! obsolete)
2401.9Slukem				print
2411.9Slukem		}'
2421.9Slukem
2431.1Sdyoung}
2441.1Sdyoung
2451.1Sdyoung#
2461.1Sdyoung# list_set_lists setname
2471.1Sdyoung# 
2481.1Sdyoung# Print to stdout a list of files, one filename per line, which
2491.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2501.1Sdyoung#
2511.1Sdyoung# 	.../lists/base/mi
2521.1Sdyoung# 	.../lists/base/rescue.mi
2531.1Sdyoung# 	.../lists/base/md.i386
2541.9Slukem#		[...]
2551.1Sdyoung#
2561.9Slukem# For a given setname $set, the following files may be selected from
2571.9Slukem# .../list/$set:
2581.9Slukem#	mi
2591.11Slukem#	ad.${MACHINE_ARCH}
2601.11Slukem# (or)	ad.${MACHINE_CPU}
2611.11Slukem#	ad.${MACHINE_CPU}.shl
2621.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2631.11Slukem# (or)	md.${MACHINE}
2641.9Slukem#	stl.mi
2651.9Slukem#	stl.stlib
2661.9Slukem#	shl.mi
2671.9Slukem#	shl.shlib
2681.9Slukem#	lkm.mi			if ${lkm} != no
2691.9Slukem#	gcc.mi
2701.9Slukem#	gcc.shl
2711.9Slukem#	tc.mi
2721.9Slukem#	tc.shl
2731.9Slukem#	rescue.shl
2741.11Slukem#	rescue.${MACHINE}
2751.11Slukem#	rescue.ad.${MACHINE_ARCH}
2761.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2771.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2781.1Sdyoung#
2791.9Slukem# Environment:
2801.1Sdyoung# 	shlib
2811.1Sdyoung# 	stlib
2821.1Sdyoung#
2831.8Slukemlist_set_lists()
2841.8Slukem{
2851.1Sdyoung	setname=$1
2861.1Sdyoung
2871.9Slukem	setdir=$setsdir/lists/$setname
2881.9Slukem	echo $setdir/mi
2891.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2901.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
2911.1Sdyoung		# since the arch-specific one will be more specific than
2921.1Sdyoung		# the cpu-specific one.
2931.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
2941.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
2951.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
2961.11Slukem			echo $setdir/ad.${MACHINE_CPU}
2971.1Sdyoung		fi
2981.1Sdyoung		if [ "$shlib" != "no" -a \
2991.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
3001.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
3011.1Sdyoung		fi
3021.1Sdyoung	fi
3031.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
3041.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
3051.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
3061.11Slukem		echo $setdir/md.${MACHINE}
3071.1Sdyoung	fi
3081.9Slukem	if [ -f $setdir/stl.mi ]; then
3091.9Slukem		echo $setdir/stl.mi
3101.1Sdyoung	fi
3111.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
3121.9Slukem		echo $setdir/stl.${stlib}
3131.1Sdyoung	fi
3141.1Sdyoung	if [ "$shlib" != "no" ]; then
3151.9Slukem		if [ -f $setdir/shl.mi ]; then
3161.9Slukem			echo $setdir/shl.mi
3171.7Sdyoung		fi
3181.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
3191.9Slukem			echo $setdir/shl.${shlib}
3201.7Sdyoung		fi
3211.1Sdyoung	fi
3221.1Sdyoung	if [ "$lkm" != "no" ]; then
3231.9Slukem		if [ -f $setdir/lkm.mi ]; then
3241.9Slukem			echo $setdir/lkm.mi
3251.1Sdyoung		fi
3261.1Sdyoung	fi
3271.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3281.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3291.9Slukem			if [ -f $setdir/gcc.mi ]; then
3301.9Slukem				echo $setdir/gcc.mi
3311.2Smrg			fi
3321.2Smrg			if [ "$shlib" != "no" ]; then
3331.9Slukem				if [ -f $setdir/gcc.shl ]; then
3341.9Slukem					echo $setdir/gcc.shl
3351.2Smrg				fi
3361.2Smrg			fi
3371.2Smrg		else
3381.9Slukem			if [ -f $setdir/tc.mi ]; then
3391.9Slukem				echo $setdir/tc.mi
3401.2Smrg			fi
3411.2Smrg			if [ "$shlib" != "no" ]; then
3421.9Slukem				if [ -f $setdir/tc.shl ]; then
3431.9Slukem					echo $setdir/tc.shl
3441.2Smrg				fi
3451.1Sdyoung			fi
3461.1Sdyoung		fi
3471.1Sdyoung	fi
3481.1Sdyoung
3491.9Slukem	if [ -f $setdir/rescue.mi ]; then
3501.9Slukem		echo $setdir/rescue.mi
3511.1Sdyoung	fi
3521.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3531.11Slukem		echo $setdir/rescue.${MACHINE}
3541.1Sdyoung	fi
3551.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3561.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3571.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3581.1Sdyoung		# specific one will be more specific than the
3591.1Sdyoung		# cpu-specific one.
3601.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3611.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3621.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3631.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3641.1Sdyoung		fi
3651.10Sjmc		if [ "$shlib" != "no" -a \
3661.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3671.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3681.10Sjmc		fi
3691.1Sdyoung	fi
3701.5Sdyoung}
3711.5Sdyoung
3721.9Slukem# arch_to_cpu mach
3731.9Slukem#
3741.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3751.9Slukem# as determined by <bsd.own.mk>.
3761.9Slukem#
3771.8Slukemarch_to_cpu()
3781.8Slukem{
3791.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3801.5Sdyoung.include <bsd.own.mk>
3811.5Sdyoungall:
3821.5Sdyoung	@echo \${MACHINE_CPU}
3831.12SlukemEOMAKE
3841.1Sdyoung}
385