sets.subr revision 1.19
1#	$NetBSD: sets.subr,v 1.19 2004/01/04 13:20:49 lukem Exp $
2#
3
4#
5# The following variables contain defaults for sets.subr functions and callers:
6#	setsdir			path to src/distrib/sets
7#	nlists			list of base sets
8#	xlists			list of x11 sets
9#	obsolete		controls if obsolete files are selected instead
10#	lkm			if != "no", enable LKM sets
11#	shlib			shared library format (a.out, elf, or "")
12#	stlib			static library format (a.out, elf)
13#	x11_version		version of XF86 (3 or 4)
14#
15# The following <bsd.own.mk> variables are exported to the environment:
16#	MACHINE	
17#	MACHINE_ARCH
18#	MACHINE_CPU
19#	HAVE_GCC3
20#	TOOLCHAIN_MISSING
21#	OBJECT_FMT
22#	MKCRYPTO
23#	MKCRYPTO_IDEA
24#	MKCRYPTO_MDC2
25#	MKCRYPTO_RC5
26#	MKCVS
27#	MKHESIOD
28#	MKKERBEROS
29#	MKKERBEROS4
30#	MKLINT
31#	MKPOSTFIX
32#	MKPROFILE
33#	MKSENDMAIL
34#	MKSKEY
35#	MKYP
36
37MKVARS="MKCRYPTO MKCRYPTO_IDEA MKCRYPTO_MDC2 MKCRYPTO_RC5 MKCVS MKHESIOD MKKERBEROS MKKERBEROS4 MKLINT MKPOSTFIX MKPROFILE MKSENDMAIL MKSKEY MKYP"
38
39oIFS=$IFS
40IFS="
41"
42for x in $(
43${MAKE:-make} -B -f- all <<EOMAKE
44.include <bsd.own.mk>
45all:
46.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
47		HAVE_GCC3 OBJECT_FMT TOOLCHAIN_MISSING \
48		${MKVARS}
49	@echo "export \$i=\${\$i}"
50.endfor
51.if defined(USE_XF86_4) && (\${USE_XF86_4} != "no")
52	@echo x11_version=4
53.else
54	@echo x11_version=3
55.endif
56
57EOMAKE
58); do
59#	echo 1>&2 "DEBUG: read $x"
60	eval $x
61done
62IFS=$oIFS
63
64setsdir=$(dirname $0)
65nlists="base comp etc games man misc text"
66case $x11_version in
673) xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
684) xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
69*) xlists="xbase xcomp xcontrib xfont xmisc xserver" ;;
70esac
71obsolete=0
72lkm=yes
73if [ "${MACHINE}" = "evbppc" ]; then
74	lkm=no				# Turn off LKMs for some ports.
75fi
76# Determine lib type.
77if [ "${OBJECT_FMT}" = "ELF" ]; then
78	shlib=elf
79else
80	shlib=aout
81fi
82stlib=$shlib
83if [ "${MACHINE_CPU}" = "sh3" -o "${MACHINE_ARCH}" = "m68000" ]; then
84	shlib=no			# Turn off shlibs for some ports.
85fi
86
87
88#
89# list_set_files setfile [...]
90# 
91# Produce a packing list for setfile(s).
92# In each file, a record consists of a path and a System Package name,
93# separated by whitespace. E.g.,
94#
95# 	# $NetBSD: sets.subr,v 1.19 2004/01/04 13:20:49 lukem Exp $
96# 	.			base-sys-root	[keyword[,...]]
97# 	./altroot		base-sys-root
98# 	./bin			base-sys-root
99# 	./bin/[			base-util-root
100# 	./bin/cat		base-util-root
101#		[...]
102#
103# A # in the first column marks a comment.
104#
105# If ${obsolete} != 0, only entries with an "obsolete" keyword will
106# be printed.
107#
108# The third field is an optional comma separated list of keywords to
109# control if a record is printed; every keyword listed must be enabled
110# for the record to be printed.  The following keywords are available:
111#	dummy			dummy entry (ignored)
112#	obsolete		file is obsolete, and only printed if 
113#				${obsolete} != 0
114#
115#	crypto			<bsd.own.mk> ${MKCRYPTO} != no
116#	crypto_idea		<bsd.own.mk> ${MKCRYPTO_IDEA} != no
117#	crypto_mdc2		<bsd.own.mk> ${MKCRYPTO_MDC2} != no
118#	crypto_rc5		<bsd.own.mk> ${MKCRYPTO_RC5} != no
119#	cvs			<bsd.own.mk> ${MKCVS} != no
120#	hesiod			<bsd.own.mk> ${MKHESIOD} != no
121#	kerberos		<bsd.own.mk> ${MKKERBEROS} != no
122#	kerberos4		<bsd.own.mk> ${MKKERBEROS4} != no
123#	lint			<bsd.own.mk> ${MKLINT} != no
124#	postfix			<bsd.own.mk> ${MKPOSTFIX} != no
125#	profile			<bsd.own.mk> ${MKPROFILE} != no
126#	sendmail		<bsd.own.mk> ${MKSENDMAIL} != no
127#	skey			<bsd.own.mk> ${MKSKEY} != no
128#	yp			<bsd.own.mk> ${MKYP} != no
129#
130list_set_files()
131{
132	for setname; do
133		list_set_lists $setname
134	done | xargs cat | \
135	awk -v obsolete=${obsolete} '
136		BEGIN {
137			if (! obsolete) {
138				split("'"${MKVARS}"'", needvars)
139				for (vi in needvars) {
140					nv = needvars[vi]
141					kw = tolower(substr(nv, 3))
142					if (ENVIRON[nv] != "no")
143						wanted[kw] = 1 
144				}
145			}
146		}
147
148		/^#/ {
149			next;
150		}
151
152		NF > 2 && $3 != "-" {
153			split($3, keywords, ",")
154			show = 1
155			for (ki in keywords) {
156				kw = keywords[ki]
157				if (kw == "obsolete") {
158					if (obsolete)
159						print
160					next
161				}
162				if (! (kw in wanted))
163					show = 0
164			}
165			if (show)
166				print
167			next
168		}
169
170		{
171			if (! obsolete)
172				print
173		}'
174
175}
176
177#
178# list_set_lists setname
179# 
180# Print to stdout a list of files, one filename per line, which
181# concatenate to create the packing list for setname. E.g.,
182#
183# 	.../lists/base/mi
184# 	.../lists/base/rescue.mi
185# 	.../lists/base/md.i386
186#		[...]
187#
188# For a given setname $set, the following files may be selected from
189# .../list/$set:
190#	mi
191#	ad.${MACHINE_ARCH}
192# (or)	ad.${MACHINE_CPU}
193#	ad.${MACHINE_CPU}.shl
194#	md.${MACHINE}.${MACHINE_ARCH}
195# (or)	md.${MACHINE}
196#	stl.mi
197#	stl.stlib
198#	shl.mi
199#	shl.shlib
200#	lkm.mi			if ${lkm} != no
201#	gcc.mi
202#	gcc.shl
203#	tc.mi
204#	tc.shl
205#	rescue.shl
206#	rescue.${MACHINE}
207#	rescue.ad.${MACHINE_ARCH}
208# (or)	rescue.ad.${MACHINE_CPU}
209# 	rescue.ad.${MACHINE_CPU}.shl
210#
211# Environment:
212# 	shlib
213# 	stlib
214#
215list_set_lists()
216{
217	setname=$1
218
219	setdir=$setsdir/lists/$setname
220	echo $setdir/mi
221	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
222		# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
223		# since the arch-specific one will be more specific than
224		# the cpu-specific one.
225		if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
226			echo $setdir/ad.${MACHINE_ARCH}
227		elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
228			echo $setdir/ad.${MACHINE_CPU}
229		fi
230		if [ "$shlib" != "no" -a \
231		     -f $setdir/ad.${MACHINE_CPU}.shl ]; then
232			echo $setdir/ad.${MACHINE_CPU}.shl
233		fi
234	fi
235	if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
236		echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
237	elif [ -f $setdir/md.${MACHINE} ]; then
238		echo $setdir/md.${MACHINE}
239	fi
240	if [ -f $setdir/stl.mi ]; then
241		echo $setdir/stl.mi
242	fi
243	if [ -f $setdir/stl.${stlib} ]; then
244		echo $setdir/stl.${stlib}
245	fi
246	if [ "$shlib" != "no" ]; then
247		if [ -f $setdir/shl.mi ]; then
248			echo $setdir/shl.mi
249		fi
250		if [ -f $setdir/shl.${shlib} ]; then
251			echo $setdir/shl.${shlib}
252		fi
253	fi
254	if [ "$lkm" != "no" ]; then
255		if [ -f $setdir/lkm.mi ]; then
256			echo $setdir/lkm.mi
257		fi
258	fi
259	if [ "${TOOLCHAIN_MISSING}" != "yes" ]; then
260		if [ "${HAVE_GCC3}" = "yes" ]; then
261			if [ -f $setdir/gcc.mi ]; then
262				echo $setdir/gcc.mi
263			fi
264			if [ "$shlib" != "no" ]; then
265				if [ -f $setdir/gcc.shl ]; then
266					echo $setdir/gcc.shl
267				fi
268			fi
269		else
270			if [ -f $setdir/tc.mi ]; then
271				echo $setdir/tc.mi
272			fi
273			if [ "$shlib" != "no" ]; then
274				if [ -f $setdir/tc.shl ]; then
275					echo $setdir/tc.shl
276				fi
277			fi
278		fi
279	fi
280
281	if [ -f $setdir/rescue.mi ]; then
282		echo $setdir/rescue.mi
283	fi
284	if [ -f $setdir/rescue.${MACHINE} ]; then
285		echo $setdir/rescue.${MACHINE}
286	fi
287	if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
288		# Prefer a rescue.ad.${MACHINE_ARCH} over a
289		# rescue.ad.${MACHINE_CPU}, since the arch-
290		# specific one will be more specific than the
291		# cpu-specific one.
292		if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
293			echo $setdir/rescue.ad.${MACHINE_ARCH}
294		elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
295			echo $setdir/rescue.ad.${MACHINE_CPU}
296		fi
297		if [ "$shlib" != "no" -a \
298		     -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
299			echo $setdir/rescue.ad.${MACHINE_CPU}.shl
300		fi
301	fi
302}
303
304# arch_to_cpu mach
305#
306# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
307# as determined by <bsd.own.mk>.
308#
309arch_to_cpu()
310{
311	MACHINE_ARCH=${1} ${MAKE:-make} -f- all <<EOMAKE
312.include <bsd.own.mk>
313all:
314	@echo \${MACHINE_CPU}
315EOMAKE
316}
317