1 # $NetBSD: sets.subr,v 1.138 2012/08/08 14:08:01 christos Exp $
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 # extlists list of extsrc sets
10 # obsolete controls if obsolete files are selected instead
11 # module if != "no", enable MODULE sets
12 # shlib shared library format (a.out, elf, or "")
13 # stlib static library format (a.out, elf)
15 # The following <bsd.own.mk> variables are exported to the environment:
29 # The following variables refer to tools that are used when building sets:
37 : ${ENV_CMD:=env} # ${ENV} is special to sh(1), ksh(1), etc.
41 : ${GZIP_CMD:=gzip} # ${GZIP} is special to gzip(1)
42 : ${HOSTNAME_CMD:=hostname} # ${HOSTNAME} is special to bash(1)
62 # If printf is a shell builtin command, then we can
63 # implement cheaper versions of basename and dirname
64 # that do not involve any fork/exec overhead.
65 # If printf is not builtin, approximate it using echo,
66 # and hope there are no weird file names that cause
67 # some versions of echo to do the wrong thing.
68 # (Converting to this version of dirname speeded up the
69 # syspkgdeps script by an order of magnitude, from 68
70 # seconds to 6.3 seconds on one particular host.)
72 # Note that naive approximations for dirname
73 # using ${foo%/*} do not do the right thing in cases
74 # where the result should be "/" or ".".
76 case "$(type printf)" in
108 ?*/*) dn="${1%/*}" ;;
123 for x in $( ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
129 MKVARS="$( ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )"
135 if [ "${MKKMOD}" = "no" ]; then
136 module=no # MODULEs are off.
142 if [ "${MKATF}" = "no" ]; then
147 # Determine lib type. Do this first so stlib also gets set.
148 if [ "${OBJECT_FMT}" = "ELF" ]; then
154 # Now check for MKPIC or specials and turn off shlib if need be.
155 if [ "${MKPIC}" = "no" ]; then
159 #nlists="base comp etc games man misc $modset $testset text"
161 xlists="xbase xcomp xetc xfont xserver"
162 extlists="extbase extcomp extetc"
164 OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
165 MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
166 SUBST="s#@MODULEDIR@#${MODULEDIR}#g"
167 SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
168 SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
171 # list_set_files setfile [...]
173 # Produce a packing list for setfile(s).
174 # In each file, a record consists of a path and a System Package name,
175 # separated by whitespace. E.g.,
177 # # $NetBSD: sets.subr,v 1.138 2012/08/08 14:08:01 christos Exp $
178 # . base-sys-root [keyword[,...]]
179 # ./altroot base-sys-root
180 # ./bin base-sys-root
181 # ./bin/[ base-util-root
182 # ./bin/cat base-util-root
185 # A # in the first column marks a comment.
187 # If ${obsolete} != 0, only entries with an "obsolete" keyword will
188 # be printed. All other keywords must be present.
190 # The third field is an optional comma separated list of keywords to
191 # control if a record is printed; every keyword listed must be enabled
192 # for the record to be printed. The following keywords are available:
193 # dummy dummy entry (ignored)
194 # obsolete file is obsolete, and only printed if
198 # bfd obsolete, use binutils.
199 # binutils ${MKBINUTILS} != no
200 # bsdgrep ${MKBSDGREP} != no
201 # catpages ${MKCATPAGES} != no
202 # compat ${MKCOMPAT} != no
203 # crypto ${MKCRYPTO} != no
204 # crypto_rc5 ${MKCRYPTO_RC5} != no
206 # debug ${MKDEBUG} != no
207 # debuglib ${MKDEBUGLIB} != no
209 # dtrace ${MKDTRACE} != no
210 # dynamicroot ${MKDYNAMICROOT} != no
211 # extsrc ${MKEXTSRC} != no
213 # gcccmds ${MKGCCCMDS} != no
215 # hesiod ${MKHESIOD} != no
216 # html ${MKHTML} != no
217 # inet6 ${MKINET6} != no
218 # info ${MKINFO} != no
219 # ipfilter ${MKIPFILTER} != no
220 # iscsi ${MKISCSI} != no
221 # kerberos ${MKKERBEROS} != no
222 # kmod ${MKKMOD} != no
223 # ldap ${MKLDAP} != no
224 # lint ${MKLINT} != no
225 # llvm ${MKLLVM} != no
227 # makemandb ${MKMAKEMANDB} != no
229 # manpages ${MKMANPAGES} != no
230 # manz ${MKMANZ} != no
231 # mdns ${MKMDNS} != no
238 # postfix ${MKPOSTFIX} != no
239 # profile ${MKPROFILE} != no
240 # perfuse ${MKPERFUSE} != no
241 # rump ${MKRUMP} != no
242 # share ${MKSHARE} != no
243 # skey ${MKSKEY} != no
244 # solaris ${MKDTRACE} != no or ${MKZFS} != no
245 # ssp ${HAS_SSP} != no
246 # x11 ${MKX11} != no && ${X11FLAVOUR} != "Xorg"
247 # xorg ${MKX11} != no && ${X11FLAVOUR} == "Xorg"
251 # binutils=<n> <n> = value of ${HAVE_BINUTILS}
252 # gcc=<n> <n> = value of ${HAVE_GCC}
253 # gdb=<n> <n> = value of ${HAVE_GDB}
255 # use_inet6 ${USE_INET6} != no
256 # use_kerberos ${USE_KERBEROS} != no
257 # use_yp ${USE_YP} != no
259 # .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
260 # automatically append ".gz" to the filename
262 # .man if ${MKMANZ} != "no" && ${MKMAN} != "no"
263 # automatically append ".gz" to the filename
267 if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
272 print_set_lists "$@" | \
273 ${AWK} -v obsolete=${obsolete} '
276 wanted["obsolete"] = 1
278 split("'"${MKVARS}"'", needvars)
279 for (vi in needvars) {
284 if (ENVIRON[nv] != "no")
288 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
289 if ("binutils" in wanted)
290 wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
292 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
294 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
296 if (("man" in wanted) && ("catpages" in wanted))
298 if (("man" in wanted) && ("manpages" in wanted))
307 notwanted[substr($1, 2)] = 1;
308 delete list [substr($1, 2)];
313 NF > 2 && $3 != "-" {
314 if (notwanted[$1] != "")
316 split($3, keywords, ",")
319 for (ki in keywords) {
321 if (("manz" in wanted) &&
322 (kw == ".cat" || kw == ".man"))
324 if (substr(kw, 1, 1) == "!") {
329 if (! (kw in wanted))
332 if (kw == "obsolete")
335 if (obsolete && ! haveobs)
343 if (notwanted[$1] != "")
358 # list_set_lists setname
360 # Print to stdout a list of files, one filename per line, which
361 # concatenate to create the packing list for setname. E.g.,
364 # .../lists/base/rescue.mi
365 # .../lists/base/md.i386
368 # For a given setname $set, the following files may be selected from
373 # (or) ad.${MACHINE_CPU}
374 # ad.${MACHINE_CPU}.shl
375 # md.${MACHINE}.${MACHINE_ARCH}
383 # module.mi if ${module} != no
384 # module.${MACHINE} if ${module} != no
385 # module.ad.${MACHINE_ARCH} if ${module} != no
386 # (or) module.ad.${MACHINE_CPU} if ${module} != no
389 # rescue.ad.${MACHINE_ARCH}
390 # (or) rescue.ad.${MACHINE_CPU}
391 # rescue.ad.${MACHINE_CPU}.shl
401 list_set_lists_mi $setname
402 list_set_lists_ad $setname
403 list_set_lists_md $setname
404 list_set_lists_stl $setname
405 list_set_lists_shl $setname
406 list_set_lists_module $setname
407 list_set_lists_rescue $setname
413 setdir=$setsdir/lists/$1
420 setdir=$setsdir/lists/$1
421 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
422 list_set_lists_common_ad $1
427 setdir=$setsdir/lists/$1
428 echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
429 echo_if_exist $setdir/md.${MACHINE}
434 setdir=$setsdir/lists/$1
435 echo_if_exist $setdir/stl.mi
436 echo_if_exist $setdir/stl.${stlib}
441 setdir=$setsdir/lists/$1
442 [ "$shlib" != "no" ] || return
443 echo_if_exist $setdir/shl.mi
444 echo_if_exist $setdir/shl.${shlib}
447 list_set_lists_module()
449 setdir=$setsdir/lists/$1
450 [ "$module" != "no" ] || return
451 echo_if_exist $setdir/module.mi
452 echo_if_exist $setdir/module.${MACHINE}
453 # XXX module never has .shl
454 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
455 list_set_lists_common_ad $1 module
458 list_set_lists_rescue()
460 setdir=$setsdir/lists/$1
461 echo_if_exist $setdir/rescue.mi
462 echo_if_exist $setdir/rescue.${MACHINE}
463 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
464 list_set_lists_common_ad $1 rescue
467 list_set_lists_common_ad()
469 setdir=$setsdir/lists/$1; _prefix=$2
471 [ -n "$_prefix" ] && prefix="$_prefix".
473 # Prefer a <prefix>.ad.${MACHINE_ARCH} over a
474 # <prefix>.ad.${MACHINE_CPU}, since the arch-
475 # specific one will be more specific than the
477 echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
478 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
479 [ "$shlib" != "no" ] && \
480 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
489 echo_if_exist_foreach()
491 local _list=$1; shift
492 for _suffix in $@; do
493 echo_if_exist ${_list}.${_suffix}
500 list=$(list_set_lists $setname)
504 echo >&2 "DEBUG: list_set_files: $l"
507 done | ${XARGS} ${SED} ${SUBST}
512 # Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
513 # as determined by <bsd.own.mk>.
517 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
518 .include <bsd.own.mk>
520 @echo \${MACHINE_CPU}
524 # arch_to_endian mach
526 # Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
527 # as determined by <bsd.endian.mk>.
531 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
532 .include <bsd.endian.mk>
534 @echo \${TARGET_ENDIANNESS}
548 # print_set_lists_{base,x,ext}
549 # list_set_lists_{base,x,ext}
550 # list_set_files_{base,x,ext}
551 for func in print_set_lists list_set_lists list_set_files; do
552 for x in base x ext; do
553 if [ $x = base ]; then
558 eval ${func}_${x} \(\) \{ $func \$$list \; \}