sets.subr revision 1.53
1# $NetBSD: sets.subr,v 1.53 2006/07/23 11:41:24 lukem 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.53 2006/07/23 11:41:24 lukem 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# uucp ${MKUUCP} != no 271# yp ${MKYP} != no 272# 273# gcc=<n> <n> = value of ${HAVE_GCC} 274# gdb=<n> <n> = value of ${HAVE_GDB} 275# 276# use_inet6 ${USE_INET6} != no 277# use_kerberos ${USE_KERBEROS} != no 278# use_yp ${USE_YP} != no 279# 280# .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no" 281# automatically append ".gz" to the filename 282# 283# .man if ${MKMANZ} != "no" && ${MKMAN} != "no" 284# automatically append ".gz" to the filename 285# 286list_set_files() 287{ 288 for setname; do 289 list_set_lists $setname 290 done | xargs cat | \ 291 ${AWK} -v obsolete=${obsolete} ' 292 BEGIN { 293 if (obsolete) 294 wanted["obsolete"] = 1 295 296 split("'"${MKVARS}"'", needvars) 297 for (vi in needvars) { 298 nv = needvars[vi] 299 kw = tolower(nv) 300 sub(/^mk/, "", kw) 301 if (ENVIRON[nv] != "no") 302 wanted[kw] = 1 303 } 304 305 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") { 306 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1 307 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1 308 } 309 if (("man" in wanted) && ("catpages" in wanted)) 310 wanted[".cat"] = 1 311 if (("man" in wanted) && ("manpages" in wanted)) 312 wanted[".man"] = 1 313 } 314 315 /^#/ { 316 next; 317 } 318 319 NF > 2 && $3 != "-" { 320 split($3, keywords, ",") 321 show = 1 322 haveobs = 0 323 for (ki in keywords) { 324 kw = keywords[ki] 325 if (("manz" in wanted) && 326 (kw == ".cat" || kw == ".man")) 327 $1 = $1 ".gz" 328 if (! (kw in wanted)) 329 show = 0 330 if (kw == "obsolete") 331 haveobs = 1 332 } 333 if (obsolete && ! haveobs) 334 next 335 if (show) 336 print 337 next 338 } 339 340 { 341 if (! obsolete) 342 print 343 }' 344 345} 346 347# 348# list_set_lists setname 349# 350# Print to stdout a list of files, one filename per line, which 351# concatenate to create the packing list for setname. E.g., 352# 353# .../lists/base/mi 354# .../lists/base/rescue.mi 355# .../lists/base/md.i386 356# [...] 357# 358# For a given setname $set, the following files may be selected from 359# .../list/$set: 360# mi 361# ad.${MACHINE_ARCH} 362# (or) ad.${MACHINE_CPU} 363# ad.${MACHINE_CPU}.shl 364# md.${MACHINE}.${MACHINE_ARCH} 365# (or) md.${MACHINE} 366# stl.mi 367# stl.stlib 368# shl.mi 369# shl.shlib 370# lkm.mi if ${lkm} != no 371# rescue.shl 372# rescue.${MACHINE} 373# rescue.ad.${MACHINE_ARCH} 374# (or) rescue.ad.${MACHINE_CPU} 375# rescue.ad.${MACHINE_CPU}.shl 376# 377# Environment: 378# shlib 379# stlib 380# 381list_set_lists() 382{ 383 setname=$1 384 385 setdir=$setsdir/lists/$setname 386 echo $setdir/mi 387 if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then 388 # Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU}, 389 # since the arch-specific one will be more specific than 390 # the cpu-specific one. 391 if [ -f $setdir/ad.${MACHINE_ARCH} ]; then 392 echo $setdir/ad.${MACHINE_ARCH} 393 elif [ -f $setdir/ad.${MACHINE_CPU} ]; then 394 echo $setdir/ad.${MACHINE_CPU} 395 fi 396 if [ "$shlib" != "no" -a \ 397 -f $setdir/ad.${MACHINE_CPU}.shl ]; then 398 echo $setdir/ad.${MACHINE_CPU}.shl 399 fi 400 fi 401 if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then 402 echo $setdir/md.${MACHINE}.${MACHINE_ARCH} 403 elif [ -f $setdir/md.${MACHINE} ]; then 404 echo $setdir/md.${MACHINE} 405 fi 406 if [ -f $setdir/stl.mi ]; then 407 echo $setdir/stl.mi 408 fi 409 if [ -f $setdir/stl.${stlib} ]; then 410 echo $setdir/stl.${stlib} 411 fi 412 if [ "$shlib" != "no" ]; then 413 if [ -f $setdir/shl.mi ]; then 414 echo $setdir/shl.mi 415 fi 416 if [ -f $setdir/shl.${shlib} ]; then 417 echo $setdir/shl.${shlib} 418 fi 419 fi 420 if [ "$lkm" != "no" ]; then 421 if [ -f $setdir/lkm.mi ]; then 422 echo $setdir/lkm.mi 423 fi 424 fi 425 426 if [ -f $setdir/rescue.mi ]; then 427 echo $setdir/rescue.mi 428 fi 429 if [ -f $setdir/rescue.${MACHINE} ]; then 430 echo $setdir/rescue.${MACHINE} 431 fi 432 if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then 433 # Prefer a rescue.ad.${MACHINE_ARCH} over a 434 # rescue.ad.${MACHINE_CPU}, since the arch- 435 # specific one will be more specific than the 436 # cpu-specific one. 437 if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then 438 echo $setdir/rescue.ad.${MACHINE_ARCH} 439 elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then 440 echo $setdir/rescue.ad.${MACHINE_CPU} 441 fi 442 if [ "$shlib" != "no" -a \ 443 -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then 444 echo $setdir/rescue.ad.${MACHINE_CPU}.shl 445 fi 446 fi 447} 448 449# arch_to_cpu mach 450# 451# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach, 452# as determined by <bsd.own.mk>. 453# 454arch_to_cpu() 455{ 456 MACHINE_ARCH=${1} ${MAKE} -f- all <<EOMAKE 457.include <bsd.own.mk> 458all: 459 @echo \${MACHINE_CPU} 460EOMAKE 461} 462 463# arch_to_endian mach 464# 465# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach, 466# as determined by <bsd.endian.mk>. 467# 468arch_to_endian() 469{ 470 MACHINE_ARCH=${1} ${MAKE} -f- all <<EOMAKE 471.include <bsd.endian.mk> 472all: 473 @echo \${TARGET_ENDIANNESS} 474EOMAKE 475} 476