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