sets.subr revision 1.40
11.40Stron#	$NetBSD: sets.subr,v 1.40 2005/03/22 09:28:24 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.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.22Slukem"
611.12Slukem
621.9SlukemoIFS=$IFS
631.9SlukemIFS="
641.9Slukem"
651.9Slukemfor x in $(
661.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
671.9Slukem.include <bsd.own.mk>
681.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
691.33SjmcMKMANPAGES=no
701.33Sjmc.else
711.33SjmcMKMANPAGES=yes
721.33Sjmc.endif
731.9Slukemall:
741.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
751.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
761.12Slukem		${MKVARS}
771.12Slukem	@echo "export \$i=\${\$i}"
781.11Slukem.endfor
791.20Slukem.if (\${MKX11:Uno} != "no")
801.20Slukem	@echo x11_version=""
811.35Stron.else
821.9Slukem	@echo x11_version=4
831.9Slukem.endif
841.9Slukem
851.12SlukemEOMAKE
861.9Slukem); do
871.11Slukem#	echo 1>&2 "DEBUG: read $x"
881.9Slukem	eval $x
891.9Slukemdone
901.9SlukemIFS=$oIFS
911.9Slukem
921.34Serhsetsdir=${0%/*}
931.9Slukemnlists="base comp etc games man misc text"
941.9Slukemcase $x11_version in
951.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
961.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
971.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
981.20Slukem*)	xlists="" ;;	# unknown!
991.9Slukemesac
1001.9Slukemobsolete=0
1011.9Slukemlkm=yes
1021.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
1031.9Slukem	lkm=no				# Turn off LKMs for some ports.
1041.9Slukemfi
1051.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1061.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1071.9Slukem	shlib=elf
1081.9Slukemelse
1091.9Slukem	shlib=aout
1101.9Slukemfi
1111.9Slukemstlib=$shlib
1121.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1131.31Sjmcif [ "${MKPIC}" = "no" ]; then
1141.31Sjmc	shlib=no
1151.31Sjmcfi
1161.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1171.9Slukem	shlib=no			# Turn off shlibs for some ports.
1181.9Slukemfi
1191.9Slukem
1201.9Slukem#
1211.9Slukem# list_set_files setfile [...]
1221.1Sdyoung# 
1231.9Slukem# Produce a packing list for setfile(s).
1241.9Slukem# In each file, a record consists of a path and a System Package name,
1251.9Slukem# separated by whitespace. E.g.,
1261.9Slukem#
1271.40Stron# 	# $NetBSD: sets.subr,v 1.40 2005/03/22 09:28:24 tron Exp $
1281.9Slukem# 	.			base-sys-root	[keyword[,...]]
1291.9Slukem# 	./altroot		base-sys-root
1301.9Slukem# 	./bin			base-sys-root
1311.9Slukem# 	./bin/[			base-util-root
1321.9Slukem# 	./bin/cat		base-util-root
1331.9Slukem#		[...]
1341.9Slukem#
1351.9Slukem# A # in the first column marks a comment.
1361.9Slukem#
1371.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1381.9Slukem# be printed.
1391.9Slukem#
1401.9Slukem# The third field is an optional comma separated list of keywords to
1411.9Slukem# control if a record is printed; every keyword listed must be enabled
1421.9Slukem# for the record to be printed.  The following keywords are available:
1431.9Slukem#	dummy			dummy entry (ignored)
1441.13Slukem#	obsolete		file is obsolete, and only printed if 
1451.13Slukem#				${obsolete} != 0
1461.13Slukem#
1471.22Slukem#	bfd			${MKBFD} != no
1481.22Slukem#	catpages		${MKCATPAGES} != no
1491.22Slukem#	crypto			${MKCRYPTO} != no
1501.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1511.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1521.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1531.22Slukem#	cvs			${MKCVS} != no
1541.23Slukem#	doc			${MKDOC} != no
1551.36Smatt#	gcccmds			${MKGCCCMDS} != no
1561.32Sscw#	gdb			${MKGDB} != no
1571.22Slukem#	hesiod			${MKHESIOD} != no
1581.23Slukem#	info			${MKINFO} != no
1591.39Speter#	ipfilter		${MKIPFILTER} != no
1601.38Slukem#	inet6			${MKINET6} != no
1611.22Slukem#	kerberos		${MKKERBEROS} != no
1621.22Slukem#	kerberos4		${MKKERBEROS4} != no
1631.22Slukem#	lint			${MKLINT} != no
1641.22Slukem#	man			${MKMAN} != no
1651.22Slukem#	manz			${MKMANZ} != no
1661.23Slukem#	nls			${MKNLS} != no
1671.37She#	pam			${MKPAM} != no
1681.39Speter#	pf			${MKPF} != no
1691.22Slukem#	postfix			${MKPOSTFIX} != no
1701.22Slukem#	profile			${MKPROFILE} != no
1711.22Slukem#	sendmail		${MKSENDMAIL} != no
1721.24Slukem#	share			${MKSHARE} != no
1731.22Slukem#	skey			${MKSKEY} != no
1741.25Slukem#	uucp			${MKUUCP} != no
1751.22Slukem#	yp			${MKYP} != no
1761.22Slukem#
1771.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1781.22Slukem#				  automatically append ".gz" to the filename
1791.22Slukem#
1801.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1811.22Slukem#				  automatically append ".gz" to the filename
1821.1Sdyoung#
1831.8Slukemlist_set_files()
1841.8Slukem{
1851.1Sdyoung	for setname; do
1861.1Sdyoung		list_set_lists $setname
1871.9Slukem	done | xargs cat | \
1881.11Slukem	awk -v obsolete=${obsolete} '
1891.9Slukem		BEGIN {
1901.9Slukem			if (! obsolete) {
1911.12Slukem				split("'"${MKVARS}"'", needvars)
1921.9Slukem				for (vi in needvars) {
1931.9Slukem					nv = needvars[vi]
1941.12Slukem					kw = tolower(substr(nv, 3))
1951.12Slukem					if (ENVIRON[nv] != "no")
1961.12Slukem						wanted[kw] = 1 
1971.9Slukem				}
1981.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
1991.22Slukem					wanted[".cat"] = 1
2001.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
2011.22Slukem					wanted[".man"] = 1
2021.9Slukem			}
2031.9Slukem		}
2041.9Slukem
2051.9Slukem		/^#/ {
2061.9Slukem			next;
2071.9Slukem		}
2081.9Slukem
2091.9Slukem		NF > 2 && $3 != "-" {
2101.9Slukem			split($3, keywords, ",")
2111.9Slukem			show = 1
2121.9Slukem			for (ki in keywords) {
2131.9Slukem				kw = keywords[ki]
2141.9Slukem				if (kw == "obsolete") {
2151.9Slukem					if (obsolete)
2161.9Slukem						print
2171.9Slukem					next
2181.9Slukem				}
2191.22Slukem				if (("manz" in wanted) &&
2201.22Slukem				    (kw == ".cat" || kw == ".man"))
2211.22Slukem					$1 = $1 ".gz"
2221.9Slukem				if (! (kw in wanted))
2231.9Slukem					show = 0
2241.9Slukem			}
2251.9Slukem			if (show)
2261.9Slukem				print
2271.9Slukem			next
2281.9Slukem		}
2291.9Slukem
2301.9Slukem		{
2311.9Slukem			if (! obsolete)
2321.9Slukem				print
2331.9Slukem		}'
2341.9Slukem
2351.1Sdyoung}
2361.1Sdyoung
2371.1Sdyoung#
2381.1Sdyoung# list_set_lists setname
2391.1Sdyoung# 
2401.1Sdyoung# Print to stdout a list of files, one filename per line, which
2411.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2421.1Sdyoung#
2431.1Sdyoung# 	.../lists/base/mi
2441.1Sdyoung# 	.../lists/base/rescue.mi
2451.1Sdyoung# 	.../lists/base/md.i386
2461.9Slukem#		[...]
2471.1Sdyoung#
2481.9Slukem# For a given setname $set, the following files may be selected from
2491.9Slukem# .../list/$set:
2501.9Slukem#	mi
2511.11Slukem#	ad.${MACHINE_ARCH}
2521.11Slukem# (or)	ad.${MACHINE_CPU}
2531.11Slukem#	ad.${MACHINE_CPU}.shl
2541.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2551.11Slukem# (or)	md.${MACHINE}
2561.9Slukem#	stl.mi
2571.9Slukem#	stl.stlib
2581.9Slukem#	shl.mi
2591.9Slukem#	shl.shlib
2601.9Slukem#	lkm.mi			if ${lkm} != no
2611.9Slukem#	gcc.mi
2621.9Slukem#	gcc.shl
2631.9Slukem#	tc.mi
2641.9Slukem#	tc.shl
2651.9Slukem#	rescue.shl
2661.11Slukem#	rescue.${MACHINE}
2671.11Slukem#	rescue.ad.${MACHINE_ARCH}
2681.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2691.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2701.1Sdyoung#
2711.9Slukem# Environment:
2721.1Sdyoung# 	shlib
2731.1Sdyoung# 	stlib
2741.1Sdyoung#
2751.8Slukemlist_set_lists()
2761.8Slukem{
2771.1Sdyoung	setname=$1
2781.1Sdyoung
2791.9Slukem	setdir=$setsdir/lists/$setname
2801.9Slukem	echo $setdir/mi
2811.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2821.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
2831.1Sdyoung		# since the arch-specific one will be more specific than
2841.1Sdyoung		# the cpu-specific one.
2851.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
2861.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
2871.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
2881.11Slukem			echo $setdir/ad.${MACHINE_CPU}
2891.1Sdyoung		fi
2901.1Sdyoung		if [ "$shlib" != "no" -a \
2911.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
2921.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
2931.1Sdyoung		fi
2941.1Sdyoung	fi
2951.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
2961.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
2971.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
2981.11Slukem		echo $setdir/md.${MACHINE}
2991.1Sdyoung	fi
3001.9Slukem	if [ -f $setdir/stl.mi ]; then
3011.9Slukem		echo $setdir/stl.mi
3021.1Sdyoung	fi
3031.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
3041.9Slukem		echo $setdir/stl.${stlib}
3051.1Sdyoung	fi
3061.1Sdyoung	if [ "$shlib" != "no" ]; then
3071.9Slukem		if [ -f $setdir/shl.mi ]; then
3081.9Slukem			echo $setdir/shl.mi
3091.7Sdyoung		fi
3101.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
3111.9Slukem			echo $setdir/shl.${shlib}
3121.7Sdyoung		fi
3131.1Sdyoung	fi
3141.1Sdyoung	if [ "$lkm" != "no" ]; then
3151.9Slukem		if [ -f $setdir/lkm.mi ]; then
3161.9Slukem			echo $setdir/lkm.mi
3171.1Sdyoung		fi
3181.1Sdyoung	fi
3191.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3201.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3211.9Slukem			if [ -f $setdir/gcc.mi ]; then
3221.9Slukem				echo $setdir/gcc.mi
3231.2Smrg			fi
3241.2Smrg			if [ "$shlib" != "no" ]; then
3251.9Slukem				if [ -f $setdir/gcc.shl ]; then
3261.9Slukem					echo $setdir/gcc.shl
3271.2Smrg				fi
3281.2Smrg			fi
3291.2Smrg		else
3301.9Slukem			if [ -f $setdir/tc.mi ]; then
3311.9Slukem				echo $setdir/tc.mi
3321.2Smrg			fi
3331.2Smrg			if [ "$shlib" != "no" ]; then
3341.9Slukem				if [ -f $setdir/tc.shl ]; then
3351.9Slukem					echo $setdir/tc.shl
3361.2Smrg				fi
3371.1Sdyoung			fi
3381.1Sdyoung		fi
3391.1Sdyoung	fi
3401.1Sdyoung
3411.9Slukem	if [ -f $setdir/rescue.mi ]; then
3421.9Slukem		echo $setdir/rescue.mi
3431.1Sdyoung	fi
3441.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3451.11Slukem		echo $setdir/rescue.${MACHINE}
3461.1Sdyoung	fi
3471.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3481.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3491.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3501.1Sdyoung		# specific one will be more specific than the
3511.1Sdyoung		# cpu-specific one.
3521.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3531.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3541.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3551.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3561.1Sdyoung		fi
3571.10Sjmc		if [ "$shlib" != "no" -a \
3581.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3591.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3601.10Sjmc		fi
3611.1Sdyoung	fi
3621.5Sdyoung}
3631.5Sdyoung
3641.9Slukem# arch_to_cpu mach
3651.9Slukem#
3661.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3671.9Slukem# as determined by <bsd.own.mk>.
3681.9Slukem#
3691.8Slukemarch_to_cpu()
3701.8Slukem{
3711.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3721.5Sdyoung.include <bsd.own.mk>
3731.5Sdyoungall:
3741.5Sdyoung	@echo \${MACHINE_CPU}
3751.12SlukemEOMAKE
3761.1Sdyoung}
377