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