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