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