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