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