sets.subr revision 1.141
1# $NetBSD: sets.subr,v 1.141 2013/01/16 16:01:05 christos 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# HAS_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="" 149else 150 debugset="debug" 151fi 152# Determine lib type. Do this first so stlib also gets set. 153if [ "${OBJECT_FMT}" = "ELF" ]; then 154 shlib=elf 155else 156 shlib=aout 157fi 158stlib=$shlib 159# Now check for MKPIC or specials and turn off shlib if need be. 160if [ "${MKPIC}" = "no" ]; then 161 shlib=no 162fi 163nlists="base comp $debugset etc games man misc $modset $testset text" 164xlists="xbase xcomp xetc xfont xserver" 165extlists="extbase extcomp extetc" 166 167OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k) 168MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" 169SUBST="s#@MODULEDIR@#${MODULEDIR}#g" 170SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g" 171SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g" 172 173# 174# list_set_files setfile [...] 175# 176# Produce a packing list for setfile(s). 177# In each file, a record consists of a path and a System Package name, 178# separated by whitespace. E.g., 179# 180# # $NetBSD: sets.subr,v 1.141 2013/01/16 16:01:05 christos Exp $ 181# . base-sys-root [keyword[,...]] 182# ./altroot base-sys-root 183# ./bin base-sys-root 184# ./bin/[ base-util-root 185# ./bin/cat base-util-root 186# [...] 187# 188# A # in the first column marks a comment. 189# 190# If ${obsolete} != 0, only entries with an "obsolete" keyword will 191# be printed. All other keywords must be present. 192# 193# The third field is an optional comma separated list of keywords to 194# control if a record is printed; every keyword listed must be enabled 195# for the record to be printed. The following keywords are available: 196# dummy dummy entry (ignored) 197# obsolete file is obsolete, and only printed if 198# ${obsolete} != 0 199# 200# atf ${MKATF} != no 201# bfd obsolete, use binutils. 202# binutils ${MKBINUTILS} != no 203# bsdgrep ${MKBSDGREP} != no 204# catpages ${MKCATPAGES} != no 205# compat ${MKCOMPAT} != no 206# crypto ${MKCRYPTO} != no 207# crypto_rc5 ${MKCRYPTO_RC5} != no 208# cvs ${MKCVS} != no 209# debug ${MKDEBUG} != no 210# debuglib ${MKDEBUGLIB} != no 211# doc ${MKDOC} != no 212# dtrace ${MKDTRACE} != no 213# dynamicroot ${MKDYNAMICROOT} != no 214# extsrc ${MKEXTSRC} != no 215# gcc ${MKGCC} != no 216# gcccmds ${MKGCCCMDS} != no 217# gdb ${MKGDB} != no 218# hesiod ${MKHESIOD} != no 219# html ${MKHTML} != no 220# inet6 ${MKINET6} != no 221# info ${MKINFO} != no 222# ipfilter ${MKIPFILTER} != no 223# iscsi ${MKISCSI} != no 224# kerberos ${MKKERBEROS} != no 225# kmod ${MKKMOD} != no 226# ldap ${MKLDAP} != no 227# lint ${MKLINT} != no 228# llvm ${MKLLVM} != no 229# lvm ${MKLVM} != no 230# makemandb ${MKMAKEMANDB} != no 231# man ${MKMAN} != no 232# manpages ${MKMANPAGES} != no 233# manz ${MKMANZ} != no 234# mdns ${MKMDNS} != no 235# nls ${MKNLS} != no 236# nvi ${MKNVI} != no 237# pam ${MKPAM} != no 238# pcc ${MKPCC} != no 239# pf ${MKPF} != no 240# pic ${MKPIC} != no 241# postfix ${MKPOSTFIX} != no 242# profile ${MKPROFILE} != no 243# perfuse ${MKPERFUSE} != no 244# rump ${MKRUMP} != no 245# share ${MKSHARE} != no 246# skey ${MKSKEY} != no 247# sljit ${MKSLJIT} != no 248# solaris ${MKDTRACE} != no or ${MKZFS} != no 249# ssp ${HAS_SSP} != no 250# tpm ${MKTPM} != no 251# x11 ${MKX11} != no && ${X11FLAVOUR} != "Xorg" 252# xorg ${MKX11} != no && ${X11FLAVOUR} == "Xorg" 253# yp ${MKYP} != no 254# zfs ${MKZFS} != no 255# 256# binutils=<n> <n> = value of ${HAVE_BINUTILS} 257# gcc=<n> <n> = value of ${HAVE_GCC} 258# gdb=<n> <n> = value of ${HAVE_GDB} 259# 260# use_inet6 ${USE_INET6} != no 261# use_kerberos ${USE_KERBEROS} != no 262# use_yp ${USE_YP} != no 263# 264# .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no" 265# automatically append ".gz" to the filename 266# 267# .man if ${MKMANZ} != "no" && ${MKMAN} != "no" 268# automatically append ".gz" to the filename 269# 270list_set_files() 271{ 272 if [ ${MAKEVERBOSE:-2} -lt 3 ]; then 273 verbose=false 274 else 275 verbose=true 276 fi 277 print_set_lists "$@" | \ 278 ${AWK} -v obsolete=${obsolete} ' 279 BEGIN { 280 if (obsolete) 281 wanted["obsolete"] = 1 282 283 split("'"${MKVARS}"'", needvars) 284 for (vi in needvars) { 285 nv = needvars[vi] 286 kw = tolower(nv) 287 sub(/^mk/, "", kw) 288 sub(/^has_/, "", kw) 289 if (ENVIRON[nv] != "no") 290 wanted[kw] = 1 291 } 292 293 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") { 294 if ("binutils" in wanted) 295 wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1 296 if ("gcc" in wanted) 297 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1 298 if ("gdb" in wanted) 299 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1 300 } 301 if (("man" in wanted) && ("catpages" in wanted)) 302 wanted[".cat"] = 1 303 if (("man" in wanted) && ("manpages" in wanted)) 304 wanted[".man"] = 1 305 } 306 307 /^#/ { 308 next; 309 } 310 311 /^-/ { 312 notwanted[substr($1, 2)] = 1; 313 delete list [substr($1, 2)]; 314 next; 315 } 316 317 318 NF > 2 && $3 != "-" { 319 if (notwanted[$1] != "") 320 next; 321 split($3, keywords, ",") 322 show = 1 323 haveobs = 0 324 for (ki in keywords) { 325 kw = keywords[ki] 326 if (("manz" in wanted) && 327 (kw == ".cat" || kw == ".man")) 328 $1 = $1 ".gz" 329 if (substr(kw, 1, 1) == "!") { 330 kw = substr(kw, 2) 331 if (kw in wanted) 332 show = 0 333 } else { 334 if (! (kw in wanted)) 335 show = 0 336 } 337 if (kw == "obsolete") 338 haveobs = 1 339 } 340 if (obsolete && ! haveobs) 341 next 342 if (show) 343 list[$1] = $0 344 next 345 } 346 347 { 348 if (notwanted[$1] != "") 349 next; 350 if (! obsolete) 351 list[$1] = $0 352 } 353 354 END { 355 for (i in list) { 356 print list[i] 357 } 358 }' 359 360} 361 362# 363# list_set_lists setname 364# 365# Print to stdout a list of files, one filename per line, which 366# concatenate to create the packing list for setname. E.g., 367# 368# .../lists/base/mi 369# .../lists/base/rescue.mi 370# .../lists/base/md.i386 371# [...] 372# 373# For a given setname $set, the following files may be selected from 374# .../list/$set: 375# mi 376# mi.ext.* 377# ad.${MACHINE_ARCH} 378# (or) ad.${MACHINE_CPU} 379# ad.${MACHINE_CPU}.shl 380# md.${MACHINE}.${MACHINE_ARCH} 381# (or) md.${MACHINE} 382# stl.mi 383# stl.${stlib} 384# shl.mi 385# shl.mi.ext.* 386# shl.${shlib} 387# shl.${shlib}.ext.* 388# module.mi if ${module} != no 389# module.${MACHINE} if ${module} != no 390# module.ad.${MACHINE_ARCH} if ${module} != no 391# (or) module.ad.${MACHINE_CPU} if ${module} != no 392# rescue.shl 393# rescue.${MACHINE} 394# rescue.ad.${MACHINE_ARCH} 395# (or) rescue.ad.${MACHINE_CPU} 396# rescue.ad.${MACHINE_CPU}.shl 397# 398# Environment: 399# shlib 400# stlib 401# 402list_set_lists() 403{ 404 setname=$1 405 406 list_set_lists_mi $setname 407 list_set_lists_ad $setname 408 list_set_lists_md $setname 409 list_set_lists_stl $setname 410 list_set_lists_shl $setname 411 list_set_lists_module $setname 412 list_set_lists_rescue $setname 413 return 0 414} 415 416list_set_lists_mi() 417{ 418 setdir=$setsdir/lists/$1 419 # always exist! 420 echo $setdir/mi 421} 422 423list_set_lists_ad() 424{ 425 setdir=$setsdir/lists/$1 426 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 427 list_set_lists_common_ad $1 428} 429 430list_set_lists_md() 431{ 432 setdir=$setsdir/lists/$1 433 echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \ 434 echo_if_exist $setdir/md.${MACHINE} 435} 436 437list_set_lists_stl() 438{ 439 setdir=$setsdir/lists/$1 440 echo_if_exist $setdir/stl.mi 441 echo_if_exist $setdir/stl.${stlib} 442} 443 444list_set_lists_shl() 445{ 446 setdir=$setsdir/lists/$1 447 [ "$shlib" != "no" ] || return 448 echo_if_exist $setdir/shl.mi 449 echo_if_exist $setdir/shl.${shlib} 450} 451 452list_set_lists_module() 453{ 454 setdir=$setsdir/lists/$1 455 [ "$module" != "no" ] || return 456 echo_if_exist $setdir/module.mi 457 echo_if_exist $setdir/module.${MACHINE} 458 # XXX module never has .shl 459 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 460 list_set_lists_common_ad $1 module 461} 462 463list_set_lists_rescue() 464{ 465 setdir=$setsdir/lists/$1 466 echo_if_exist $setdir/rescue.mi 467 echo_if_exist $setdir/rescue.${MACHINE} 468 [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \ 469 list_set_lists_common_ad $1 rescue 470} 471 472list_set_lists_common_ad() 473{ 474 setdir=$setsdir/lists/$1; _prefix=$2 475 476 [ -n "$_prefix" ] && prefix="$_prefix". 477 478 # Prefer a <prefix>.ad.${MACHINE_ARCH} over a 479 # <prefix>.ad.${MACHINE_CPU}, since the arch- 480 # specific one will be more specific than the 481 # cpu-specific one. 482 echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \ 483 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU} 484 [ "$shlib" != "no" ] && \ 485 echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl 486} 487 488echo_if_exist() 489{ 490 [ -f $1 ] && echo $1 491 return $? 492} 493 494echo_if_exist_foreach() 495{ 496 local _list=$1; shift 497 for _suffix in $@; do 498 echo_if_exist ${_list}.${_suffix} 499 done 500} 501 502print_set_lists() 503{ 504 for setname; do 505 list=$(list_set_lists $setname) 506 for l in $list; do 507 echo $l 508 if $verbose; then 509 echo >&2 "DEBUG: list_set_files: $l" 510 fi 511 done 512 done | ${XARGS} ${SED} ${SUBST} 513} 514 515# arch_to_cpu mach 516# 517# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach, 518# as determined by <bsd.own.mk>. 519# 520arch_to_cpu() 521{ 522 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 523.include <bsd.own.mk> 524all: 525 @echo \${MACHINE_CPU} 526EOMAKE 527} 528 529# arch_to_endian mach 530# 531# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach, 532# as determined by <bsd.endian.mk>. 533# 534arch_to_endian() 535{ 536 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 537.include <bsd.endian.mk> 538all: 539 @echo \${TARGET_ENDIANNESS} 540EOMAKE 541} 542 543##### 544 545# print_mkvars 546print_mkvars() 547{ 548 for v in $MKVARS; do 549 eval echo $v=\$$v 550 done 551} 552 553# print_set_lists_{base,x,ext} 554# list_set_lists_{base,x,ext} 555# list_set_files_{base,x,ext} 556for func in print_set_lists list_set_lists list_set_files; do 557 for x in base x ext; do 558 if [ $x = base ]; then 559 list=nlists 560 else 561 list=${x}lists 562 fi 563 eval ${func}_${x} \(\) \{ $func \$$list \; \} 564 done 565done 566