sets.subr revision 1.205
1# $NetBSD: sets.subr,v 1.205 2024/04/09 15:17:22 nia 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# module if != "no", enable MODULE sets 11# shlib shared library format (a.out, elf, or "") 12# stlib static library format (a.out, elf) 13# 14# The following <bsd.own.mk> variables are exported to the environment: 15# MACHINE 16# MACHINE_ARCH 17# MACHINE_CPU 18# HAVE_ACPI 19# HAVE_BINUTILS 20# HAVE_GCC 21# HAVE_GDB 22# HAVE_NVMM 23# HAVE_OPENSSL 24# HAVE_SSP 25# HAVE_UEFI 26# TOOLCHAIN_MISSING 27# OBJECT_FMT 28# as well as: 29# 30 31# 32# The following variables refer to tools that are used when building sets: 33# 34: ${AWK:=awk} 35: ${CKSUM:=cksum} 36: ${COMM:=comm} 37: ${DATE:=date} 38: ${DB:=db} 39: ${EGREP:=egrep} 40: ${ENV_CMD:=env} # ${ENV} is special to sh(1), ksh(1), etc. 41: ${FGREP:=fgrep} 42: ${FIND:=find} 43: ${GREP:=grep} 44: ${GZIP_CMD:=gzip} # ${GZIP} is special to gzip(1) 45: ${HOSTNAME_CMD:=hostname} # ${HOSTNAME} is special to bash(1) 46: ${HOST_SH:=sh} 47: ${IDENT:=ident} 48: ${JOIN:=join} 49: ${LS:=ls} 50: ${MAKE:=make} 51: ${MKTEMP:=mktemp} 52: ${MTREE:=mtree} 53: ${PASTE:=paste} 54: ${PAX:=pax} 55: ${PRINTF:=printf} 56: ${SED:=sed} 57: ${SORT:=sort} 58: ${STAT:=stat} 59: ${TSORT:=tsort} 60: ${UNAME:=uname} 61: ${WC:=wc} 62: ${XARGS:=xargs} 63 64# 65# If printf is a shell builtin command, then we can 66# implement cheaper versions of basename and dirname 67# that do not involve any fork/exec overhead. 68# If printf is not builtin, approximate it using echo, 69# and hope there are no weird file names that cause 70# some versions of echo to do the wrong thing. 71# (Converting to this version of dirname speeded up the 72# syspkgdeps script by an order of magnitude, from 68 73# seconds to 6.3 seconds on one particular host.) 74# 75# Note that naive approximations for dirname 76# using ${foo%/*} do not do the right thing in cases 77# where the result should be "/" or ".". 78# 79case "$(type printf)" in 80*builtin*) 81 basename () 82 { 83 local bn 84 bn="${1##*/}" 85 bn="${bn%$2}" 86 printf "%s\n" "$bn" 87 } 88 dirname () 89 { 90 local dn 91 case "$1" in 92 ?*/*) dn="${1%/*}" ;; 93 /*) dn=/ ;; 94 *) dn=. ;; 95 esac 96 printf "%s\n" "$dn" 97 } 98 ;; 99*) 100 basename () 101 { 102 local bn 103 bn="${1##*/}" 104 bn="${bn%$2}" 105 echo "$bn" 106 } 107 dirname () 108 { 109 local dn 110 case "$1" in 111 ?*/*) dn="${1%/*}" ;; 112 /*) dn=/ ;; 113 *) dn=. ;; 114 esac 115 echo "$dn" 116 } 117 ;; 118esac 119 120##### 121 122oIFS=$IFS 123IFS=" 124" 125 126for x in $( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do 127 eval export $x 128done 129 130IFS=$oIFS 131 132MKVARS="$( MAKEVERBOSE= ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )" 133 134##### 135 136setsdir=${rundir} 137obsolete=0 138if [ "${MKKMOD}" = "no" ]; then 139 module=no # MODULEs are off. 140 modset="" 141else 142 module=yes 143 modset="modules" 144fi 145if [ "${MKATF}" = "no" ]; then 146 testset="" 147else 148 testset="tests" 149fi 150if [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then 151 debugset="" 152 xdebugset="" 153else 154 debugset="debug" 155 xdebugset="xdebug" 156fi 157if [ -z "${debugset}" -o "${MKCOMPAT}" = "no" ]; then 158 debug32set="" 159else 160 debug32set="debug32" 161fi 162if [ "${MKDTB}" = "no" ]; then 163 dtbset="" 164else 165 dtbset="dtb" 166fi 167if [ "${MKHTML}" = "no" ]; then 168 manhtmlset="" 169else 170 manhtmlset="manhtml" 171fi 172if [ "${MKCOMPAT}" = "no" ]; then 173 base32set="" 174else 175 base32set="base32" 176fi 177 178# Determine lib type. Do this first so stlib also gets set. 179if [ "${OBJECT_FMT}" = "ELF" ]; then 180 shlib=elf 181else 182 shlib=aout 183fi 184stlib=$shlib 185# Now check for MKPIC or specials and turn off shlib if need be. 186if [ "${MKPIC}" = "no" ]; then 187 shlib=no 188fi 189nlists="base $base32set comp $debugset $debug32set $dtbset etc games gpufw man $manhtmlset misc $modset rescue $testset text" 190xlists="xbase xcomp $xdebugset xetc xfont xserver" 191 192OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k) 193if [ "${KERNEL_DIR}" = "yes" ]; then 194 MODULEDIR="netbsd/modules" 195else 196 MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" 197fi 198SUBST="s#@MODULEDIR@#${MODULEDIR}#g" 199SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g" 200SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g" 201 202# 203# list_set_files setfile [...] 204# 205# Produce a packing list for setfile(s). 206# In each file, a record consists of a path and a System Package name, 207# separated by whitespace. E.g., 208# 209# # $NetBSD: sets.subr,v 1.205 2024/04/09 15:17:22 nia Exp $ 210# . base-sys-root [keyword[,...]] 211# ./altroot base-sys-root 212# ./bin base-sys-root 213# ./bin/[ base-util-root 214# ./bin/cat base-util-root 215# [...] 216# 217# A # in the first column marks a comment. 218# 219# If ${obsolete} != 0, only entries with an "obsolete" keyword will 220# be printed. All other keywords must be present. 221# 222# The third field is an optional comma separated list of keywords to 223# control if a record is printed; every keyword listed must be enabled 224# for the record to be printed. The list of all available make variables 225# that can be turned on or off can be found by running in this directory: 226# 227# make -f mkvars.mk mkvarsyesno 228# 229# These MK<NAME> variables can be used as selectors in the sets as <name>. 230# 231# The following extra keywords are also available, listed by: 232# 233# make -f mkvars.mk mkextravars 234# 235# These are: 236# 1. The HAVE_<name>: 237# ssp ${HAVE_SSP} != no 238# libgcc_eh ${HAVE_LIBGCC_EH} != no 239# acpi ${HAVE_ACPI} != no 240# binutils=<n> <n> = value of ${HAVE_BINUTILS} 241# gcc=<n> <n> = value of ${HAVE_GCC} 242# gdb=<n> <n> = value of ${HAVE_GDB} 243# mesa_ver=<n> <n> = value of ${HAVE_MESA_VER} 244# nvmm ${HAVE_NVMM} != no 245# openssl=<n> <n> = value of ${HAVE_OPENSSL} 246# uefi ${HAVE_UEFI} != no 247# xorg_server_ver=<n> <n> = value of ${HAVE_XORG_SERVER_VER} 248# xorg_glamor ${HAVE_XORG_GLAMOR} != no 249# 250# 2. The USE_<name>: 251# use_inet6 ${USE_INET6} != no 252# use_kerberos ${USE_KERBEROS} != no 253# use_ldap ${USE_LDAP} != no 254# use_yp ${USE_YP} != no 255# 256# 3. Finally: 257# dummy dummy entry (ignored) 258# obsolete file is obsolete, and only printed if 259# ${obsolete} != 0 260# 261# solaris ${MKDTRACE} != no or ${MKZFS} != no or ${MKCTF} != no 262# 263# 264# endian=<n> <n> = value of ${TARGET_ENDIANNESS} 265# 266# 267# .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no" 268# automatically append ".gz" to the filename 269# 270# .man if ${MKMANZ} != "no" && ${MKMAN} != "no" 271# automatically append ".gz" to the filename 272# 273list_set_files() 274{ 275 if [ ${MAKEVERBOSE:-2} -lt 3 ]; then 276 verbose=false 277 else 278 verbose=true 279 fi 280 local CONFIGS="$( list_kernel_configs )" 281 print_set_lists "$@" | \ 282 ${AWK} -v obsolete=${obsolete} ' 283 function addkmod(line, fname, prefix, pat, patlen) { 284 if (substr(line, 1, patlen) != pat) { 285 return 286 } 287 for (d in kmodarchdirs) { 288 xd = prefix kmodarchdirs[d] 289 xline = xd substr(line, patlen + 1) 290 xfname = xd substr(fname, patlen + 1) 291 list[xline] = xfname 292 } 293 } 294 function adddebugkernel(line, fname, pat, patlen) { 295 if (pat == "" || substr(line, 1, patlen) != pat) { 296 return 0 297 } 298 split("'"${CONFIGS}"'", configs) 299 for (d in configs) { 300 xfname = fname 301 sub("@CONFIG@", configs[d], xfname) 302 xline = line; 303 sub("@CONFIG@", configs[d], xline) 304 list[xline] = xfname 305 } 306 return 1 307 } 308 BEGIN { 309 if (obsolete) 310 wanted["obsolete"] = 1 311 312 split("'"${MKVARS}"'", needvars) 313 doingcompat = 0 314 doingcompattests = 0 315 ignoredkeywords["compatdir"] = 1 316 ignoredkeywords["compatfile"] = 1 317 ignoredkeywords["compattestdir"] = 1 318 ignoredkeywords["compattestfile"] = 1 319 ignoredkeywords["compatx11dir"] = 1 320 ignoredkeywords["compatx11file"] = 1 321 for (vi in needvars) { 322 nv = needvars[vi] 323 kw = tolower(nv) 324 sub(/^mk/, "", kw) 325 sub(/^have_/, "", kw) 326 sub(/^target_endianness/, "endian", kw) 327 if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") { 328 wanted[kw] = 1 329 } 330 } 331 332 if ("compat" in wanted) { 333 doingcompat = 1; 334 split("'"${COMPATARCHDIRS}"'", compatarchdirs, ","); 335 compatdirkeywords["compatdir"] = 1 336 compatfilekeywords["compatfile"] = 1 337 338 if (wanted["compattests"]) { 339 doingcompattests = 1; 340 compatdirkeywords["compattestdir"] = 1 341 compatfilekeywords["compattestfile"] = 1 342 } 343 if (wanted["compatx11"]) { 344 doingcompatx11 = 1; 345 compatdirkeywords["compatx11dir"] = 1 346 compatfilekeywords["compatx11file"] = 1 347 } 348 } 349 350 if (("kmod" in wanted) && ("compatmodules" in wanted)) { 351 split("'"${KMODARCHDIRS}"'", kmodarchdirs, ","); 352 kmodprefix = "./stand/" 353 kmodpat = kmodprefix ENVIRON["MACHINE"] 354 l_kmodpat = length(kmodpat) 355 kmoddbprefix = "./usr/libdata/debug/stand/" 356 kmoddbpat = kmoddbprefix ENVIRON["MACHINE"] 357 l_kmoddbpat = length(kmoddbpat) 358 } 359 if ("debug" in wanted) { 360 debugkernelname = "./usr/libdata/debug/netbsd-@CONFIG@.debug" 361 l_debugkernelname = length(debugkernelname); 362 } 363 364 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") { 365 if ("binutils" in wanted) 366 wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1 367 if ("gcc" in wanted) 368 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1 369 if ("gdb" in wanted) 370 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1 371 } 372 if ("acpi" in wanted) { 373 wanted["acpi=" "'"${HAVE_ACPI}"'"] = 1 374 } 375 if ("mesa_ver" in wanted) { 376 wanted["mesa_ver=" "'"${HAVE_MESA_VER}"'"] = 1 377 } 378 if ("nvmm" in wanted) { 379 wanted["nvmm=" "'"${HAVE_NVMM}"'"] = 1 380 } 381 if ("openssl" in wanted) { 382 wanted["openssl=" "'"${HAVE_OPENSSL}"'"] = 1 383 } 384 if ("xorg_server_ver" in wanted) { 385 wanted["xorg_server_ver=" "'"${HAVE_XORG_SERVER_VER}"'"] = 1 386 } 387 if ("uefi" in wanted) { 388 wanted["uefi=" "'"${HAVE_UEFI}"'"] = 1 389 } 390 if (("man" in wanted) && ("catpages" in wanted)) 391 wanted[".cat"] = 1 392 if (("man" in wanted) && ("manpages" in wanted)) 393 wanted[".man"] = 1 394 if ("endian" in wanted) 395 wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1 396 if ("machine" in wanted) 397 wanted["machine=" "'"${MACHINE}"'"] = 1 398 if ("machine_arch" in wanted) 399 wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1 400 if ("machine_cpu" in wanted) 401 wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1 402 } 403 404 /^#/ { 405 next; 406 } 407 408 /^-/ { 409 notwanted[substr($1, 2)] = 1; 410 delete list [substr($1, 2)]; 411 next; 412 } 413 414 415 NF > 2 && $3 != "-" { 416 if (notwanted[$1] != "") 417 next; 418 split($3, keywords, ",") 419 show = 1 420 haveobs = 0 421 iscompatfile = 0 422 havekmod = 0 423 iscompatdir = 0 424 for (ki in keywords) { 425 kw = keywords[ki] 426 if (("manz" in wanted) && 427 (kw == ".cat" || kw == ".man")) 428 $1 = $1 ".gz" 429 if (substr(kw, 1, 1) == "!") { 430 kw = substr(kw, 2) 431 if (kw in wanted) 432 show = 0 433 } else if (kw in compatdirkeywords) { 434 iscompatdir = 1 435 } else if (kw in compatfilekeywords) { 436 iscompatfile = 1 437 } else if (kw == "nocompatmodules") { 438 havekmod = -1 439 } else if (kw in ignoredkeywords) { 440 # ignore 441 } else if (! (kw in wanted)) { 442 show = 0 443 } else if (kw == "kmod" && havekmod == 0) { 444 havekmod = 1 445 } 446 if (kw == "obsolete") 447 haveobs = 1 448 } 449 if (iscompatdir) { 450 for (d in cpaths) { 451 if (cpaths[d] == $1 "/") 452 next 453 } 454 cpaths[ncpaths++] = $1 "/" 455 } 456 if (obsolete && ! haveobs) 457 next 458 if (!show) 459 next 460 if (adddebugkernel($0, $1, debugkernelname, l_debugkernelname)) 461 next 462 463 list[$1] = $0 464 if (havekmod > 0) { 465 addkmod($0, $1, kmodprefix, kmodpat, l_kmodpat) 466 addkmod($0, $1, kmoddbprefix, kmoddbpat, l_kmoddbpat) 467 next 468 } 469 470 if (!doingcompat || !(iscompatfile || iscompatdir)) 471 next 472 473 if (iscompatfile) { 474 emitcompat[$1] = 1; 475 next 476 } 477 for (d in compatarchdirs) { 478 tmp = $0 479 xfile = $1 "/" compatarchdirs[d] 480 tmp = xfile substr(tmp, length($1) + 1) 481 if (xfile in notwanted) 482 continue; 483 sub("compatdir","compat",tmp); 484 sub("compattestdir","compat",tmp); 485 list[xfile] = tmp 486 } 487 next 488 } 489 490 { 491 if ($1 in notwanted) 492 next; 493 if (! obsolete) 494 list[$1] = $0 495 } 496 497 END { 498 for (i in list) { 499 print list[i] 500 if (! (i in emitcompat)) 501 continue; 502 l_i = length(i) 503 l = 0 504 for (j in cpaths) { 505 lx = length(cpaths[j]) 506 if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) { 507 continue; 508 } 509 if (lx > l) { 510 l = lx; 511 cpath = cpaths[j]; 512 } 513 } 514 for (d in compatarchdirs) { 515 tmp = list[i] 516 extrapath = compatarchdirs[d] "/" 517 xfile = cpath extrapath substr(i, l + 1) 518 if (xfile in notwanted) 519 continue; 520 sub("compatfile","compat",tmp); 521 sub("compattestfile","compat",tmp); 522 tmp = xfile substr(tmp, l_i + 1) 523 print tmp; 524 } 525 } 526 }' 527 528} 529 530# 531# list_set_lists setname 532# 533# Print to stdout a list of files, one filename per line, which 534# concatenate to create the packing list for setname. E.g., 535# 536# .../lists/base/mi 537# .../lists/base/rescue.mi 538# .../lists/base/md.i386 539# [...] 540# 541# For a given setname $set, the following files may be selected from 542# .../list/$set: 543# mi 544# mi.ext.* 545# ad.${MACHINE_ARCH} 546# (or) ad.${MACHINE_CPU} 547# ad.${MACHINE_CPU}.shl 548# md.${MACHINE}.${MACHINE_ARCH} 549# (or) md.${MACHINE} 550# stl.mi 551# stl.${stlib} 552# shl.mi 553# shl.mi.ext.* 554# shl.${shlib} 555# shl.${shlib}.ext.* 556# module.mi if ${module} != no 557# module.${MACHINE} if ${module} != no 558# module.ad.${MACHINE_ARCH} if ${module} != no 559# (or) module.ad.${MACHINE_CPU} if ${module} != no 560# rescue.shl 561# rescue.${MACHINE} 562# rescue.ad.${MACHINE_ARCH} 563# (or) rescue.ad.${MACHINE_CPU} 564# rescue.ad.${MACHINE_CPU}.shl 565# 566# Environment: 567# shlib 568# stlib 569# 570list_set_lists() 571{ 572 setname=$1 573 574 list_set_lists_mi $setname 575 list_set_lists_ad $setname 576 list_set_lists_md $setname 577 list_set_lists_stl $setname 578 list_set_lists_shl $setname 579 list_set_lists_module $setname 580 list_set_lists_rescue $setname 581 return 0 582} 583 584list_set_lists_mi() 585{ 586 setdir=$setsdir/lists/$1 587 # always exist! 588 echo $setdir/mi 589} 590 591list_set_lists_ad() 592{ 593 setdir=$setsdir/lists/$1 594 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 595 list_set_lists_common_ad $1 596} 597 598list_set_lists_md() 599{ 600 setdir=$setsdir/lists/$1 601 echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \ 602 echo_if_exist $setdir/md.${MACHINE} 603} 604 605list_set_lists_stl() 606{ 607 setdir=$setsdir/lists/$1 608 echo_if_exist $setdir/stl.mi 609 echo_if_exist $setdir/stl.${stlib} 610} 611 612list_set_lists_shl() 613{ 614 setdir=$setsdir/lists/$1 615 [ "$shlib" != "no" ] || return 616 echo_if_exist $setdir/shl.mi 617 echo_if_exist $setdir/shl.${shlib} 618} 619 620list_set_lists_module() 621{ 622 setdir=$setsdir/lists/$1 623 [ "$module" != "no" ] || return 624 echo_if_exist $setdir/module.mi 625 echo_if_exist $setdir/module.${MACHINE} 626 echo_if_exist $setdir/module.ad.${MACHINE} 627 echo_if_exist $setdir/module.md.${MACHINE} 628 # XXX module never has .shl 629 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 630 list_set_lists_common_ad $1 module 631} 632 633list_set_lists_rescue() 634{ 635 setdir=$setsdir/lists/$1 636 echo_if_exist $setdir/rescue.mi 637 echo_if_exist $setdir/rescue.${MACHINE} 638 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 639 list_set_lists_common_ad $1 rescue 640} 641 642list_set_lists_common_ad() 643{ 644 setdir=$setsdir/lists/$1; _prefix=$2 645 646 [ -n "$_prefix" ] && prefix="$_prefix". 647 648 # Prefer a <prefix>.ad.${MACHINE_ARCH} over a 649 # <prefix>.ad.${MACHINE_CPU}, since the arch- 650 # specific one will be more specific than the 651 # cpu-specific one. 652 echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \ 653 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU} 654 [ "$shlib" != "no" ] && \ 655 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl 656} 657 658echo_if_exist() 659{ 660 [ -f $1 ] && echo $1 661 return $? 662} 663 664echo_if_exist_foreach() 665{ 666 local _list=$1; shift 667 for _suffix in $@; do 668 echo_if_exist ${_list}.${_suffix} 669 done 670} 671 672print_set_lists() 673{ 674 for setname; do 675 list=$(list_set_lists $setname) 676 for l in $list; do 677 echo $l 678 if $verbose; then 679 echo >&2 "DEBUG: list_set_files: $l" 680 fi 681 done 682 done | ${XARGS} ${SED} ${SUBST} 683} 684 685 686list_kernel_configs() 687{ 688 (cd ${NETBSDSRCDIR}/etc 689 MAKEFLAGS= \ 690 ${MAKE} -m ${NETBSDSRCDIR}/share/mk -V '${ALL_KERNELS}') 691} 692 693# arch_to_cpu mach 694# 695# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach, 696# as determined by <bsd.own.mk>. 697# 698arch_to_cpu() 699{ 700 MACHINE_ARCH=${1} MAKEFLAGS= \ 701 ${MAKE} -m ${NETBSDSRCDIR}/share/mk \ 702 -f ${NETBSDSRCDIR}/share/mk/bsd.own.mk \ 703 -V '${MACHINE_CPU}' 704} 705 706# arch_to_endian mach 707# 708# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach, 709# as determined by <bsd.endian.mk>. 710# 711arch_to_endian() 712{ 713 MACHINE_ARCH=${1} MAKEFLAGS= \ 714 ${MAKE} -m ${NETBSDSRCDIR}/share/mk \ 715 -f ${NETBSDSRCDIR}/share/mk/bsd.endian.mk \ 716 -V '${TARGET_ENDIANNESS}' 717} 718 719##### 720 721# print_mkvars 722print_mkvars() 723{ 724 for v in $MKVARS; do 725 eval echo $v=\$$v 726 done 727} 728 729# print_set_lists_{base,x,ext} 730# list_set_lists_{base,x,ext} 731# list_set_files_{base,x,ext} 732for func in print_set_lists list_set_lists list_set_files; do 733 for x in base x ext; do 734 if [ $x = base ]; then 735 list=nlists 736 else 737 list=${x}lists 738 fi 739 eval ${func}_${x} \(\) \{ $func \$$list \; \} 740 done 741done 742