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