sets.subr revision 1.39
11.39Speter#	$NetBSD: sets.subr,v 1.39 2005/02/22 14:39:58 peter 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.22Slukem	MKYP		\
591.22Slukem"
601.12Slukem
611.9SlukemoIFS=$IFS
621.9SlukemIFS="
631.9Slukem"
641.9Slukemfor x in $(
651.12Slukem${MAKE:-make} -B -f- all <<EOMAKE
661.9Slukem.include <bsd.own.mk>
671.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
681.33SjmcMKMANPAGES=no
691.33Sjmc.else
701.33SjmcMKMANPAGES=yes
711.33Sjmc.endif
721.9Slukemall:
731.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
741.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
751.12Slukem		${MKVARS}
761.12Slukem	@echo "export \$i=\${\$i}"
771.11Slukem.endfor
781.20Slukem.if (\${MKX11:Uno} != "no")
791.20Slukem	@echo x11_version=""
801.35Stron.else
811.9Slukem	@echo x11_version=4
821.9Slukem.endif
831.9Slukem
841.12SlukemEOMAKE
851.9Slukem); do
861.11Slukem#	echo 1>&2 "DEBUG: read $x"
871.9Slukem	eval $x
881.9Slukemdone
891.9SlukemIFS=$oIFS
901.9Slukem
911.34Serhsetsdir=${0%/*}
921.9Slukemnlists="base comp etc games man misc text"
931.9Slukemcase $x11_version in
941.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
951.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
961.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
971.20Slukem*)	xlists="" ;;	# unknown!
981.9Slukemesac
991.9Slukemobsolete=0
1001.9Slukemlkm=yes
1011.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
1021.9Slukem	lkm=no				# Turn off LKMs for some ports.
1031.9Slukemfi
1041.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1051.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1061.9Slukem	shlib=elf
1071.9Slukemelse
1081.9Slukem	shlib=aout
1091.9Slukemfi
1101.9Slukemstlib=$shlib
1111.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1121.31Sjmcif [ "${MKPIC}" = "no" ]; then
1131.31Sjmc	shlib=no
1141.31Sjmcfi
1151.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1161.9Slukem	shlib=no			# Turn off shlibs for some ports.
1171.9Slukemfi
1181.9Slukem
1191.9Slukem#
1201.9Slukem# list_set_files setfile [...]
1211.1Sdyoung# 
1221.9Slukem# Produce a packing list for setfile(s).
1231.9Slukem# In each file, a record consists of a path and a System Package name,
1241.9Slukem# separated by whitespace. E.g.,
1251.9Slukem#
1261.39Speter# 	# $NetBSD: sets.subr,v 1.39 2005/02/22 14:39:58 peter Exp $
1271.9Slukem# 	.			base-sys-root	[keyword[,...]]
1281.9Slukem# 	./altroot		base-sys-root
1291.9Slukem# 	./bin			base-sys-root
1301.9Slukem# 	./bin/[			base-util-root
1311.9Slukem# 	./bin/cat		base-util-root
1321.9Slukem#		[...]
1331.9Slukem#
1341.9Slukem# A # in the first column marks a comment.
1351.9Slukem#
1361.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1371.9Slukem# be printed.
1381.9Slukem#
1391.9Slukem# The third field is an optional comma separated list of keywords to
1401.9Slukem# control if a record is printed; every keyword listed must be enabled
1411.9Slukem# for the record to be printed.  The following keywords are available:
1421.9Slukem#	dummy			dummy entry (ignored)
1431.13Slukem#	obsolete		file is obsolete, and only printed if 
1441.13Slukem#				${obsolete} != 0
1451.13Slukem#
1461.22Slukem#	bfd			${MKBFD} != no
1471.22Slukem#	catpages		${MKCATPAGES} != no
1481.22Slukem#	crypto			${MKCRYPTO} != no
1491.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1501.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1511.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1521.22Slukem#	cvs			${MKCVS} != no
1531.23Slukem#	doc			${MKDOC} != no
1541.36Smatt#	gcccmds			${MKGCCCMDS} != no
1551.32Sscw#	gdb			${MKGDB} != no
1561.22Slukem#	hesiod			${MKHESIOD} != no
1571.23Slukem#	info			${MKINFO} != no
1581.39Speter#	ipfilter		${MKIPFILTER} != no
1591.38Slukem#	inet6			${MKINET6} != no
1601.22Slukem#	kerberos		${MKKERBEROS} != no
1611.22Slukem#	kerberos4		${MKKERBEROS4} != no
1621.22Slukem#	lint			${MKLINT} != no
1631.22Slukem#	man			${MKMAN} != no
1641.22Slukem#	manz			${MKMANZ} != no
1651.23Slukem#	nls			${MKNLS} != no
1661.37She#	pam			${MKPAM} != no
1671.39Speter#	pf			${MKPF} != no
1681.22Slukem#	postfix			${MKPOSTFIX} != no
1691.22Slukem#	profile			${MKPROFILE} != no
1701.22Slukem#	sendmail		${MKSENDMAIL} != no
1711.24Slukem#	share			${MKSHARE} != no
1721.22Slukem#	skey			${MKSKEY} != no
1731.25Slukem#	uucp			${MKUUCP} != no
1741.22Slukem#	yp			${MKYP} != no
1751.22Slukem#
1761.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
1771.22Slukem#				  automatically append ".gz" to the filename
1781.22Slukem#
1791.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
1801.22Slukem#				  automatically append ".gz" to the filename
1811.1Sdyoung#
1821.8Slukemlist_set_files()
1831.8Slukem{
1841.1Sdyoung	for setname; do
1851.1Sdyoung		list_set_lists $setname
1861.9Slukem	done | xargs cat | \
1871.11Slukem	awk -v obsolete=${obsolete} '
1881.9Slukem		BEGIN {
1891.9Slukem			if (! obsolete) {
1901.12Slukem				split("'"${MKVARS}"'", needvars)
1911.9Slukem				for (vi in needvars) {
1921.9Slukem					nv = needvars[vi]
1931.12Slukem					kw = tolower(substr(nv, 3))
1941.12Slukem					if (ENVIRON[nv] != "no")
1951.12Slukem						wanted[kw] = 1 
1961.9Slukem				}
1971.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
1981.22Slukem					wanted[".cat"] = 1
1991.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
2001.22Slukem					wanted[".man"] = 1
2011.9Slukem			}
2021.9Slukem		}
2031.9Slukem
2041.9Slukem		/^#/ {
2051.9Slukem			next;
2061.9Slukem		}
2071.9Slukem
2081.9Slukem		NF > 2 && $3 != "-" {
2091.9Slukem			split($3, keywords, ",")
2101.9Slukem			show = 1
2111.9Slukem			for (ki in keywords) {
2121.9Slukem				kw = keywords[ki]
2131.9Slukem				if (kw == "obsolete") {
2141.9Slukem					if (obsolete)
2151.9Slukem						print
2161.9Slukem					next
2171.9Slukem				}
2181.22Slukem				if (("manz" in wanted) &&
2191.22Slukem				    (kw == ".cat" || kw == ".man"))
2201.22Slukem					$1 = $1 ".gz"
2211.9Slukem				if (! (kw in wanted))
2221.9Slukem					show = 0
2231.9Slukem			}
2241.9Slukem			if (show)
2251.9Slukem				print
2261.9Slukem			next
2271.9Slukem		}
2281.9Slukem
2291.9Slukem		{
2301.9Slukem			if (! obsolete)
2311.9Slukem				print
2321.9Slukem		}'
2331.9Slukem
2341.1Sdyoung}
2351.1Sdyoung
2361.1Sdyoung#
2371.1Sdyoung# list_set_lists setname
2381.1Sdyoung# 
2391.1Sdyoung# Print to stdout a list of files, one filename per line, which
2401.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2411.1Sdyoung#
2421.1Sdyoung# 	.../lists/base/mi
2431.1Sdyoung# 	.../lists/base/rescue.mi
2441.1Sdyoung# 	.../lists/base/md.i386
2451.9Slukem#		[...]
2461.1Sdyoung#
2471.9Slukem# For a given setname $set, the following files may be selected from
2481.9Slukem# .../list/$set:
2491.9Slukem#	mi
2501.11Slukem#	ad.${MACHINE_ARCH}
2511.11Slukem# (or)	ad.${MACHINE_CPU}
2521.11Slukem#	ad.${MACHINE_CPU}.shl
2531.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2541.11Slukem# (or)	md.${MACHINE}
2551.9Slukem#	stl.mi
2561.9Slukem#	stl.stlib
2571.9Slukem#	shl.mi
2581.9Slukem#	shl.shlib
2591.9Slukem#	lkm.mi			if ${lkm} != no
2601.9Slukem#	gcc.mi
2611.9Slukem#	gcc.shl
2621.9Slukem#	tc.mi
2631.9Slukem#	tc.shl
2641.9Slukem#	rescue.shl
2651.11Slukem#	rescue.${MACHINE}
2661.11Slukem#	rescue.ad.${MACHINE_ARCH}
2671.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
2681.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
2691.1Sdyoung#
2701.9Slukem# Environment:
2711.1Sdyoung# 	shlib
2721.1Sdyoung# 	stlib
2731.1Sdyoung#
2741.8Slukemlist_set_lists()
2751.8Slukem{
2761.1Sdyoung	setname=$1
2771.1Sdyoung
2781.9Slukem	setdir=$setsdir/lists/$setname
2791.9Slukem	echo $setdir/mi
2801.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
2811.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
2821.1Sdyoung		# since the arch-specific one will be more specific than
2831.1Sdyoung		# the cpu-specific one.
2841.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
2851.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
2861.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
2871.11Slukem			echo $setdir/ad.${MACHINE_CPU}
2881.1Sdyoung		fi
2891.1Sdyoung		if [ "$shlib" != "no" -a \
2901.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
2911.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
2921.1Sdyoung		fi
2931.1Sdyoung	fi
2941.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
2951.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
2961.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
2971.11Slukem		echo $setdir/md.${MACHINE}
2981.1Sdyoung	fi
2991.9Slukem	if [ -f $setdir/stl.mi ]; then
3001.9Slukem		echo $setdir/stl.mi
3011.1Sdyoung	fi
3021.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
3031.9Slukem		echo $setdir/stl.${stlib}
3041.1Sdyoung	fi
3051.1Sdyoung	if [ "$shlib" != "no" ]; then
3061.9Slukem		if [ -f $setdir/shl.mi ]; then
3071.9Slukem			echo $setdir/shl.mi
3081.7Sdyoung		fi
3091.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
3101.9Slukem			echo $setdir/shl.${shlib}
3111.7Sdyoung		fi
3121.1Sdyoung	fi
3131.1Sdyoung	if [ "$lkm" != "no" ]; then
3141.9Slukem		if [ -f $setdir/lkm.mi ]; then
3151.9Slukem			echo $setdir/lkm.mi
3161.1Sdyoung		fi
3171.1Sdyoung	fi
3181.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3191.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3201.9Slukem			if [ -f $setdir/gcc.mi ]; then
3211.9Slukem				echo $setdir/gcc.mi
3221.2Smrg			fi
3231.2Smrg			if [ "$shlib" != "no" ]; then
3241.9Slukem				if [ -f $setdir/gcc.shl ]; then
3251.9Slukem					echo $setdir/gcc.shl
3261.2Smrg				fi
3271.2Smrg			fi
3281.2Smrg		else
3291.9Slukem			if [ -f $setdir/tc.mi ]; then
3301.9Slukem				echo $setdir/tc.mi
3311.2Smrg			fi
3321.2Smrg			if [ "$shlib" != "no" ]; then
3331.9Slukem				if [ -f $setdir/tc.shl ]; then
3341.9Slukem					echo $setdir/tc.shl
3351.2Smrg				fi
3361.1Sdyoung			fi
3371.1Sdyoung		fi
3381.1Sdyoung	fi
3391.1Sdyoung
3401.9Slukem	if [ -f $setdir/rescue.mi ]; then
3411.9Slukem		echo $setdir/rescue.mi
3421.1Sdyoung	fi
3431.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3441.11Slukem		echo $setdir/rescue.${MACHINE}
3451.1Sdyoung	fi
3461.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3471.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3481.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3491.1Sdyoung		# specific one will be more specific than the
3501.1Sdyoung		# cpu-specific one.
3511.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3521.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3531.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3541.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3551.1Sdyoung		fi
3561.10Sjmc		if [ "$shlib" != "no" -a \
3571.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3581.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
3591.10Sjmc		fi
3601.1Sdyoung	fi
3611.5Sdyoung}
3621.5Sdyoung
3631.9Slukem# arch_to_cpu mach
3641.9Slukem#
3651.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
3661.9Slukem# as determined by <bsd.own.mk>.
3671.9Slukem#
3681.8Slukemarch_to_cpu()
3691.8Slukem{
3701.12Slukem	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
3711.5Sdyoung.include <bsd.own.mk>
3721.5Sdyoungall:
3731.5Sdyoung	@echo \${MACHINE_CPU}
3741.12SlukemEOMAKE
3751.1Sdyoung}
376