1 # $NetBSD: sets.subr,v 1.173 2015/07/23 08:03:25 mrg 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
145 testset="tests minix-tests"
147 if [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then
151 debugset="minix-debug"
154 # Determine lib type. Do this first so stlib also gets set.
155 if [ "${OBJECT_FMT}" = "ELF" ]; then
161 # Now check for MKPIC or specials and turn off shlib if need be.
162 if [ "${MKPIC}" = "no" ]; then
166 nlists="minix-base minix-comp minix-games minix-kernel minix-man $testset $debugset"
167 #nlists="base comp $debugset etc games man misc $modset $testset text"
168 xlists="xbase xcomp $xdebugset xetc xfont xserver"
169 extlists="extbase extcomp extetc"
171 OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
172 MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
173 SUBST="s#@MODULEDIR@#${MODULEDIR}#g"
174 SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
175 SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
178 # list_set_files setfile [...]
180 # Produce a packing list for setfile(s).
181 # In each file, a record consists of a path and a System Package name,
182 # separated by whitespace. E.g.,
184 # # $NetBSD: sets.subr,v 1.173 2015/07/23 08:03:25 mrg Exp $
185 # . base-sys-root [keyword[,...]]
186 # ./altroot base-sys-root
187 # ./bin base-sys-root
188 # ./bin/[ base-util-root
189 # ./bin/cat base-util-root
192 # A # in the first column marks a comment.
194 # If ${obsolete} != 0, only entries with an "obsolete" keyword will
195 # be printed. All other keywords must be present.
197 # The third field is an optional comma separated list of keywords to
198 # control if a record is printed; every keyword listed must be enabled
199 # for the record to be printed. The following keywords are available:
200 # dummy dummy entry (ignored)
201 # obsolete file is obsolete, and only printed if
205 # bfd obsolete, use binutils.
206 # binutils ${MKBINUTILS} != no
207 # bsdgrep ${MKBSDGREP} != no
208 # catpages ${MKCATPAGES} != no
209 # compat ${MKCOMPAT} != no
210 # compatmodules ${MKCOMPATMODULES} != no
211 # compattests ${MKCOMPATTESTS} != no
212 # crypto ${MKCRYPTO} != no
213 # crypto_rc5 ${MKCRYPTO_RC5} != no
215 # debug ${MKDEBUG} != no
216 # debuglib ${MKDEBUGLIB} != no
218 # dtrace ${MKDTRACE} != no
219 # dynamicroot ${MKDYNAMICROOT} != no
220 # extsrc ${MKEXTSRC} != no
222 # gcccmds ${MKGCCCMDS} != no
224 # hesiod ${MKHESIOD} != no
225 # html ${MKHTML} != no
226 # inet6 ${MKINET6} != no
227 # info ${MKINFO} != no
228 # ipfilter ${MKIPFILTER} != no
229 # iscsi ${MKISCSI} != no
230 # kerberos ${MKKERBEROS} != no
231 # kmod ${MKKMOD} != no
232 # kyua ${MKKYUA} != no
233 # ldap ${MKLDAP} != no
234 # lint ${MKLINT} != no
235 # libcxx ${MKLIBCXX} != no
236 # libgcc_eh ${HAVE_LIBGCC_EH} != no
237 # libstdcxx ${MKLIBSTDCXX} != no
239 # lldb ${MKLLDB} != no
240 # llvm ${MKLLVM} != no
242 # makemandb ${MKMAKEMANDB} != no
244 # manpages ${MKMANPAGES} != no
245 # manz ${MKMANZ} != no
246 # mclinker ${MKMCLINKER} != no
247 # mdns ${MKMDNS} != no
254 # picinstall ${MKPICINSTALL} != no
255 # pigzgzip ${MKPIGZGZIP} != no
256 # postfix ${MKPOSTFIX} != no
257 # profile ${MKPROFILE} != no
258 # perfuse ${MKPERFUSE} != no
259 # rump ${MKRUMP} != no
260 # share ${MKSHARE} != no
261 # skey ${MKSKEY} != no
262 # sljit ${MKSLJIT} != no
263 # softfloat ${MKSOFTFLOAT} != no
264 # solaris ${MKDTRACE} != no or ${MKZFS} != no
265 # ssp ${HAVE_SSP} != no
267 # xorg ${MKX11} != no
268 # xorg_server ${MKXORG_SERVER} != no
272 # endian=<n> <n> = value of ${TARGET_ENDIANNESS}
273 # binutils=<n> <n> = value of ${HAVE_BINUTILS}
274 # gcc=<n> <n> = value of ${HAVE_GCC}
275 # gdb=<n> <n> = value of ${HAVE_GDB}
277 # use_inet6 ${USE_INET6} != no
278 # use_kerberos ${USE_KERBEROS} != no
279 # use_yp ${USE_YP} != no
281 # .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
282 # automatically append ".gz" to the filename
284 # .man if ${MKMANZ} != "no" && ${MKMAN} != "no"
285 # automatically append ".gz" to the filename
289 if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
294 print_set_lists "$@" | \
295 ${AWK} -v obsolete=${obsolete} '
298 wanted["obsolete"] = 1
300 split("'"${MKVARS}"'", needvars)
303 ignoredkeywords["compatdir"] = 1
304 ignoredkeywords["compatfile"] = 1
305 ignoredkeywords["compattestdir"] = 1
306 ignoredkeywords["compattestfile"] = 1
307 ignoredkeywords["compatx11dir"] = 1
308 ignoredkeywords["compatx11file"] = 1
309 for (vi in needvars) {
313 sub(/^have_/, "", kw)
314 sub(/^target_endianness/, "endian", kw)
315 if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
320 if ("compat" in wanted) {
322 split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
323 compatdirkeywords["compatdir"] = 1
324 compatfilekeywords["compatfile"] = 1
326 if (wanted["compattests"]) {
327 doingcompattests = 1;
328 compatdirkeywords["compattestdir"] = 1
329 compatfilekeywords["compattestfile"] = 1
331 if (wanted["compatx11"]) {
333 compatdirkeywords["compatx11dir"] = 1
334 compatfilekeywords["compatx11file"] = 1
338 if (("kmod" in wanted) && ("compatmodules" in wanted)) {
339 split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
340 kmodpat = "./stand/" ENVIRON["MACHINE"]
341 l_kmodpat = length(kmodpat)
344 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
345 if ("binutils" in wanted)
346 wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
348 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
350 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
352 if (("man" in wanted) && ("catpages" in wanted))
354 if (("man" in wanted) && ("manpages" in wanted))
356 if ("endian" in wanted)
357 wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
358 if ("machine" in wanted)
359 wanted["machine=" "'"${MACHINE}"'"] = 1
360 if ("machine_arch" in wanted)
361 wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
362 if ("machine_cpu" in wanted)
363 wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
371 notwanted[substr($1, 2)] = 1;
372 delete list [substr($1, 2)];
377 NF > 2 && $3 != "-" {
378 if (notwanted[$1] != "")
380 split($3, keywords, ",")
386 for (ki in keywords) {
388 if (("manz" in wanted) &&
389 (kw == ".cat" || kw == ".man"))
391 if (substr(kw, 1, 1) == "!") {
395 } else if (kw in compatdirkeywords) {
397 } else if (kw in compatfilekeywords) {
399 } else if (kw == "nocompatmodules") {
401 } else if (kw in ignoredkeywords) {
403 } else if (! (kw in wanted)) {
405 } else if (kw == "kmod" && havekmod == 0) {
408 if (kw == "obsolete")
411 if (obsolete && ! haveobs)
417 if (havekmod > 0 && substr($1,1,l_kmodpat) == kmodpat) {
418 for (d in kmodarchdirs) {
419 xd = "./stand/" kmodarchdirs[d]
420 xfile = xd substr($1, l_kmodpat+1)
421 tmp = xd substr($0, l_kmodpat+1)
427 if (!doingcompat || !(iscompatfile || iscompatdir))
435 if (cpaths[d] == $1 "/")
438 cpaths[ncpaths++] = $1 "/"
439 for (d in compatarchdirs) {
441 xfile = $1 "/" compatarchdirs[d]
442 tmp = xfile substr(tmp, length($1) + 1)
443 if (xfile in notwanted)
445 sub("compatdir","compat",tmp);
446 sub("compattestdir","compat",tmp);
462 if (! (i in emitcompat))
467 lx = length(cpaths[j])
468 if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
476 for (d in compatarchdirs) {
478 extrapath = compatarchdirs[d] "/"
479 xfile = cpath extrapath substr(i, l + 1)
480 if (xfile in notwanted)
482 sub("compatfile","compat",tmp);
483 sub("compattestfile","compat",tmp);
484 tmp = xfile substr(tmp, l_i + 1)
493 # list_set_lists setname
495 # Print to stdout a list of files, one filename per line, which
496 # concatenate to create the packing list for setname. E.g.,
499 # .../lists/base/rescue.mi
500 # .../lists/base/md.i386
503 # For a given setname $set, the following files may be selected from
508 # (or) ad.${MACHINE_CPU}
509 # ad.${MACHINE_CPU}.shl
510 # md.${MACHINE}.${MACHINE_ARCH}
518 # module.mi if ${module} != no
519 # module.${MACHINE} if ${module} != no
520 # module.ad.${MACHINE_ARCH} if ${module} != no
521 # (or) module.ad.${MACHINE_CPU} if ${module} != no
524 # rescue.ad.${MACHINE_ARCH}
525 # (or) rescue.ad.${MACHINE_CPU}
526 # rescue.ad.${MACHINE_CPU}.shl
536 list_set_lists_mi $setname
537 list_set_lists_ad $setname
538 list_set_lists_md $setname
539 list_set_lists_stl $setname
540 list_set_lists_shl $setname
541 list_set_lists_module $setname
542 list_set_lists_rescue $setname
548 setdir=$setsdir/lists/$1
555 setdir=$setsdir/lists/$1
556 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
557 list_set_lists_common_ad $1
562 setdir=$setsdir/lists/$1
563 echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
564 echo_if_exist $setdir/md.${MACHINE}
569 setdir=$setsdir/lists/$1
570 echo_if_exist $setdir/stl.mi
571 echo_if_exist $setdir/stl.${stlib}
576 setdir=$setsdir/lists/$1
577 [ "$shlib" != "no" ] || return
578 echo_if_exist $setdir/shl.mi
579 echo_if_exist $setdir/shl.${shlib}
582 list_set_lists_module()
584 setdir=$setsdir/lists/$1
585 [ "$module" != "no" ] || return
586 echo_if_exist $setdir/module.mi
587 echo_if_exist $setdir/module.${MACHINE}
588 # XXX module never has .shl
589 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
590 list_set_lists_common_ad $1 module
593 list_set_lists_rescue()
595 setdir=$setsdir/lists/$1
596 echo_if_exist $setdir/rescue.mi
597 echo_if_exist $setdir/rescue.${MACHINE}
598 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
599 list_set_lists_common_ad $1 rescue
602 list_set_lists_common_ad()
604 setdir=$setsdir/lists/$1; _prefix=$2
606 [ -n "$_prefix" ] && prefix="$_prefix".
608 # Prefer a <prefix>.ad.${MACHINE_ARCH} over a
609 # <prefix>.ad.${MACHINE_CPU}, since the arch-
610 # specific one will be more specific than the
612 echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
613 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
614 [ "$shlib" != "no" ] && \
615 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
624 echo_if_exist_foreach()
626 local _list=$1; shift
627 for _suffix in $@; do
628 echo_if_exist ${_list}.${_suffix}
635 list=$(list_set_lists $setname)
639 echo >&2 "DEBUG: list_set_files: $l"
642 done | ${XARGS} ${SED} ${SUBST}
647 # Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
648 # as determined by <bsd.own.mk>.
652 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
653 .include <bsd.own.mk>
655 @echo \${MACHINE_CPU}
659 # arch_to_endian mach
661 # Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
662 # as determined by <bsd.endian.mk>.
666 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
667 .include <bsd.endian.mk>
669 @echo \${TARGET_ENDIANNESS}
683 # print_set_lists_{base,x,ext}
684 # list_set_lists_{base,x,ext}
685 # list_set_files_{base,x,ext}
686 for func in print_set_lists list_set_lists list_set_files; do
687 for x in base x ext; do
688 if [ $x = base ]; then
693 eval ${func}_${x} \(\) \{ $func \$$list \; \}