sets.subr revision 1.165
1# $NetBSD: sets.subr,v 1.165 2015/06/22 05:59:59 matt 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# 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) 14# 15# The following <bsd.own.mk> variables are exported to the environment: 16# MACHINE 17# MACHINE_ARCH 18# MACHINE_CPU 19# HAVE_BINUTILS 20# HAVE_GCC 21# HAVE_GDB 22# HAVE_SSP 23# TOOLCHAIN_MISSING 24# OBJECT_FMT 25# as well as: 26# 27 28# 29# The following variables refer to tools that are used when building sets: 30# 31: ${AWK:=awk} 32: ${CKSUM:=cksum} 33: ${COMM:=comm} 34: ${DATE:=date} 35: ${DB:=db} 36: ${EGREP:=egrep} 37: ${ENV_CMD:=env} # ${ENV} is special to sh(1), ksh(1), etc. 38: ${FGREP:=fgrep} 39: ${FIND:=find} 40: ${GREP:=grep} 41: ${GZIP_CMD:=gzip} # ${GZIP} is special to gzip(1) 42: ${HOSTNAME_CMD:=hostname} # ${HOSTNAME} is special to bash(1) 43: ${HOST_SH:=sh} 44: ${IDENT:=ident} 45: ${JOIN:=join} 46: ${LS:=ls} 47: ${MAKE:=make} 48: ${MKTEMP:=mktemp} 49: ${MTREE:=mtree} 50: ${PASTE:=paste} 51: ${PAX:=pax} 52: ${PRINTF:=printf} 53: ${SED:=sed} 54: ${SORT:=sort} 55: ${STAT:=stat} 56: ${TSORT:=tsort} 57: ${UNAME:=uname} 58: ${WC:=wc} 59: ${XARGS:=xargs} 60 61# 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.) 71# 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 ".". 75# 76case "$(type printf)" in 77*builtin*) 78 basename () 79 { 80 local bn 81 bn="${1##*/}" 82 bn="${bn%$2}" 83 printf "%s\n" "$bn" 84 } 85 dirname () 86 { 87 local dn 88 case "$1" in 89 ?*/*) dn="${1%/*}" ;; 90 /*) dn=/ ;; 91 *) dn=. ;; 92 esac 93 printf "%s\n" "$dn" 94 } 95 ;; 96*) 97 basename () 98 { 99 local bn 100 bn="${1##*/}" 101 bn="${bn%$2}" 102 echo "$bn" 103 } 104 dirname () 105 { 106 local dn 107 case "$1" in 108 ?*/*) dn="${1%/*}" ;; 109 /*) dn=/ ;; 110 *) dn=. ;; 111 esac 112 echo "$dn" 113 } 114 ;; 115esac 116 117##### 118 119oIFS=$IFS 120IFS=" 121" 122 123for x in $( ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do 124 eval export $x 125done 126 127IFS=$oIFS 128 129MKVARS="$( ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )" 130 131##### 132 133setsdir=${rundir} 134obsolete=0 135if [ "${MKKMOD}" = "no" ]; then 136 module=no # MODULEs are off. 137 modset="" 138else 139 module=yes 140 modset="modules" 141fi 142if [ "${MKATF}" = "no" ]; then 143 testset="" 144else 145 testset="tests" 146fi 147if [ "${MKDEBUG}" = "no" ]; then 148 debugset="" 149 xdebugset="" 150else 151 debugset="debug" 152 xdebugset="xdebug" 153fi 154# Determine lib type. Do this first so stlib also gets set. 155if [ "${OBJECT_FMT}" = "ELF" ]; then 156 shlib=elf 157else 158 shlib=aout 159fi 160stlib=$shlib 161# Now check for MKPIC or specials and turn off shlib if need be. 162if [ "${MKPIC}" = "no" ]; then 163 shlib=no 164fi 165nlists="base comp $debugset etc games man misc $modset $testset text" 166xlists="xbase xcomp $xdebugset xetc xfont xserver" 167extlists="extbase extcomp extetc" 168 169OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k) 170MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" 171SUBST="s#@MODULEDIR@#${MODULEDIR}#g" 172SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g" 173SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g" 174 175# 176# list_set_files setfile [...] 177# 178# Produce a packing list for setfile(s). 179# In each file, a record consists of a path and a System Package name, 180# separated by whitespace. E.g., 181# 182# # $NetBSD: sets.subr,v 1.165 2015/06/22 05:59:59 matt Exp $ 183# . base-sys-root [keyword[,...]] 184# ./altroot base-sys-root 185# ./bin base-sys-root 186# ./bin/[ base-util-root 187# ./bin/cat base-util-root 188# [...] 189# 190# A # in the first column marks a comment. 191# 192# If ${obsolete} != 0, only entries with an "obsolete" keyword will 193# be printed. All other keywords must be present. 194# 195# The third field is an optional comma separated list of keywords to 196# control if a record is printed; every keyword listed must be enabled 197# for the record to be printed. The following keywords are available: 198# dummy dummy entry (ignored) 199# obsolete file is obsolete, and only printed if 200# ${obsolete} != 0 201# 202# atf ${MKATF} != no 203# bfd obsolete, use binutils. 204# binutils ${MKBINUTILS} != no 205# bsdgrep ${MKBSDGREP} != no 206# catpages ${MKCATPAGES} != no 207# compat ${MKCOMPAT} != no 208# compatmodules ${MKCOMPATMODULES} != no 209# compattests ${MKCOMPATTESTS} != no 210# crypto ${MKCRYPTO} != no 211# crypto_rc5 ${MKCRYPTO_RC5} != no 212# cvs ${MKCVS} != no 213# debug ${MKDEBUG} != no 214# debuglib ${MKDEBUGLIB} != no 215# doc ${MKDOC} != no 216# dtrace ${MKDTRACE} != no 217# dynamicroot ${MKDYNAMICROOT} != no 218# extsrc ${MKEXTSRC} != no 219# gcc ${MKGCC} != no 220# gcccmds ${MKGCCCMDS} != no 221# gdb ${MKGDB} != no 222# hesiod ${MKHESIOD} != no 223# html ${MKHTML} != no 224# inet6 ${MKINET6} != no 225# info ${MKINFO} != no 226# ipfilter ${MKIPFILTER} != no 227# iscsi ${MKISCSI} != no 228# kerberos ${MKKERBEROS} != no 229# kmod ${MKKMOD} != no 230# kyua ${MKKYUA} != no 231# ldap ${MKLDAP} != no 232# lint ${MKLINT} != no 233# libcxx ${MKLIBCXX} != no 234# libgcc_eh ${HAVE_LIBGCC_EH} != no 235# libstdcxx ${MKLIBSTDCXX} != no 236# lld ${MKLLD} != no 237# lldb ${MKLLDB} != no 238# llvm ${MKLLVM} != no 239# lvm ${MKLVM} != no 240# makemandb ${MKMAKEMANDB} != no 241# man ${MKMAN} != no 242# manpages ${MKMANPAGES} != no 243# manz ${MKMANZ} != no 244# mclinker ${MKMCLINKER} != no 245# mdns ${MKMDNS} != no 246# nls ${MKNLS} != no 247# nvi ${MKNVI} != no 248# pam ${MKPAM} != no 249# pcc ${MKPCC} != no 250# pf ${MKPF} != no 251# pic ${MKPIC} != no 252# picinstall ${MKPICINSTALL} != no 253# postfix ${MKPOSTFIX} != no 254# profile ${MKPROFILE} != no 255# perfuse ${MKPERFUSE} != no 256# rump ${MKRUMP} != no 257# share ${MKSHARE} != no 258# skey ${MKSKEY} != no 259# sljit ${MKSLJIT} != no 260# softfloat ${MKSOFTFLOAT} != no 261# solaris ${MKDTRACE} != no or ${MKZFS} != no 262# ssp ${HAVE_SSP} != no 263# tpm ${MKTPM} != no 264# x11 ${MKX11} != no && ${X11FLAVOUR} != "Xorg" 265# xorg ${MKX11} != no && ${X11FLAVOUR} == "Xorg" 266# xorg_server ${MKXORG_SERVER} != no 267# yp ${MKYP} != no 268# zfs ${MKZFS} != no 269# 270# endian=<n> <n> = value of ${TARGET_ENDIANNESS} 271# binutils=<n> <n> = value of ${HAVE_BINUTILS} 272# gcc=<n> <n> = value of ${HAVE_GCC} 273# gdb=<n> <n> = value of ${HAVE_GDB} 274# 275# use_inet6 ${USE_INET6} != no 276# use_kerberos ${USE_KERBEROS} != no 277# use_yp ${USE_YP} != no 278# 279# .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no" 280# automatically append ".gz" to the filename 281# 282# .man if ${MKMANZ} != "no" && ${MKMAN} != "no" 283# automatically append ".gz" to the filename 284# 285list_set_files() 286{ 287 if [ ${MAKEVERBOSE:-2} -lt 3 ]; then 288 verbose=false 289 else 290 verbose=true 291 fi 292 print_set_lists "$@" | \ 293 ${AWK} -v obsolete=${obsolete} ' 294 BEGIN { 295 x="tmp.out" 296 if (obsolete) 297 wanted["obsolete"] = 1 298 299 split("'"${MKVARS}"'", needvars) 300 doingcompat = 0 301 doingcompattests = 0 302 ignoredkeywords["compatdir"] = 1 303 ignoredkeywords["compatfile"] = 1 304 ignoredkeywords["compattestdir"] = 1 305 ignoredkeywords["compattestfile"] = 1 306 for (vi in needvars) { 307 nv = needvars[vi] 308 kw = tolower(nv) 309 sub(/^mk/, "", kw) 310 sub(/^have_/, "", kw) 311 sub(/^target_endianness/, "endian", kw) 312 if (kw == "compat" && ENVIRON[nv] != "no") { 313 doingcompat = 1; 314 split("'"${COMPATARCHDIRS}"'", compatarchdirs, ","); 315 wanted[kw] = 1 316 compatdirkeywords["compatdir"] = 1 317 compatfilekeywords["compatfile"] = 1 318 } else if (kw == "compattests" && ENVIRON[nv] != "no") { 319 doingcompattests = 1; 320 compatdirkeywords["compattestdir"] = 1 321 compatfilekeywords["compattestfile"] = 1 322 } else if (kw == "kmod" && ENVIRON[nv] != "no") { 323 split("'"${KMODARCHDIRS}"'", kmodarchdirs, ","); 324 wanted[kw] = 1 325 kmodpat = "./stand/" ENVIRON["MACHINE"] 326 l_kmodpat = length(kmodpat) 327 } else if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATDIRS" && nv != "MODULEARCHDIRS") 328 wanted[kw] = 1 329 } 330 331 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") { 332 if ("binutils" in wanted) 333 wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1 334 if ("gcc" in wanted) 335 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1 336 if ("gdb" in wanted) 337 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1 338 } 339 if (("man" in wanted) && ("catpages" in wanted)) 340 wanted[".cat"] = 1 341 if (("man" in wanted) && ("manpages" in wanted)) 342 wanted[".man"] = 1 343 if ("endian" in wanted) 344 wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1 345 if ("machine" in wanted) 346 wanted["machine=" "'"${MACHINE}"'"] = 1 347 if ("machine_arch" in wanted) 348 wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1 349 if ("machine_cpu" in wanted) 350 wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1 351 } 352 353 /^#/ { 354 next; 355 } 356 357 /^-/ { 358 notwanted[substr($1, 2)] = 1; 359 delete list [substr($1, 2)]; 360 next; 361 } 362 363 364 NF > 2 && $3 != "-" { 365 if (notwanted[$1] != "") 366 next; 367 split($3, keywords, ",") 368 show = 1 369 haveobs = 0 370 havecompat = 0 371 havekmod = 0 372 iscompatdir = 0 373 for (ki in keywords) { 374 kw = keywords[ki] 375 if (("manz" in wanted) && 376 (kw == ".cat" || kw == ".man")) 377 $1 = $1 ".gz" 378 if (substr(kw, 1, 1) == "!") { 379 kw = substr(kw, 2) 380 if (kw in wanted) 381 show = 0 382 } else if (kw in compatdirkeywords) { 383 iscompatdir = 1 384 } else if (kw in compatfilekeywords) { 385 havecompat = 1 386 } else if (kw in ignoredkeywords) { 387 # ignore 388 } else { 389 if (! (kw in wanted)) 390 show = 0 391 else if (kw == "kmod") 392 havekmod = 1 393 } 394 if (kw == "obsolete") 395 haveobs = 1 396 } 397 if (obsolete && ! haveobs) 398 next 399 if (!show) 400 next 401 402 list[$1] = $0 403 if (havekmod && substr($1,1,l_kmodpat) == kmodpat) { 404 for (d in kmodarchdirs) { 405 xd = "./stand/" kmodarchdirs[d] 406 xfile = xd substr($1, l_kmodpat+1) 407 tmp = xd substr($0, l_kmodpat+1) 408 list[xfile] = tmp; 409 } 410 next 411 } 412 413 if (!doingcompat || !(havecompat || iscompatdir)) 414 next 415 416 if (havecompat) { 417 emitcompat[$1] = 1; 418 next; 419 } 420 cpaths[ncpaths++] = $1 "/" 421 for (d in compatarchdirs) { 422 tmp = $0 423 xfile = $1 "/" compatarchdirs[d] 424 tmp = xfile substr(tmp, length($1) + 1) 425 if (xfile in notwanted) 426 continue; 427 sub("compatdir","compat",tmp); 428 sub("compattestdir","compat",tmp); 429 list[xfile] = tmp 430 } 431 next 432 } 433 434 { 435 if ($1 in notwanted) 436 next; 437 if (! obsolete) 438 list[$1] = $0 439 } 440 441 END { 442 for (i in list) { 443 print list[i] 444 if (! (i in emitcompat)) 445 continue; 446 l_i = length(i) 447 l = 0 448 for (j in cpaths) { 449 lx = length(cpaths[j]) 450 if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) { 451 continue; 452 } 453 if (lx > l) { 454 l = lx; 455 cpath = cpaths[j]; 456 } 457 } 458 for (d in compatarchdirs) { 459 tmp = list[i] 460 extrapath = compatarchdirs[d] "/" 461 xfile = cpath extrapath substr(i, l + 1) 462 if (xfile in notwanted) 463 continue; 464 sub("compatfile","compat",tmp); 465 sub("compattestfile","compat",tmp); 466 tmp = xfile substr(tmp, l_i + 1) 467 print tmp; 468 } 469 } 470 }' 471 472} 473 474# 475# list_set_lists setname 476# 477# Print to stdout a list of files, one filename per line, which 478# concatenate to create the packing list for setname. E.g., 479# 480# .../lists/base/mi 481# .../lists/base/rescue.mi 482# .../lists/base/md.i386 483# [...] 484# 485# For a given setname $set, the following files may be selected from 486# .../list/$set: 487# mi 488# mi.ext.* 489# ad.${MACHINE_ARCH} 490# (or) ad.${MACHINE_CPU} 491# ad.${MACHINE_CPU}.shl 492# md.${MACHINE}.${MACHINE_ARCH} 493# (or) md.${MACHINE} 494# stl.mi 495# stl.${stlib} 496# shl.mi 497# shl.mi.ext.* 498# shl.${shlib} 499# shl.${shlib}.ext.* 500# module.mi if ${module} != no 501# module.${MACHINE} if ${module} != no 502# module.ad.${MACHINE_ARCH} if ${module} != no 503# (or) module.ad.${MACHINE_CPU} if ${module} != no 504# rescue.shl 505# rescue.${MACHINE} 506# rescue.ad.${MACHINE_ARCH} 507# (or) rescue.ad.${MACHINE_CPU} 508# rescue.ad.${MACHINE_CPU}.shl 509# 510# Environment: 511# shlib 512# stlib 513# 514list_set_lists() 515{ 516 setname=$1 517 518 list_set_lists_mi $setname 519 list_set_lists_ad $setname 520 list_set_lists_md $setname 521 list_set_lists_stl $setname 522 list_set_lists_shl $setname 523 list_set_lists_module $setname 524 list_set_lists_rescue $setname 525 return 0 526} 527 528list_set_lists_mi() 529{ 530 setdir=$setsdir/lists/$1 531 # always exist! 532 echo $setdir/mi 533} 534 535list_set_lists_ad() 536{ 537 setdir=$setsdir/lists/$1 538 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 539 list_set_lists_common_ad $1 540} 541 542list_set_lists_md() 543{ 544 setdir=$setsdir/lists/$1 545 echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \ 546 echo_if_exist $setdir/md.${MACHINE} 547} 548 549list_set_lists_stl() 550{ 551 setdir=$setsdir/lists/$1 552 echo_if_exist $setdir/stl.mi 553 echo_if_exist $setdir/stl.${stlib} 554} 555 556list_set_lists_shl() 557{ 558 setdir=$setsdir/lists/$1 559 [ "$shlib" != "no" ] || return 560 echo_if_exist $setdir/shl.mi 561 echo_if_exist $setdir/shl.${shlib} 562} 563 564list_set_lists_module() 565{ 566 setdir=$setsdir/lists/$1 567 [ "$module" != "no" ] || return 568 echo_if_exist $setdir/module.mi 569 echo_if_exist $setdir/module.${MACHINE} 570 # XXX module never has .shl 571 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 572 list_set_lists_common_ad $1 module 573} 574 575list_set_lists_rescue() 576{ 577 setdir=$setsdir/lists/$1 578 echo_if_exist $setdir/rescue.mi 579 echo_if_exist $setdir/rescue.${MACHINE} 580 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 581 list_set_lists_common_ad $1 rescue 582} 583 584list_set_lists_common_ad() 585{ 586 setdir=$setsdir/lists/$1; _prefix=$2 587 588 [ -n "$_prefix" ] && prefix="$_prefix". 589 590 # Prefer a <prefix>.ad.${MACHINE_ARCH} over a 591 # <prefix>.ad.${MACHINE_CPU}, since the arch- 592 # specific one will be more specific than the 593 # cpu-specific one. 594 echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \ 595 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU} 596 [ "$shlib" != "no" ] && \ 597 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl 598} 599 600echo_if_exist() 601{ 602 [ -f $1 ] && echo $1 603 return $? 604} 605 606echo_if_exist_foreach() 607{ 608 local _list=$1; shift 609 for _suffix in $@; do 610 echo_if_exist ${_list}.${_suffix} 611 done 612} 613 614print_set_lists() 615{ 616 for setname; do 617 list=$(list_set_lists $setname) 618 for l in $list; do 619 echo $l 620 if $verbose; then 621 echo >&2 "DEBUG: list_set_files: $l" 622 fi 623 done 624 done | ${XARGS} ${SED} ${SUBST} 625} 626 627# arch_to_cpu mach 628# 629# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach, 630# as determined by <bsd.own.mk>. 631# 632arch_to_cpu() 633{ 634 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 635.include <bsd.own.mk> 636all: 637 @echo \${MACHINE_CPU} 638EOMAKE 639} 640 641# arch_to_endian mach 642# 643# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach, 644# as determined by <bsd.endian.mk>. 645# 646arch_to_endian() 647{ 648 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 649.include <bsd.endian.mk> 650all: 651 @echo \${TARGET_ENDIANNESS} 652EOMAKE 653} 654 655##### 656 657# print_mkvars 658print_mkvars() 659{ 660 for v in $MKVARS; do 661 eval echo $v=\$$v 662 done 663} 664 665# print_set_lists_{base,x,ext} 666# list_set_lists_{base,x,ext} 667# list_set_files_{base,x,ext} 668for func in print_set_lists list_set_lists list_set_files; do 669 for x in base x ext; do 670 if [ $x = base ]; then 671 list=nlists 672 else 673 list=${x}lists 674 fi 675 eval ${func}_${x} \(\) \{ $func \$$list \; \} 676 done 677done 678