sets.subr revision 1.42
11.42Sapb#	$NetBSD: sets.subr,v 1.42 2006/01/03 15:42:42 apb 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.42Sapb#
651.42Sapb# The following variables refer to tools that are used when building sets:
661.42Sapb#
671.42Sapb: ${CKSUM:=cksum}
681.42Sapb: ${HOST_SH:=sh}
691.42Sapb: ${MKTEMP:=mktemp}
701.42Sapb: ${MTREE:=/usr/sbin/mtree}
711.42Sapb: ${PAX:=pax}
721.42Sapb: ${TOOL_DB:=db}
731.12Slukem
741.9SlukemoIFS=$IFS
751.9SlukemIFS="
761.9Slukem"
771.9Slukemfor x in $(
781.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
791.9Slukem.include <bsd.own.mk>
801.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
811.33SjmcMKMANPAGES=no
821.33Sjmc.else
831.33SjmcMKMANPAGES=yes
841.33Sjmc.endif
851.9Slukemall:
861.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
871.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
881.12Slukem		${MKVARS}
891.12Slukem	@echo "export \$i=\${\$i}"
901.11Slukem.endfor
911.20Slukem.if (\${MKX11:Uno} != "no")
921.20Slukem	@echo x11_version=""
931.35Stron.else
941.9Slukem	@echo x11_version=4
951.9Slukem.endif
961.9Slukem
971.12SlukemEOMAKE
981.9Slukem); do
991.11Slukem#	echo 1>&2 "DEBUG: read $x"
1001.9Slukem	eval $x
1011.9Slukemdone
1021.9SlukemIFS=$oIFS
1031.9Slukem
1041.34Serhsetsdir=${0%/*}
1051.9Slukemnlists="base comp etc games man misc text"
1061.9Slukemcase $x11_version in
1071.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
1081.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
1091.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
1101.20Slukem*)	xlists="" ;;	# unknown!
1111.9Slukemesac
1121.9Slukemobsolete=0
1131.9Slukemlkm=yes
1141.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
1151.9Slukem	lkm=no				# Turn off LKMs for some ports.
1161.9Slukemfi
1171.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1181.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1191.9Slukem	shlib=elf
1201.9Slukemelse
1211.9Slukem	shlib=aout
1221.9Slukemfi
1231.9Slukemstlib=$shlib
1241.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1251.31Sjmcif [ "${MKPIC}" = "no" ]; then
1261.31Sjmc	shlib=no
1271.31Sjmcfi
1281.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1291.9Slukem	shlib=no			# Turn off shlibs for some ports.
1301.9Slukemfi
1311.9Slukem
1321.9Slukem#
1331.9Slukem# list_set_files setfile [...]
1341.1Sdyoung# 
1351.9Slukem# Produce a packing list for setfile(s).
1361.9Slukem# In each file, a record consists of a path and a System Package name,
1371.9Slukem# separated by whitespace. E.g.,
1381.9Slukem#
1391.42Sapb# 	# $NetBSD: sets.subr,v 1.42 2006/01/03 15:42:42 apb Exp $
1401.9Slukem# 	.			base-sys-root	[keyword[,...]]
1411.9Slukem# 	./altroot		base-sys-root
1421.9Slukem# 	./bin			base-sys-root
1431.9Slukem# 	./bin/[			base-util-root
1441.9Slukem# 	./bin/cat		base-util-root
1451.9Slukem#		[...]
1461.9Slukem#
1471.9Slukem# A # in the first column marks a comment.
1481.9Slukem#
1491.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1501.9Slukem# be printed.
1511.9Slukem#
1521.9Slukem# The third field is an optional comma separated list of keywords to
1531.9Slukem# control if a record is printed; every keyword listed must be enabled
1541.9Slukem# for the record to be printed.  The following keywords are available:
1551.9Slukem#	dummy			dummy entry (ignored)
1561.13Slukem#	obsolete		file is obsolete, and only printed if 
1571.13Slukem#				${obsolete} != 0
1581.13Slukem#
1591.22Slukem#	bfd			${MKBFD} != no
1601.22Slukem#	catpages		${MKCATPAGES} != no
1611.22Slukem#	crypto			${MKCRYPTO} != no
1621.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1631.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1641.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1651.22Slukem#	cvs			${MKCVS} != no
1661.23Slukem#	doc			${MKDOC} != no
1671.36Smatt#	gcccmds			${MKGCCCMDS} != no
1681.32Sscw#	gdb			${MKGDB} != no
1691.22Slukem#	hesiod			${MKHESIOD} != no
1701.23Slukem#	info			${MKINFO} != no
1711.39Speter#	ipfilter		${MKIPFILTER} != no
1721.38Slukem#	inet6			${MKINET6} != no
1731.22Slukem#	kerberos		${MKKERBEROS} != no
1741.22Slukem#	kerberos4		${MKKERBEROS4} != no
1751.22Slukem#	lint			${MKLINT} != no
1761.22Slukem#	man			${MKMAN} != no
1771.22Slukem#	manz			${MKMANZ} != no
1781.23Slukem#	nls			${MKNLS} != no
1791.37She#	pam			${MKPAM} != no
1801.39Speter#	pf			${MKPF} != no
1811.22Slukem#	postfix			${MKPOSTFIX} != no
1821.22Slukem#	profile			${MKPROFILE} != no
1831.22Slukem#	sendmail		${MKSENDMAIL} != no
1841.24Slukem#	share			${MKSHARE} != no
1851.22Slukem#	skey			${MKSKEY} != no
1861.25Slukem#	uucp			${MKUUCP} != no
1871.22Slukem#	yp			${MKYP} != no
1881.22Slukem#
1891.41Slukem#	use_inet6		${USE_INET6} != no
1901.41Slukem#	use_kerberos		${USE_KERBEROS} != no
1911.41Slukem#	use_yp			${USE_YP} != no
1921.41Slukem#
1931.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1941.22Slukem#				  automatically append ".gz" to the filename
1951.22Slukem#
1961.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1971.22Slukem#				  automatically append ".gz" to the filename
1981.1Sdyoung#
1991.8Slukemlist_set_files()
2001.8Slukem{
2011.1Sdyoung	for setname; do
2021.1Sdyoung		list_set_lists $setname
2031.9Slukem	done | xargs cat | \
2041.11Slukem	awk -v obsolete=${obsolete} '
2051.9Slukem		BEGIN {
2061.9Slukem			if (! obsolete) {
2071.12Slukem				split("'"${MKVARS}"'", needvars)
2081.9Slukem				for (vi in needvars) {
2091.9Slukem					nv = needvars[vi]
2101.41Slukem					kw = tolower(nv)
2111.41Slukem					sub(/^mk/, "", kw)
2121.12Slukem					if (ENVIRON[nv] != "no")
2131.12Slukem						wanted[kw] = 1 
2141.9Slukem				}
2151.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
2161.22Slukem					wanted[".cat"] = 1
2171.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
2181.22Slukem					wanted[".man"] = 1
2191.9Slukem			}
2201.9Slukem		}
2211.9Slukem
2221.9Slukem		/^#/ {
2231.9Slukem			next;
2241.9Slukem		}
2251.9Slukem
2261.9Slukem		NF > 2 && $3 != "-" {
2271.9Slukem			split($3, keywords, ",")
2281.9Slukem			show = 1
2291.9Slukem			for (ki in keywords) {
2301.9Slukem				kw = keywords[ki]
2311.9Slukem				if (kw == "obsolete") {
2321.9Slukem					if (obsolete)
2331.9Slukem						print
2341.9Slukem					next
2351.9Slukem				}
2361.22Slukem				if (("manz" in wanted) &&
2371.22Slukem				    (kw == ".cat" || kw == ".man"))
2381.22Slukem					$1 = $1 ".gz"
2391.9Slukem				if (! (kw in wanted))
2401.9Slukem					show = 0
2411.9Slukem			}
2421.9Slukem			if (show)
2431.9Slukem				print
2441.9Slukem			next
2451.9Slukem		}
2461.9Slukem
2471.9Slukem		{
2481.9Slukem			if (! obsolete)
2491.9Slukem				print
2501.9Slukem		}'
2511.9Slukem
2521.1Sdyoung}
2531.1Sdyoung
2541.1Sdyoung#
2551.1Sdyoung# list_set_lists setname
2561.1Sdyoung# 
2571.1Sdyoung# Print to stdout a list of files, one filename per line, which
2581.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2591.1Sdyoung#
2601.1Sdyoung# 	.../lists/base/mi
2611.1Sdyoung# 	.../lists/base/rescue.mi
2621.1Sdyoung# 	.../lists/base/md.i386
2631.9Slukem#		[...]
2641.1Sdyoung#
2651.9Slukem# For a given setname $set, the following files may be selected from
2661.9Slukem# .../list/$set:
2671.9Slukem#	mi
2681.11Slukem#	ad.${MACHINE_ARCH}
2691.11Slukem# (or)	ad.${MACHINE_CPU}
2701.11Slukem#	ad.${MACHINE_CPU}.shl
2711.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2721.11Slukem# (or)	md.${MACHINE}
2731.9Slukem#	stl.mi
2741.9Slukem#	stl.stlib
2751.9Slukem#	shl.mi
2761.9Slukem#	shl.shlib
2771.9Slukem#	lkm.mi			if ${lkm} != no
2781.9Slukem#	gcc.mi
2791.9Slukem#	gcc.shl
2801.9Slukem#	tc.mi
2811.9Slukem#	tc.shl
2821.9Slukem#	rescue.shl
2831.11Slukem#	rescue.${MACHINE}
2841.11Slukem#	rescue.ad.${MACHINE_ARCH}
2851.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2861.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2871.1Sdyoung#
2881.9Slukem# Environment:
2891.1Sdyoung# 	shlib
2901.1Sdyoung# 	stlib
2911.1Sdyoung#
2921.8Slukemlist_set_lists()
2931.8Slukem{
2941.1Sdyoung	setname=$1
2951.1Sdyoung
2961.9Slukem	setdir=$setsdir/lists/$setname
2971.9Slukem	echo $setdir/mi
2981.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2991.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
3001.1Sdyoung		# since the arch-specific one will be more specific than
3011.1Sdyoung		# the cpu-specific one.
3021.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
3031.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
3041.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
3051.11Slukem			echo $setdir/ad.${MACHINE_CPU}
3061.1Sdyoung		fi
3071.1Sdyoung		if [ "$shlib" != "no" -a \
3081.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
3091.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
3101.1Sdyoung		fi
3111.1Sdyoung	fi
3121.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
3131.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
3141.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
3151.11Slukem		echo $setdir/md.${MACHINE}
3161.1Sdyoung	fi
3171.9Slukem	if [ -f $setdir/stl.mi ]; then
3181.9Slukem		echo $setdir/stl.mi
3191.1Sdyoung	fi
3201.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
3211.9Slukem		echo $setdir/stl.${stlib}
3221.1Sdyoung	fi
3231.1Sdyoung	if [ "$shlib" != "no" ]; then
3241.9Slukem		if [ -f $setdir/shl.mi ]; then
3251.9Slukem			echo $setdir/shl.mi
3261.7Sdyoung		fi
3271.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
3281.9Slukem			echo $setdir/shl.${shlib}
3291.7Sdyoung		fi
3301.1Sdyoung	fi
3311.1Sdyoung	if [ "$lkm" != "no" ]; then
3321.9Slukem		if [ -f $setdir/lkm.mi ]; then
3331.9Slukem			echo $setdir/lkm.mi
3341.1Sdyoung		fi
3351.1Sdyoung	fi
3361.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3371.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3381.9Slukem			if [ -f $setdir/gcc.mi ]; then
3391.9Slukem				echo $setdir/gcc.mi
3401.2Smrg			fi
3411.2Smrg			if [ "$shlib" != "no" ]; then
3421.9Slukem				if [ -f $setdir/gcc.shl ]; then
3431.9Slukem					echo $setdir/gcc.shl
3441.2Smrg				fi
3451.2Smrg			fi
3461.2Smrg		else
3471.9Slukem			if [ -f $setdir/tc.mi ]; then
3481.9Slukem				echo $setdir/tc.mi
3491.2Smrg			fi
3501.2Smrg			if [ "$shlib" != "no" ]; then
3511.9Slukem				if [ -f $setdir/tc.shl ]; then
3521.9Slukem					echo $setdir/tc.shl
3531.2Smrg				fi
3541.1Sdyoung			fi
3551.1Sdyoung		fi
3561.1Sdyoung	fi
3571.1Sdyoung
3581.9Slukem	if [ -f $setdir/rescue.mi ]; then
3591.9Slukem		echo $setdir/rescue.mi
3601.1Sdyoung	fi
3611.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3621.11Slukem		echo $setdir/rescue.${MACHINE}
3631.1Sdyoung	fi
3641.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3651.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3661.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3671.1Sdyoung		# specific one will be more specific than the
3681.1Sdyoung		# cpu-specific one.
3691.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3701.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3711.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3721.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3731.1Sdyoung		fi
3741.10Sjmc		if [ "$shlib" != "no" -a \
3751.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3761.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3771.10Sjmc		fi
3781.1Sdyoung	fi
3791.5Sdyoung}
3801.5Sdyoung
3811.9Slukem# arch_to_cpu mach
3821.9Slukem#
3831.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3841.9Slukem# as determined by <bsd.own.mk>.
3851.9Slukem#
3861.8Slukemarch_to_cpu()
3871.8Slukem{
3881.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3891.5Sdyoung.include <bsd.own.mk>
3901.5Sdyoungall:
3911.5Sdyoung	@echo \${MACHINE_CPU}
3921.12SlukemEOMAKE
3931.1Sdyoung}
394