sets.subr revision 1.89
1# $NetBSD: sets.subr,v 1.89 2009/10/07 22:22:18 haad 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# obsolete controls if obsolete files are selected instead 10# module if != "no", enable MODULE sets 11# shlib shared library format (a.out, elf, or "") 12# stlib static library format (a.out, elf) 13# 14# The following <bsd.own.mk> variables are exported to the environment: 15# MACHINE 16# MACHINE_ARCH 17# MACHINE_CPU 18# HAVE_BINUTILS 19# HAVE_GCC 20# HAVE_GDB 21# TOOLCHAIN_MISSING 22# OBJECT_FMT 23# as well as: 24# 25MKVARS="\ 26 MKBFD \ 27 MKBINUTILS \ 28 MKCATPAGES \ 29 MKCOMPAT \ 30 MKCRYPTO \ 31 MKCRYPTO_IDEA \ 32 MKCRYPTO_MDC2 \ 33 MKCRYPTO_RC5 \ 34 MKCVS \ 35 MKDEBUG \ 36 MKDEBUGLIB \ 37 MKDOC \ 38 MKDYNAMICROOT \ 39 MKGCC \ 40 MKGCCCMDS \ 41 MKGDB \ 42 MKHESIOD \ 43 MKHTML \ 44 MKINET6 \ 45 MKINFO \ 46 MKIPFILTER \ 47 MKISCSI \ 48 MKKERBEROS \ 49 MKKMOD \ 50 MKLDAP \ 51 MKLINT \ 52 MKLVM \ 53 MKMAN \ 54 MKMANPAGES \ 55 MKMANZ \ 56 MKMDNS \ 57 MKNLS \ 58 MKNVI \ 59 MKPAM \ 60 MKPF \ 61 MKPIC \ 62 MKPOSTFIX \ 63 MKPROFILE \ 64 MKSHARE \ 65 MKSKEY \ 66 MKX11 \ 67 MKX11FONTS \ 68 MKXORG \ 69 MKYP \ 70 MKZFS \ 71 USE_INET6 \ 72 USE_KERBEROS \ 73 USE_LDAP \ 74 USE_YP \ 75 NETBSDSRCDIR \ 76 MAKEVERBOSE \ 77" 78# 79# The following variables refer to tools that are used when building sets: 80# 81: ${AWK:=awk} 82: ${CKSUM:=cksum} 83: ${COMM:=comm} 84: ${DATE:=date} 85: ${DB:=db} 86: ${EGREP:=egrep} 87: ${ENV_CMD:=env} # ${ENV} is special to sh(1), ksh(1), etc. 88: ${FGREP:=fgrep} 89: ${FIND:=find} 90: ${GREP:=grep} 91: ${GZIP_CMD:=gzip} # ${GZIP} is special to gzip(1) 92: ${HOSTNAME:=hostname} 93: ${HOST_SH:=sh} 94: ${IDENT:=ident} 95: ${JOIN:=join} 96: ${LS:=ls} 97: ${MAKE:=make} 98: ${MKTEMP:=mktemp} 99: ${MTREE:=mtree} 100: ${PASTE:=paste} 101: ${PAX:=pax} 102: ${PKG_CREATE:=pkg_create} 103: ${PRINTF:=printf} 104: ${SED:=sed} 105: ${SORT:=sort} 106: ${STAT:=stat} 107: ${TSORT:=tsort} 108: ${UNAME:=uname} 109: ${WC:=wc} 110 111# 112# If printf is a shell builtin command, then we can 113# implement cheaper versions of basename and dirname 114# that do not involve any fork/exec overhead. 115# If printf is not builtin, approximate it using echo, 116# and hope there are no weird file names that cause 117# some versions of echo to do the wrong thing. 118# (Converting to this version of dirname speeded up the 119# syspkgdeps script by an order of magnitude, from 68 120# seconds to 6.3 seconds on one particular host.) 121# 122# Note that naive approximations for dirname 123# using ${foo%/*} do not do the right thing in cases 124# where the result should be "/" or ".". 125# 126case "$(type printf)" in 127*builtin*) 128 basename () 129 { 130 local bn 131 bn="${1##*/}" 132 bn="${bn%$2}" 133 printf "%s\n" "$bn" 134 } 135 dirname () 136 { 137 local dn 138 case "$1" in 139 ?*/*) dn="${1%/*}" ;; 140 /*) dn=/ ;; 141 *) dn=. ;; 142 esac 143 printf "%s\n" "$dn" 144 } 145 ;; 146*) 147 basename () 148 { 149 local bn 150 bn="${1##*/}" 151 bn="${bn%$2}" 152 echo "$bn" 153 } 154 dirname () 155 { 156 local dn 157 case "$1" in 158 ?*/*) dn="${1%/*}" ;; 159 /*) dn=/ ;; 160 *) dn=. ;; 161 esac 162 echo "$dn" 163 } 164 ;; 165esac 166 167oIFS=$IFS 168IFS=" 169" 170for x in $( 171${MAKE} -B -f- all <<EOMAKE 172.include <bsd.own.mk> 173.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall)) 174MKMANPAGES=no 175.else 176MKMANPAGES=yes 177.endif 178.if \${MKX11} != "no" 179. if \${X11FLAVOUR} == "Xorg" 180MKXORG:=yes 181MKX11:=no 182. else 183MKXORG:=no 184. endif 185.endif 186all: 187.for i in MACHINE MACHINE_ARCH MACHINE_CPU \ 188 HAVE_BINUTILS HAVE_GCC HAVE_GDB OBJECT_FMT TOOLCHAIN_MISSING \ 189 ${MKVARS} 190 @echo "export \$i=\${\$i}" 191.endfor 192 193EOMAKE 194); do 195# echo 1>&2 "DEBUG: read $x" 196 eval $x 197done 198IFS=$oIFS 199 200setsdir=${0%/*} 201obsolete=0 202module=yes 203if [ "${MACHINE}" = "evbppc" ]; then 204 module=no # Turn off MODULEs for some ports. 205fi 206# Determine lib type. Do this first so stlib also gets set. 207if [ "${OBJECT_FMT}" = "ELF" ]; then 208 shlib=elf 209else 210 shlib=aout 211fi 212stlib=$shlib 213# Now check for MKPIC or specials and turn off shlib if need be. 214if [ "${MKPIC}" = "no" ]; then 215 shlib=no 216fi 217if [ "${MACHINE_ARCH}" = "m68000" ]; then 218 shlib=no # Turn off shlibs for some ports. 219fi 220if [ "$module" != "no" ]; then 221 nlists="base comp etc games man misc modules tests text" 222else 223 nlists="base comp etc games man misc tests text" 224fi 225xlists="xbase xcomp xetc xfont xserver" 226 227OSRELEASE=`${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh` 228MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" 229SUBST="s#@MODULEDIR@#${MODULEDIR}#g" 230SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g" 231SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g" 232 233# 234# list_set_files setfile [...] 235# 236# Produce a packing list for setfile(s). 237# In each file, a record consists of a path and a System Package name, 238# separated by whitespace. E.g., 239# 240# # $NetBSD: sets.subr,v 1.89 2009/10/07 22:22:18 haad Exp $ 241# . base-sys-root [keyword[,...]] 242# ./altroot base-sys-root 243# ./bin base-sys-root 244# ./bin/[ base-util-root 245# ./bin/cat base-util-root 246# [...] 247# 248# A # in the first column marks a comment. 249# 250# If ${obsolete} != 0, only entries with an "obsolete" keyword will 251# be printed. All other keywords must be present. 252# 253# The third field is an optional comma separated list of keywords to 254# control if a record is printed; every keyword listed must be enabled 255# for the record to be printed. The following keywords are available: 256# dummy dummy entry (ignored) 257# obsolete file is obsolete, and only printed if 258# ${obsolete} != 0 259# 260# bfd obsolete, use binutils. 261# binutils ${MKBINUTILS} != no 262# catpages ${MKCATPAGES} != no 263# compat ${MKCOMPAT} != no 264# crypto ${MKCRYPTO} != no 265# crypto_idea ${MKCRYPTO_IDEA} != no 266# crypto_mdc2 ${MKCRYPTO_MDC2} != no 267# crypto_rc5 ${MKCRYPTO_RC5} != no 268# cvs ${MKCVS} != no 269# debug ${MKDEBUG} != no 270# debuglib ${MKDEBUGLIB} != no 271# doc ${MKDOC} != no 272# dynamicroot ${MKDYNAMICROOT} != no 273# gcc ${MKGCC} != no 274# gcccmds ${MKGCCCMDS} != no 275# gdb ${MKGDB} != no 276# hesiod ${MKHESIOD} != no 277# html ${MKHTML} != no 278# inet6 ${MKINET6} != no 279# info ${MKINFO} != no 280# ipfilter ${MKIPFILTER} != no 281# iscsi ${MKISCSI} != no 282# kerberos ${MKKERBEROS} != no 283# kmod ${MKKMOD} != no 284# ldap ${MKLDAP} != no 285# lint ${MKLINT} != no 286# lvm ${MKLVM} != no 287# man ${MKMAN} != no 288# manpages ${MKMANPAGES} != no 289# manz ${MKMANZ} != no 290# mdns ${MKMDNS} != no 291# nls ${MKNLS} != no 292# nvi ${MKNVI} != no 293# pam ${MKPAM} != no 294# pf ${MKPF} != no 295# pic ${MKPIC} != no 296# postfix ${MKPOSTFIX} != no 297# profile ${MKPROFILE} != no 298# share ${MKSHARE} != no 299# skey ${MKSKEY} != no 300# x11 ${MKX11} != no && ${X11FLAVOUR} != "Xorg" 301# xorg ${MKX11} != no && ${X11FLAVOUR} == "Xorg" 302# yp ${MKYP} != no 303# zfs ${MKZFS} != no 304# 305# binutils=<n> <n> = value of ${HAVE_BINUTILS} 306# gcc=<n> <n> = value of ${HAVE_GCC} 307# gdb=<n> <n> = value of ${HAVE_GDB} 308# 309# use_inet6 ${USE_INET6} != no 310# use_kerberos ${USE_KERBEROS} != no 311# use_yp ${USE_YP} != no 312# 313# .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no" 314# automatically append ".gz" to the filename 315# 316# .man if ${MKMANZ} != "no" && ${MKMAN} != "no" 317# automatically append ".gz" to the filename 318# 319list_set_files() 320{ 321 if [ ${MAKEVERBOSE:-2} -lt 3 ]; then 322 verbose=false 323 else 324 verbose=true 325 fi 326 for setname; do 327 list=`list_set_lists $setname` 328 for l in $list; do 329 echo $l 330 if $verbose; then 331 echo >&2 "DEBUG: list_set_files: $l" 332 fi 333 done 334 done | xargs cat | ${SED} ${SUBST} | \ 335 ${AWK} -v obsolete=${obsolete} ' 336 BEGIN { 337 if (obsolete) 338 wanted["obsolete"] = 1 339 340 split("'"${MKVARS}"'", needvars) 341 for (vi in needvars) { 342 nv = needvars[vi] 343 kw = tolower(nv) 344 sub(/^mk/, "", kw) 345 if (ENVIRON[nv] != "no") 346 wanted[kw] = 1 347 } 348 349 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") { 350 wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1 351 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1 352 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1 353 } 354 if (("man" in wanted) && ("catpages" in wanted)) 355 wanted[".cat"] = 1 356 if (("man" in wanted) && ("manpages" in wanted)) 357 wanted[".man"] = 1 358 } 359 360 /^#/ { 361 next; 362 } 363 364 NF > 2 && $3 != "-" { 365 split($3, keywords, ",") 366 show = 1 367 haveobs = 0 368 for (ki in keywords) { 369 kw = keywords[ki] 370 if (("manz" in wanted) && 371 (kw == ".cat" || kw == ".man")) 372 $1 = $1 ".gz" 373 negated = match(kw, "! *") 374 if (negated > 0) { 375 kw = substr(kw, RSTART + RLENGTH) 376 if (kw in wanted) 377 show = 0 378 } else { 379 if (! (kw in wanted)) 380 show = 0 381 } 382 if (kw == "obsolete") 383 haveobs = 1 384 } 385 if (obsolete && ! haveobs) 386 next 387 if (show) 388 print 389 next 390 } 391 392 { 393 if (! obsolete) 394 print 395 }' 396 397} 398 399# 400# list_set_lists setname 401# 402# Print to stdout a list of files, one filename per line, which 403# concatenate to create the packing list for setname. E.g., 404# 405# .../lists/base/mi 406# .../lists/base/rescue.mi 407# .../lists/base/md.i386 408# [...] 409# 410# For a given setname $set, the following files may be selected from 411# .../list/$set: 412# mi 413# ad.${MACHINE_ARCH} 414# (or) ad.${MACHINE_CPU} 415# ad.${MACHINE_CPU}.shl 416# md.${MACHINE}.${MACHINE_ARCH} 417# (or) md.${MACHINE} 418# stl.mi 419# stl.stlib 420# shl.mi 421# shl.shlib 422# module.mi if ${module} != no 423# module.${MACHINE} if ${module} != no 424# module.ad.${MACHINE_ARCH} if ${module} != no 425# (or) module.ad.${MACHINE_CPU} if ${module} != no 426# rescue.shl 427# rescue.${MACHINE} 428# rescue.ad.${MACHINE_ARCH} 429# (or) rescue.ad.${MACHINE_CPU} 430# rescue.ad.${MACHINE_CPU}.shl 431# 432# Environment: 433# shlib 434# stlib 435# 436list_set_lists() 437{ 438 setname=$1 439 440 setdir=$setsdir/lists/$setname 441 echo $setdir/mi 442 if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then 443 # Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU}, 444 # since the arch-specific one will be more specific than 445 # the cpu-specific one. 446 if [ -f $setdir/ad.${MACHINE_ARCH} ]; then 447 echo $setdir/ad.${MACHINE_ARCH} 448 elif [ -f $setdir/ad.${MACHINE_CPU} ]; then 449 echo $setdir/ad.${MACHINE_CPU} 450 fi 451 if [ "$shlib" != "no" -a \ 452 -f $setdir/ad.${MACHINE_CPU}.shl ]; then 453 echo $setdir/ad.${MACHINE_CPU}.shl 454 fi 455 fi 456 if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then 457 echo $setdir/md.${MACHINE}.${MACHINE_ARCH} 458 elif [ -f $setdir/md.${MACHINE} ]; then 459 echo $setdir/md.${MACHINE} 460 fi 461 if [ -f $setdir/stl.mi ]; then 462 echo $setdir/stl.mi 463 fi 464 if [ -f $setdir/stl.${stlib} ]; then 465 echo $setdir/stl.${stlib} 466 fi 467 if [ "$shlib" != "no" ]; then 468 if [ -f $setdir/shl.mi ]; then 469 echo $setdir/shl.mi 470 fi 471 if [ -f $setdir/shl.${shlib} ]; then 472 echo $setdir/shl.${shlib} 473 fi 474 fi 475 if [ "$module" != "no" ]; then 476 if [ -f $setdir/module.mi ]; then 477 echo $setdir/module.mi 478 fi 479 if [ -f $setdir/module.${MACHINE} ]; then 480 echo $setdir/module.${MACHINE} 481 fi 482 if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then 483 # Prefer a module.ad.${MACHINE_ARCH} over a 484 # module.ad.${MACHINE_CPU}, since the arch- 485 # specific one will be more specific than the 486 # cpu-specific one. 487 if [ -f $setdir/module.ad.${MACHINE_ARCH} ]; then 488 echo $setdir/module.ad.${MACHINE_ARCH} 489 elif [ -f $setdir/module.ad.${MACHINE_CPU} ]; then 490 echo $setdir/module.ad.${MACHINE_CPU} 491 fi 492 fi 493 fi 494 495 if [ -f $setdir/rescue.mi ]; then 496 echo $setdir/rescue.mi 497 fi 498 if [ -f $setdir/rescue.${MACHINE} ]; then 499 echo $setdir/rescue.${MACHINE} 500 fi 501 if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then 502 # Prefer a rescue.ad.${MACHINE_ARCH} over a 503 # rescue.ad.${MACHINE_CPU}, since the arch- 504 # specific one will be more specific than the 505 # cpu-specific one. 506 if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then 507 echo $setdir/rescue.ad.${MACHINE_ARCH} 508 elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then 509 echo $setdir/rescue.ad.${MACHINE_CPU} 510 fi 511 if [ "$shlib" != "no" -a \ 512 -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then 513 echo $setdir/rescue.ad.${MACHINE_CPU}.shl 514 fi 515 fi 516} 517 518# arch_to_cpu mach 519# 520# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach, 521# as determined by <bsd.own.mk>. 522# 523arch_to_cpu() 524{ 525 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 526.include <bsd.own.mk> 527all: 528 @echo \${MACHINE_CPU} 529EOMAKE 530} 531 532# arch_to_endian mach 533# 534# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach, 535# as determined by <bsd.endian.mk>. 536# 537arch_to_endian() 538{ 539 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 540.include <bsd.endian.mk> 541all: 542 @echo \${TARGET_ENDIANNESS} 543EOMAKE 544} 545