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