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