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