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