sets.subr revision 1.71
1# $NetBSD: sets.subr,v 1.71 2008/10/26 07:31:00 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# 14# The following <bsd.own.mk> variables are exported to the environment: 15# MACHINE 16# MACHINE_ARCH 17# MACHINE_CPU 18# HAVE_GCC 19# HAVE_GDB 20# TOOLCHAIN_MISSING 21# OBJECT_FMT 22# as well as: 23# 24MKVARS="\ 25 MKBFD \ 26 MKCATPAGES \ 27 MKCOMPAT \ 28 MKCRYPTO \ 29 MKCRYPTO_IDEA \ 30 MKCRYPTO_MDC2 \ 31 MKCRYPTO_RC5 \ 32 MKCVS \ 33 MKDEBUG \ 34 MKDEBUGLIB \ 35 MKDOC \ 36 MKDYNAMICROOT \ 37 MKGCC \ 38 MKGCCCMDS \ 39 MKGDB \ 40 MKHESIOD \ 41 MKHTML \ 42 MKINET6 \ 43 MKINFO \ 44 MKIPFILTER \ 45 MKISCSI \ 46 MKKERBEROS \ 47 MKLDAP \ 48 MKLINT \ 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 MKXORG \ 66 MKYP \ 67 USE_INET6 \ 68 USE_KERBEROS \ 69 USE_LDAP \ 70 USE_YP \ 71 NETBSDSRCDIR \ 72 MAKEVERBOSE \ 73" 74# 75# The following variables refer to tools that are used when building sets: 76# 77: ${AWK:=awk} 78: ${CKSUM:=cksum} 79: ${COMM:=comm} 80: ${DATE:=date} 81: ${DB:=db} 82: ${EGREP:=egrep} 83: ${ENV_CMD:=env} # ${ENV} is special to sh(1), ksh(1), etc. 84: ${FGREP:=fgrep} 85: ${FIND:=find} 86: ${GREP:=grep} 87: ${GZIP_CMD:=gzip} # ${GZIP} is special to gzip(1) 88: ${HOSTNAME:=hostname} 89: ${HOST_SH:=sh} 90: ${IDENT:=ident} 91: ${JOIN:=join} 92: ${LS:=ls} 93: ${MAKE:=make} 94: ${MKTEMP:=mktemp} 95: ${MTREE:=mtree} 96: ${PASTE:=paste} 97: ${PAX:=pax} 98: ${PKG_CREATE:=pkg_create} 99: ${PRINTF:=printf} 100: ${SED:=sed} 101: ${SORT:=sort} 102: ${STAT:=stat} 103: ${TSORT:=tsort} 104: ${UNAME:=uname} 105: ${WC:=wc} 106 107# 108# If printf is a shell builtin command, then we can 109# implement cheaper versions of basename and dirname 110# that do not involve any fork/exec overhead. 111# If printf is not builtin, approximate it using echo, 112# and hope there are no weird file names that cause 113# some versions of echo to do the wrong thing. 114# (Converting to this version of dirname speeded up the 115# syspkgdeps script by an order of magnitude, from 68 116# seconds to 6.3 seconds on one particular host.) 117# 118# Note that naive approximations for dirname 119# using ${foo%/*} do not do the right thing in cases 120# where the result should be "/" or ".". 121# 122case "$(type printf)" in 123*builtin*) 124 basename () 125 { 126 local bn 127 bn="${1##*/}" 128 bn="${bn%$2}" 129 printf "%s\n" "$bn" 130 } 131 dirname () 132 { 133 local dn 134 case "$1" in 135 ?*/*) dn="${1%/*}" ;; 136 /*) dn=/ ;; 137 *) dn=. ;; 138 esac 139 printf "%s\n" "$dn" 140 } 141 ;; 142*) 143 basename () 144 { 145 local bn 146 bn="${1##*/}" 147 bn="${bn%$2}" 148 echo "$bn" 149 } 150 dirname () 151 { 152 local dn 153 case "$1" in 154 ?*/*) dn="${1%/*}" ;; 155 /*) dn=/ ;; 156 *) dn=. ;; 157 esac 158 echo "$dn" 159 } 160 ;; 161esac 162 163oIFS=$IFS 164IFS=" 165" 166for x in $( 167${MAKE} -B -f- all <<EOMAKE 168.include <bsd.own.mk> 169.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall)) 170MKMANPAGES=no 171.else 172MKMANPAGES=yes 173.endif 174all: 175.for i in MACHINE MACHINE_ARCH MACHINE_CPU \ 176 HAVE_GCC HAVE_GDB OBJECT_FMT TOOLCHAIN_MISSING \ 177 ${MKVARS} 178 @echo "export \$i=\${\$i}" 179.endfor 180 181EOMAKE 182); do 183# echo 1>&2 "DEBUG: read $x" 184 eval $x 185done 186IFS=$oIFS 187 188setsdir=${0%/*} 189nlists="base comp etc games man misc tests text" 190xlists="xbase xcomp xetc xfont xserver" 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 211OSRELEASE=`${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh` 212MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" 213SUBST="s#@MODULEDIR@#${MODULEDIR}#g" 214SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g" 215SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g" 216 217# 218# list_set_files setfile [...] 219# 220# Produce a packing list for setfile(s). 221# In each file, a record consists of a path and a System Package name, 222# separated by whitespace. E.g., 223# 224# # $NetBSD: sets.subr,v 1.71 2008/10/26 07:31:00 mrg Exp $ 225# . base-sys-root [keyword[,...]] 226# ./altroot base-sys-root 227# ./bin base-sys-root 228# ./bin/[ base-util-root 229# ./bin/cat base-util-root 230# [...] 231# 232# A # in the first column marks a comment. 233# 234# If ${obsolete} != 0, only entries with an "obsolete" keyword will 235# be printed. All other keywords must be present. 236# 237# The third field is an optional comma separated list of keywords to 238# control if a record is printed; every keyword listed must be enabled 239# for the record to be printed. The following keywords are available: 240# dummy dummy entry (ignored) 241# obsolete file is obsolete, and only printed if 242# ${obsolete} != 0 243# 244# bfd ${MKBFD} != no 245# catpages ${MKCATPAGES} != no 246# compat ${MKCOMPAT} != no 247# crypto ${MKCRYPTO} != no 248# crypto_idea ${MKCRYPTO_IDEA} != no 249# crypto_mdc2 ${MKCRYPTO_MDC2} != no 250# crypto_rc5 ${MKCRYPTO_RC5} != no 251# cvs ${MKCVS} != no 252# debug ${MKDEBUG} != no 253# debuglib ${MKDEBUGLIB} != no 254# doc ${MKDOC} != no 255# dynamicroot ${MKDYNAMICROOT} != no 256# gcc ${MKGCC} != no 257# gcccmds ${MKGCCCMDS} != no 258# gdb ${MKGDB} != no 259# hesiod ${MKHESIOD} != no 260# html ${MKHTML} != no 261# inet6 ${MKINET6} != no 262# info ${MKINFO} != no 263# ipfilter ${MKIPFILTER} != no 264# iscsi ${MKISCSI} != no 265# kerberos ${MKKERBEROS} != no 266# ldap ${MKLDAP} != no 267# lint ${MKLINT} != no 268# man ${MKMAN} != no 269# manpages ${MKMANPAGES} != no 270# manz ${MKMANZ} != no 271# modular ${MKMODULAR} != no 272# nls ${MKNLS} != no 273# nvi ${MKNVI} != no 274# pam ${MKPAM} != no 275# pf ${MKPF} != no 276# pic ${MKPIC} != no 277# postfix ${MKPOSTFIX} != no 278# profile ${MKPROFILE} != no 279# puffs ${MKPUFFS} != no 280# sendmail ${MKSENDMAIL} != no 281# share ${MKSHARE} != no 282# skey ${MKSKEY} != no 283# x11 ${MKX11} != no 284# xorg ${MKXORG} != 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