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