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