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