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