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