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