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