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