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