sets.subr revision 1.44
11.44Sapb#	$NetBSD: sets.subr,v 1.44 2006/01/04 14:23:22 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.43Sapb: ${AWK:=awk}
681.42Sapb: ${CKSUM:=cksum}
691.43Sapb: ${COMM:=comm}
701.44Sapb: ${DATE:=date}
711.43Sapb: ${DB:=db}
721.43Sapb: ${EGREP:=egrep}
731.43Sapb: ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
741.44Sapb: ${FGREP:=fgrep}
751.43Sapb: ${FIND:=find}
761.44Sapb: ${GREP:=grep}
771.43Sapb: ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
781.44Sapb: ${HOSTNAME:=hostname}
791.42Sapb: ${HOST_SH:=sh}
801.43Sapb: ${IDENT:=ident}
811.43Sapb: ${JOIN:=join}
821.43Sapb: ${LS:=ls}
831.43Sapb: ${MAKE:=make}
841.42Sapb: ${MKTEMP:=mktemp}
851.43Sapb: ${MTREE:=mtree}
861.43Sapb: ${PASTE:=paste}
871.42Sapb: ${PAX:=pax}
881.43Sapb: ${PKG_CREATE:=pkg_create}
891.43Sapb: ${PRINTF:=printf}
901.43Sapb: ${SED:=sed}
911.43Sapb: ${SORT:=sort}
921.44Sapb: ${STAT:=stat}
931.44Sapb: ${TSORT:=tsort}
941.43Sapb: ${UNAME:=uname}
951.43Sapb: ${WC:=wc}
961.43Sapb
971.9SlukemoIFS=$IFS
981.9SlukemIFS="
991.9Slukem"
1001.9Slukemfor x in $(
1011.43Sapb${MAKE} -B -f- all <<EOMAKE
1021.9Slukem.include <bsd.own.mk>
1031.33Sjmc.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
1041.33SjmcMKMANPAGES=no
1051.33Sjmc.else
1061.33SjmcMKMANPAGES=yes
1071.33Sjmc.endif
1081.9Slukemall:
1091.11Slukem.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
1101.11Slukem		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
1111.12Slukem		${MKVARS}
1121.12Slukem	@echo "export \$i=\${\$i}"
1131.11Slukem.endfor
1141.20Slukem.if (\${MKX11:Uno} != "no")
1151.20Slukem	@echo x11_version=""
1161.35Stron.else
1171.9Slukem	@echo x11_version=4
1181.9Slukem.endif
1191.9Slukem
1201.12SlukemEOMAKE
1211.9Slukem); do
1221.11Slukem#	echo 1>&2 "DEBUG: read $x"
1231.9Slukem	eval $x
1241.9Slukemdone
1251.9SlukemIFS=$oIFS
1261.9Slukem
1271.34Serhsetsdir=${0%/*}
1281.9Slukemnlists="base comp etc games man misc text"
1291.9Slukemcase $x11_version in
1301.20Slukem3)	xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
1311.20Slukem4)	xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
1321.28Slukem"")	xlists="xbase xcomp xetc xfont xserver" ;;
1331.20Slukem*)	xlists="" ;;	# unknown!
1341.9Slukemesac
1351.9Slukemobsolete=0
1361.9Slukemlkm=yes
1371.11Slukemif [ "${MACHINE}" = "evbppc" ]; then
1381.9Slukem	lkm=no				# Turn off LKMs for some ports.
1391.9Slukemfi
1401.31Sjmc# Determine lib type. Do this first so stlib also gets set.
1411.31Sjmcif [ "${OBJECT_FMT}" = "ELF" ]; then
1421.9Slukem	shlib=elf
1431.9Slukemelse
1441.9Slukem	shlib=aout
1451.9Slukemfi
1461.9Slukemstlib=$shlib
1471.31Sjmc# Now check for MKPIC or specials and turn off shlib if need be.
1481.31Sjmcif [ "${MKPIC}" = "no" ]; then
1491.31Sjmc	shlib=no
1501.31Sjmcfi
1511.29Suweif [ "${MACHINE_ARCH}" = "m68000" ]; then
1521.9Slukem	shlib=no			# Turn off shlibs for some ports.
1531.9Slukemfi
1541.9Slukem
1551.9Slukem#
1561.9Slukem# list_set_files setfile [...]
1571.1Sdyoung# 
1581.9Slukem# Produce a packing list for setfile(s).
1591.9Slukem# In each file, a record consists of a path and a System Package name,
1601.9Slukem# separated by whitespace. E.g.,
1611.9Slukem#
1621.44Sapb# 	# $NetBSD: sets.subr,v 1.44 2006/01/04 14:23:22 apb Exp $
1631.9Slukem# 	.			base-sys-root	[keyword[,...]]
1641.9Slukem# 	./altroot		base-sys-root
1651.9Slukem# 	./bin			base-sys-root
1661.9Slukem# 	./bin/[			base-util-root
1671.9Slukem# 	./bin/cat		base-util-root
1681.9Slukem#		[...]
1691.9Slukem#
1701.9Slukem# A # in the first column marks a comment.
1711.9Slukem#
1721.9Slukem# If ${obsolete} != 0, only entries with an "obsolete" keyword will
1731.9Slukem# be printed.
1741.9Slukem#
1751.9Slukem# The third field is an optional comma separated list of keywords to
1761.9Slukem# control if a record is printed; every keyword listed must be enabled
1771.9Slukem# for the record to be printed.  The following keywords are available:
1781.9Slukem#	dummy			dummy entry (ignored)
1791.13Slukem#	obsolete		file is obsolete, and only printed if 
1801.13Slukem#				${obsolete} != 0
1811.13Slukem#
1821.22Slukem#	bfd			${MKBFD} != no
1831.22Slukem#	catpages		${MKCATPAGES} != no
1841.22Slukem#	crypto			${MKCRYPTO} != no
1851.22Slukem#	crypto_idea		${MKCRYPTO_IDEA} != no
1861.22Slukem#	crypto_mdc2		${MKCRYPTO_MDC2} != no
1871.22Slukem#	crypto_rc5		${MKCRYPTO_RC5} != no
1881.22Slukem#	cvs			${MKCVS} != no
1891.23Slukem#	doc			${MKDOC} != no
1901.36Smatt#	gcccmds			${MKGCCCMDS} != no
1911.32Sscw#	gdb			${MKGDB} != no
1921.22Slukem#	hesiod			${MKHESIOD} != no
1931.23Slukem#	info			${MKINFO} != no
1941.39Speter#	ipfilter		${MKIPFILTER} != no
1951.38Slukem#	inet6			${MKINET6} != no
1961.22Slukem#	kerberos		${MKKERBEROS} != no
1971.22Slukem#	kerberos4		${MKKERBEROS4} != no
1981.22Slukem#	lint			${MKLINT} != no
1991.22Slukem#	man			${MKMAN} != no
2001.22Slukem#	manz			${MKMANZ} != no
2011.23Slukem#	nls			${MKNLS} != no
2021.37She#	pam			${MKPAM} != no
2031.39Speter#	pf			${MKPF} != no
2041.22Slukem#	postfix			${MKPOSTFIX} != no
2051.22Slukem#	profile			${MKPROFILE} != no
2061.22Slukem#	sendmail		${MKSENDMAIL} != no
2071.24Slukem#	share			${MKSHARE} != no
2081.22Slukem#	skey			${MKSKEY} != no
2091.25Slukem#	uucp			${MKUUCP} != no
2101.22Slukem#	yp			${MKYP} != no
2111.22Slukem#
2121.41Slukem#	use_inet6		${USE_INET6} != no
2131.41Slukem#	use_kerberos		${USE_KERBEROS} != no
2141.41Slukem#	use_yp			${USE_YP} != no
2151.41Slukem#
2161.22Slukem#	.cat			if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
2171.22Slukem#				  automatically append ".gz" to the filename
2181.22Slukem#
2191.22Slukem#	.man			if ${MKMANZ} != "no" && ${MKMAN} != "no"
2201.22Slukem#				  automatically append ".gz" to the filename
2211.1Sdyoung#
2221.8Slukemlist_set_files()
2231.8Slukem{
2241.1Sdyoung	for setname; do
2251.1Sdyoung		list_set_lists $setname
2261.9Slukem	done | xargs cat | \
2271.43Sapb	${AWK} -v obsolete=${obsolete} '
2281.9Slukem		BEGIN {
2291.9Slukem			if (! obsolete) {
2301.12Slukem				split("'"${MKVARS}"'", needvars)
2311.9Slukem				for (vi in needvars) {
2321.9Slukem					nv = needvars[vi]
2331.41Slukem					kw = tolower(nv)
2341.41Slukem					sub(/^mk/, "", kw)
2351.12Slukem					if (ENVIRON[nv] != "no")
2361.12Slukem						wanted[kw] = 1 
2371.9Slukem				}
2381.33Sjmc				if (("man" in wanted) && ("catpages" in wanted))
2391.22Slukem					wanted[".cat"] = 1
2401.33Sjmc				if (("man" in wanted) && ("manpages" in wanted))
2411.22Slukem					wanted[".man"] = 1
2421.9Slukem			}
2431.9Slukem		}
2441.9Slukem
2451.9Slukem		/^#/ {
2461.9Slukem			next;
2471.9Slukem		}
2481.9Slukem
2491.9Slukem		NF > 2 && $3 != "-" {
2501.9Slukem			split($3, keywords, ",")
2511.9Slukem			show = 1
2521.9Slukem			for (ki in keywords) {
2531.9Slukem				kw = keywords[ki]
2541.9Slukem				if (kw == "obsolete") {
2551.9Slukem					if (obsolete)
2561.9Slukem						print
2571.9Slukem					next
2581.9Slukem				}
2591.22Slukem				if (("manz" in wanted) &&
2601.22Slukem				    (kw == ".cat" || kw == ".man"))
2611.22Slukem					$1 = $1 ".gz"
2621.9Slukem				if (! (kw in wanted))
2631.9Slukem					show = 0
2641.9Slukem			}
2651.9Slukem			if (show)
2661.9Slukem				print
2671.9Slukem			next
2681.9Slukem		}
2691.9Slukem
2701.9Slukem		{
2711.9Slukem			if (! obsolete)
2721.9Slukem				print
2731.9Slukem		}'
2741.9Slukem
2751.1Sdyoung}
2761.1Sdyoung
2771.1Sdyoung#
2781.1Sdyoung# list_set_lists setname
2791.1Sdyoung# 
2801.1Sdyoung# Print to stdout a list of files, one filename per line, which
2811.1Sdyoung# concatenate to create the packing list for setname. E.g.,
2821.1Sdyoung#
2831.1Sdyoung# 	.../lists/base/mi
2841.1Sdyoung# 	.../lists/base/rescue.mi
2851.1Sdyoung# 	.../lists/base/md.i386
2861.9Slukem#		[...]
2871.1Sdyoung#
2881.9Slukem# For a given setname $set, the following files may be selected from
2891.9Slukem# .../list/$set:
2901.9Slukem#	mi
2911.11Slukem#	ad.${MACHINE_ARCH}
2921.11Slukem# (or)	ad.${MACHINE_CPU}
2931.11Slukem#	ad.${MACHINE_CPU}.shl
2941.11Slukem#	md.${MACHINE}.${MACHINE_ARCH}
2951.11Slukem# (or)	md.${MACHINE}
2961.9Slukem#	stl.mi
2971.9Slukem#	stl.stlib
2981.9Slukem#	shl.mi
2991.9Slukem#	shl.shlib
3001.9Slukem#	lkm.mi			if ${lkm} != no
3011.9Slukem#	gcc.mi
3021.9Slukem#	gcc.shl
3031.9Slukem#	tc.mi
3041.9Slukem#	tc.shl
3051.9Slukem#	rescue.shl
3061.11Slukem#	rescue.${MACHINE}
3071.11Slukem#	rescue.ad.${MACHINE_ARCH}
3081.11Slukem# (or)	rescue.ad.${MACHINE_CPU}
3091.11Slukem# 	rescue.ad.${MACHINE_CPU}.shl
3101.1Sdyoung#
3111.9Slukem# Environment:
3121.1Sdyoung# 	shlib
3131.1Sdyoung# 	stlib
3141.1Sdyoung#
3151.8Slukemlist_set_lists()
3161.8Slukem{
3171.1Sdyoung	setname=$1
3181.1Sdyoung
3191.9Slukem	setdir=$setsdir/lists/$setname
3201.9Slukem	echo $setdir/mi
3211.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3221.11Slukem		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
3231.1Sdyoung		# since the arch-specific one will be more specific than
3241.1Sdyoung		# the cpu-specific one.
3251.11Slukem		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
3261.11Slukem			echo $setdir/ad.${MACHINE_ARCH}
3271.11Slukem		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
3281.11Slukem			echo $setdir/ad.${MACHINE_CPU}
3291.1Sdyoung		fi
3301.1Sdyoung		if [ "$shlib" != "no" -a \
3311.11Slukem		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
3321.11Slukem			echo $setdir/ad.${MACHINE_CPU}.shl
3331.1Sdyoung		fi
3341.1Sdyoung	fi
3351.11Slukem	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
3361.11Slukem		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
3371.11Slukem	elif [ -f $setdir/md.${MACHINE} ]; then
3381.11Slukem		echo $setdir/md.${MACHINE}
3391.1Sdyoung	fi
3401.9Slukem	if [ -f $setdir/stl.mi ]; then
3411.9Slukem		echo $setdir/stl.mi
3421.1Sdyoung	fi
3431.9Slukem	if [ -f $setdir/stl.${stlib} ]; then
3441.9Slukem		echo $setdir/stl.${stlib}
3451.1Sdyoung	fi
3461.1Sdyoung	if [ "$shlib" != "no" ]; then
3471.9Slukem		if [ -f $setdir/shl.mi ]; then
3481.9Slukem			echo $setdir/shl.mi
3491.7Sdyoung		fi
3501.9Slukem		if [ -f $setdir/shl.${shlib} ]; then
3511.9Slukem			echo $setdir/shl.${shlib}
3521.7Sdyoung		fi
3531.1Sdyoung	fi
3541.1Sdyoung	if [ "$lkm" != "no" ]; then
3551.9Slukem		if [ -f $setdir/lkm.mi ]; then
3561.9Slukem			echo $setdir/lkm.mi
3571.1Sdyoung		fi
3581.1Sdyoung	fi
3591.11Slukem	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
3601.11Slukem		if [ "${HAVE_GCC3}" = "yes" ]; then
3611.9Slukem			if [ -f $setdir/gcc.mi ]; then
3621.9Slukem				echo $setdir/gcc.mi
3631.2Smrg			fi
3641.2Smrg			if [ "$shlib" != "no" ]; then
3651.9Slukem				if [ -f $setdir/gcc.shl ]; then
3661.9Slukem					echo $setdir/gcc.shl
3671.2Smrg				fi
3681.2Smrg			fi
3691.2Smrg		else
3701.9Slukem			if [ -f $setdir/tc.mi ]; then
3711.9Slukem				echo $setdir/tc.mi
3721.2Smrg			fi
3731.2Smrg			if [ "$shlib" != "no" ]; then
3741.9Slukem				if [ -f $setdir/tc.shl ]; then
3751.9Slukem					echo $setdir/tc.shl
3761.2Smrg				fi
3771.1Sdyoung			fi
3781.1Sdyoung		fi
3791.1Sdyoung	fi
3801.1Sdyoung
3811.9Slukem	if [ -f $setdir/rescue.mi ]; then
3821.9Slukem		echo $setdir/rescue.mi
3831.1Sdyoung	fi
3841.11Slukem	if [ -f $setdir/rescue.${MACHINE} ]; then
3851.11Slukem		echo $setdir/rescue.${MACHINE}
3861.1Sdyoung	fi
3871.11Slukem	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
3881.11Slukem		# Prefer a rescue.ad.${MACHINE_ARCH} over a
3891.11Slukem		# rescue.ad.${MACHINE_CPU}, since the arch-
3901.1Sdyoung		# specific one will be more specific than the
3911.1Sdyoung		# cpu-specific one.
3921.11Slukem		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
3931.11Slukem			echo $setdir/rescue.ad.${MACHINE_ARCH}
3941.11Slukem		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
3951.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}
3961.1Sdyoung		fi
3971.10Sjmc		if [ "$shlib" != "no" -a \
3981.11Slukem		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
3991.11Slukem			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
4001.10Sjmc		fi
4011.1Sdyoung	fi
4021.5Sdyoung}
4031.5Sdyoung
4041.9Slukem# arch_to_cpu mach
4051.9Slukem#
4061.11Slukem# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
4071.9Slukem# as determined by <bsd.own.mk>.
4081.9Slukem#
4091.8Slukemarch_to_cpu()
4101.8Slukem{
4111.43Sapb	MACHINE_ARCH=${1} ${MAKE} -f- all <<EOMAKE
4121.5Sdyoung.include <bsd.own.mk>
4131.5Sdyoungall:
4141.5Sdyoung	@echo \${MACHINE_CPU}
4151.12SlukemEOMAKE
4161.1Sdyoung}
417