sets.subr revision 1.163
1# $NetBSD: sets.subr,v 1.163 2015/03/01 07:46:04 mrg 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.163 2015/03/01 07:46:04 mrg 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# crypto ${MKCRYPTO} != no 210# crypto_rc5 ${MKCRYPTO_RC5} != no 211# cvs ${MKCVS} != no 212# debug ${MKDEBUG} != no 213# debuglib ${MKDEBUGLIB} != no 214# doc ${MKDOC} != no 215# dtrace ${MKDTRACE} != no 216# dynamicroot ${MKDYNAMICROOT} != no 217# extsrc ${MKEXTSRC} != no 218# gcc ${MKGCC} != no 219# gcccmds ${MKGCCCMDS} != no 220# gdb ${MKGDB} != no 221# hesiod ${MKHESIOD} != no 222# html ${MKHTML} != no 223# inet6 ${MKINET6} != no 224# info ${MKINFO} != no 225# ipfilter ${MKIPFILTER} != no 226# iscsi ${MKISCSI} != no 227# kerberos ${MKKERBEROS} != no 228# kmod ${MKKMOD} != no 229# kyua ${MKKYUA} != no 230# ldap ${MKLDAP} != no 231# lint ${MKLINT} != no 232# libcxx ${MKLIBCXX} != no 233# libgcc_eh ${HAVE_LIBGCC_EH} != no 234# libstdcxx ${MKLIBSTDCXX} != no 235# lld ${MKLLD} != no 236# lldb ${MKLLDB} != no 237# llvm ${MKLLVM} != no 238# lvm ${MKLVM} != no 239# makemandb ${MKMAKEMANDB} != no 240# man ${MKMAN} != no 241# manpages ${MKMANPAGES} != no 242# manz ${MKMANZ} != no 243# mclinker ${MKMCLINKER} != no 244# mdns ${MKMDNS} != no 245# nls ${MKNLS} != no 246# nvi ${MKNVI} != no 247# pam ${MKPAM} != no 248# pcc ${MKPCC} != no 249# pf ${MKPF} != no 250# pic ${MKPIC} != no 251# picinstall ${MKPICINSTALL} != no 252# postfix ${MKPOSTFIX} != no 253# profile ${MKPROFILE} != no 254# perfuse ${MKPERFUSE} != no 255# rump ${MKRUMP} != no 256# share ${MKSHARE} != no 257# skey ${MKSKEY} != no 258# sljit ${MKSLJIT} != no 259# softfloat ${MKSOFTFLOAT} != no 260# solaris ${MKDTRACE} != no or ${MKZFS} != no 261# ssp ${HAVE_SSP} != no 262# tpm ${MKTPM} != no 263# x11 ${MKX11} != no && ${X11FLAVOUR} != "Xorg" 264# x11radeonkms ${MKX11} != no && ${MKX11RADEONKMS} != no 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 if (obsolete) 296 wanted["obsolete"] = 1 297 298 split("'"${MKVARS}"'", needvars) 299 for (vi in needvars) { 300 nv = needvars[vi] 301 kw = tolower(nv) 302 sub(/^mk/, "", kw) 303 sub(/^have_/, "", kw) 304 sub(/^target_endianness/, "endian", kw) 305 if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no") 306 wanted[kw] = 1 307 } 308 309 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") { 310 if ("binutils" in wanted) 311 wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1 312 if ("gcc" in wanted) 313 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1 314 if ("gdb" in wanted) 315 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1 316 } 317 if (("man" in wanted) && ("catpages" in wanted)) 318 wanted[".cat"] = 1 319 if (("man" in wanted) && ("manpages" in wanted)) 320 wanted[".man"] = 1 321 if ("endian" in wanted) 322 wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1 323 if ("machine" in wanted) 324 wanted["machine=" "'"${MACHINE}"'"] = 1 325 if ("machine_arch" in wanted) 326 wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1 327 if ("machine_cpu" in wanted) 328 wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1 329 } 330 331 /^#/ { 332 next; 333 } 334 335 /^-/ { 336 notwanted[substr($1, 2)] = 1; 337 delete list [substr($1, 2)]; 338 next; 339 } 340 341 342 NF > 2 && $3 != "-" { 343 if (notwanted[$1] != "") 344 next; 345 split($3, keywords, ",") 346 show = 1 347 haveobs = 0 348 for (ki in keywords) { 349 kw = keywords[ki] 350 if (("manz" in wanted) && 351 (kw == ".cat" || kw == ".man")) 352 $1 = $1 ".gz" 353 if (substr(kw, 1, 1) == "!") { 354 kw = substr(kw, 2) 355 if (kw in wanted) 356 show = 0 357 } else { 358 if (! (kw in wanted)) 359 show = 0 360 } 361 if (kw == "obsolete") 362 haveobs = 1 363 } 364 if (obsolete && ! haveobs) 365 next 366 if (show) 367 list[$1] = $0 368 next 369 } 370 371 { 372 if (notwanted[$1] != "") 373 next; 374 if (! obsolete) 375 list[$1] = $0 376 } 377 378 END { 379 for (i in list) { 380 print list[i] 381 } 382 }' 383 384} 385 386# 387# list_set_lists setname 388# 389# Print to stdout a list of files, one filename per line, which 390# concatenate to create the packing list for setname. E.g., 391# 392# .../lists/base/mi 393# .../lists/base/rescue.mi 394# .../lists/base/md.i386 395# [...] 396# 397# For a given setname $set, the following files may be selected from 398# .../list/$set: 399# mi 400# mi.ext.* 401# ad.${MACHINE_ARCH} 402# (or) ad.${MACHINE_CPU} 403# ad.${MACHINE_CPU}.shl 404# md.${MACHINE}.${MACHINE_ARCH} 405# (or) md.${MACHINE} 406# stl.mi 407# stl.${stlib} 408# shl.mi 409# shl.mi.ext.* 410# shl.${shlib} 411# shl.${shlib}.ext.* 412# module.mi if ${module} != no 413# module.${MACHINE} if ${module} != no 414# module.ad.${MACHINE_ARCH} if ${module} != no 415# (or) module.ad.${MACHINE_CPU} if ${module} != no 416# rescue.shl 417# rescue.${MACHINE} 418# rescue.ad.${MACHINE_ARCH} 419# (or) rescue.ad.${MACHINE_CPU} 420# rescue.ad.${MACHINE_CPU}.shl 421# 422# Environment: 423# shlib 424# stlib 425# 426list_set_lists() 427{ 428 setname=$1 429 430 list_set_lists_mi $setname 431 list_set_lists_ad $setname 432 list_set_lists_md $setname 433 list_set_lists_stl $setname 434 list_set_lists_shl $setname 435 list_set_lists_module $setname 436 list_set_lists_rescue $setname 437 return 0 438} 439 440list_set_lists_mi() 441{ 442 setdir=$setsdir/lists/$1 443 # always exist! 444 echo $setdir/mi 445} 446 447list_set_lists_ad() 448{ 449 setdir=$setsdir/lists/$1 450 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 451 list_set_lists_common_ad $1 452} 453 454list_set_lists_md() 455{ 456 setdir=$setsdir/lists/$1 457 echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \ 458 echo_if_exist $setdir/md.${MACHINE} 459} 460 461list_set_lists_stl() 462{ 463 setdir=$setsdir/lists/$1 464 echo_if_exist $setdir/stl.mi 465 echo_if_exist $setdir/stl.${stlib} 466} 467 468list_set_lists_shl() 469{ 470 setdir=$setsdir/lists/$1 471 [ "$shlib" != "no" ] || return 472 echo_if_exist $setdir/shl.mi 473 echo_if_exist $setdir/shl.${shlib} 474} 475 476list_set_lists_module() 477{ 478 setdir=$setsdir/lists/$1 479 [ "$module" != "no" ] || return 480 echo_if_exist $setdir/module.mi 481 echo_if_exist $setdir/module.${MACHINE} 482 # XXX module never has .shl 483 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 484 list_set_lists_common_ad $1 module 485} 486 487list_set_lists_rescue() 488{ 489 setdir=$setsdir/lists/$1 490 echo_if_exist $setdir/rescue.mi 491 echo_if_exist $setdir/rescue.${MACHINE} 492 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 493 list_set_lists_common_ad $1 rescue 494} 495 496list_set_lists_common_ad() 497{ 498 setdir=$setsdir/lists/$1; _prefix=$2 499 500 [ -n "$_prefix" ] && prefix="$_prefix". 501 502 # Prefer a <prefix>.ad.${MACHINE_ARCH} over a 503 # <prefix>.ad.${MACHINE_CPU}, since the arch- 504 # specific one will be more specific than the 505 # cpu-specific one. 506 echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \ 507 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU} 508 [ "$shlib" != "no" ] && \ 509 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl 510} 511 512echo_if_exist() 513{ 514 [ -f $1 ] && echo $1 515 return $? 516} 517 518echo_if_exist_foreach() 519{ 520 local _list=$1; shift 521 for _suffix in $@; do 522 echo_if_exist ${_list}.${_suffix} 523 done 524} 525 526print_set_lists() 527{ 528 for setname; do 529 list=$(list_set_lists $setname) 530 for l in $list; do 531 echo $l 532 if $verbose; then 533 echo >&2 "DEBUG: list_set_files: $l" 534 fi 535 done 536 done | ${XARGS} ${SED} ${SUBST} 537} 538 539# arch_to_cpu mach 540# 541# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach, 542# as determined by <bsd.own.mk>. 543# 544arch_to_cpu() 545{ 546 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 547.include <bsd.own.mk> 548all: 549 @echo \${MACHINE_CPU} 550EOMAKE 551} 552 553# arch_to_endian mach 554# 555# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach, 556# as determined by <bsd.endian.mk>. 557# 558arch_to_endian() 559{ 560 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 561.include <bsd.endian.mk> 562all: 563 @echo \${TARGET_ENDIANNESS} 564EOMAKE 565} 566 567##### 568 569# print_mkvars 570print_mkvars() 571{ 572 for v in $MKVARS; do 573 eval echo $v=\$$v 574 done 575} 576 577# print_set_lists_{base,x,ext} 578# list_set_lists_{base,x,ext} 579# list_set_files_{base,x,ext} 580for func in print_set_lists list_set_lists list_set_files; do 581 for x in base x ext; do 582 if [ $x = base ]; then 583 list=nlists 584 else 585 list=${x}lists 586 fi 587 eval ${func}_${x} \(\) \{ $func \$$list \; \} 588 done 589done 590