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