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