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