sets.subr revision 1.70
1# $NetBSD: sets.subr,v 1.70 2008/08/31 00:19:33 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# 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 MKCRYPTO \ 28 MKCRYPTO_IDEA \ 29 MKCRYPTO_MDC2 \ 30 MKCRYPTO_RC5 \ 31 MKCVS \ 32 MKDEBUG \ 33 MKDEBUGLIB \ 34 MKDOC \ 35 MKDYNAMICROOT \ 36 MKGCC \ 37 MKGCCCMDS \ 38 MKGDB \ 39 MKHESIOD \ 40 MKHTML \ 41 MKINET6 \ 42 MKINFO \ 43 MKIPFILTER \ 44 MKISCSI \ 45 MKKERBEROS \ 46 MKLDAP \ 47 MKLINT \ 48 MKMAN \ 49 MKMANPAGES \ 50 MKMANZ \ 51 MKMODULAR \ 52 MKNLS \ 53 MKNVI \ 54 MKPAM \ 55 MKPF \ 56 MKPIC \ 57 MKPOSTFIX \ 58 MKPROFILE \ 59 MKPUFFS \ 60 MKSENDMAIL \ 61 MKSHARE \ 62 MKSKEY \ 63 MKX11 \ 64 MKXORG \ 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 180EOMAKE 181); do 182# echo 1>&2 "DEBUG: read $x" 183 eval $x 184done 185IFS=$oIFS 186 187setsdir=${0%/*} 188nlists="base comp etc games man misc tests text" 189xlists="xbase xcomp xetc xfont xserver" 190obsolete=0 191lkm=yes 192if [ "${MACHINE}" = "evbppc" ]; then 193 lkm=no # Turn off LKMs for some ports. 194fi 195# Determine lib type. Do this first so stlib also gets set. 196if [ "${OBJECT_FMT}" = "ELF" ]; then 197 shlib=elf 198else 199 shlib=aout 200fi 201stlib=$shlib 202# Now check for MKPIC or specials and turn off shlib if need be. 203if [ "${MKPIC}" = "no" ]; then 204 shlib=no 205fi 206if [ "${MACHINE_ARCH}" = "m68000" ]; then 207 shlib=no # Turn off shlibs for some ports. 208fi 209 210OSRELEASE=`${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh` 211MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" 212SUBST="s#@MODULEDIR@#${MODULEDIR}#g" 213SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g" 214SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g" 215 216# 217# list_set_files setfile [...] 218# 219# Produce a packing list for setfile(s). 220# In each file, a record consists of a path and a System Package name, 221# separated by whitespace. E.g., 222# 223# # $NetBSD: sets.subr,v 1.70 2008/08/31 00:19:33 lukem Exp $ 224# . base-sys-root [keyword[,...]] 225# ./altroot base-sys-root 226# ./bin base-sys-root 227# ./bin/[ base-util-root 228# ./bin/cat base-util-root 229# [...] 230# 231# A # in the first column marks a comment. 232# 233# If ${obsolete} != 0, only entries with an "obsolete" keyword will 234# be printed. All other keywords must be present. 235# 236# The third field is an optional comma separated list of keywords to 237# control if a record is printed; every keyword listed must be enabled 238# for the record to be printed. The following keywords are available: 239# dummy dummy entry (ignored) 240# obsolete file is obsolete, and only printed if 241# ${obsolete} != 0 242# 243# bfd ${MKBFD} != no 244# catpages ${MKCATPAGES} != no 245# crypto ${MKCRYPTO} != no 246# crypto_idea ${MKCRYPTO_IDEA} != no 247# crypto_mdc2 ${MKCRYPTO_MDC2} != no 248# crypto_rc5 ${MKCRYPTO_RC5} != no 249# cvs ${MKCVS} != no 250# debug ${MKDEBUG} != no 251# debuglib ${MKDEBUGLIB} != no 252# doc ${MKDOC} != no 253# dynamicroot ${MKDYNAMICROOT} != no 254# gcc ${MKGCC} != no 255# gcccmds ${MKGCCCMDS} != no 256# gdb ${MKGDB} != no 257# hesiod ${MKHESIOD} != no 258# html ${MKHTML} != no 259# inet6 ${MKINET6} != no 260# info ${MKINFO} != no 261# ipfilter ${MKIPFILTER} != no 262# iscsi ${MKISCSI} != no 263# kerberos ${MKKERBEROS} != no 264# ldap ${MKLDAP} != no 265# lint ${MKLINT} != no 266# man ${MKMAN} != no 267# manpages ${MKMANPAGES} != no 268# manz ${MKMANZ} != no 269# modular ${MKMODULAR} != no 270# nls ${MKNLS} != no 271# nvi ${MKNVI} != no 272# pam ${MKPAM} != no 273# pf ${MKPF} != no 274# pic ${MKPIC} != no 275# postfix ${MKPOSTFIX} != no 276# profile ${MKPROFILE} != no 277# puffs ${MKPUFFS} != no 278# sendmail ${MKSENDMAIL} != no 279# share ${MKSHARE} != no 280# skey ${MKSKEY} != no 281# x11 ${MKX11} != no 282# xorg ${MKXORG} != no 283# yp ${MKYP} != no 284# 285# gcc=<n> <n> = value of ${HAVE_GCC} 286# gdb=<n> <n> = value of ${HAVE_GDB} 287# 288# use_inet6 ${USE_INET6} != no 289# use_kerberos ${USE_KERBEROS} != no 290# use_yp ${USE_YP} != no 291# 292# .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no" 293# automatically append ".gz" to the filename 294# 295# .man if ${MKMANZ} != "no" && ${MKMAN} != "no" 296# automatically append ".gz" to the filename 297# 298list_set_files() 299{ 300 if [ ${MAKEVERBOSE:-2} -lt 2 ]; then 301 verbose=false 302 else 303 verbose=true 304 fi 305 for setname; do 306 list=`list_set_lists $setname` 307 for l in $list; do 308 echo $l 309 if $verbose; then 310 echo $l >&2 311 fi 312 done 313 done | xargs cat | ${SED} ${SUBST} | \ 314 ${AWK} -v obsolete=${obsolete} ' 315 BEGIN { 316 if (obsolete) 317 wanted["obsolete"] = 1 318 319 split("'"${MKVARS}"'", needvars) 320 for (vi in needvars) { 321 nv = needvars[vi] 322 kw = tolower(nv) 323 sub(/^mk/, "", kw) 324 if (ENVIRON[nv] != "no") 325 wanted[kw] = 1 326 } 327 328 if ("'"${TOOLCHAIN_MISSING}"'" != "yes") { 329 wanted["gcc=" "'"${HAVE_GCC}"'"] = 1 330 wanted["gdb=" "'"${HAVE_GDB}"'"] = 1 331 } 332 if (("man" in wanted) && ("catpages" in wanted)) 333 wanted[".cat"] = 1 334 if (("man" in wanted) && ("manpages" in wanted)) 335 wanted[".man"] = 1 336 } 337 338 /^#/ { 339 next; 340 } 341 342 NF > 2 && $3 != "-" { 343 split($3, keywords, ",") 344 show = 1 345 haveobs = 0 346 for (ki in keywords) { 347 kw = keywords[ki] 348 if (("manz" in wanted) && 349 (kw == ".cat" || kw == ".man")) 350 $1 = $1 ".gz" 351 negated = match(kw, "! *") 352 if (negated > 0) { 353 kw = substr(kw, RSTART + RLENGTH) 354 if (kw in wanted) 355 show = 0 356 } else { 357 if (! (kw in wanted)) 358 show = 0 359 } 360 if (kw == "obsolete") 361 haveobs = 1 362 } 363 if (obsolete && ! haveobs) 364 next 365 if (show) 366 print 367 next 368 } 369 370 { 371 if (! obsolete) 372 print 373 }' 374 375} 376 377# 378# list_set_lists setname 379# 380# Print to stdout a list of files, one filename per line, which 381# concatenate to create the packing list for setname. E.g., 382# 383# .../lists/base/mi 384# .../lists/base/rescue.mi 385# .../lists/base/md.i386 386# [...] 387# 388# For a given setname $set, the following files may be selected from 389# .../list/$set: 390# mi 391# ad.${MACHINE_ARCH} 392# (or) ad.${MACHINE_CPU} 393# ad.${MACHINE_CPU}.shl 394# md.${MACHINE}.${MACHINE_ARCH} 395# (or) md.${MACHINE} 396# stl.mi 397# stl.stlib 398# shl.mi 399# shl.shlib 400# lkm.mi if ${lkm} != no 401# rescue.shl 402# rescue.${MACHINE} 403# rescue.ad.${MACHINE_ARCH} 404# (or) rescue.ad.${MACHINE_CPU} 405# rescue.ad.${MACHINE_CPU}.shl 406# 407# Environment: 408# shlib 409# stlib 410# 411list_set_lists() 412{ 413 setname=$1 414 415 setdir=$setsdir/lists/$setname 416 echo $setdir/mi 417 if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then 418 # Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU}, 419 # since the arch-specific one will be more specific than 420 # the cpu-specific one. 421 if [ -f $setdir/ad.${MACHINE_ARCH} ]; then 422 echo $setdir/ad.${MACHINE_ARCH} 423 elif [ -f $setdir/ad.${MACHINE_CPU} ]; then 424 echo $setdir/ad.${MACHINE_CPU} 425 fi 426 if [ "$shlib" != "no" -a \ 427 -f $setdir/ad.${MACHINE_CPU}.shl ]; then 428 echo $setdir/ad.${MACHINE_CPU}.shl 429 fi 430 fi 431 if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then 432 echo $setdir/md.${MACHINE}.${MACHINE_ARCH} 433 elif [ -f $setdir/md.${MACHINE} ]; then 434 echo $setdir/md.${MACHINE} 435 fi 436 if [ -f $setdir/stl.mi ]; then 437 echo $setdir/stl.mi 438 fi 439 if [ -f $setdir/stl.${stlib} ]; then 440 echo $setdir/stl.${stlib} 441 fi 442 if [ "$shlib" != "no" ]; then 443 if [ -f $setdir/shl.mi ]; then 444 echo $setdir/shl.mi 445 fi 446 if [ -f $setdir/shl.${shlib} ]; then 447 echo $setdir/shl.${shlib} 448 fi 449 fi 450 if [ "$lkm" != "no" ]; then 451 if [ -f $setdir/lkm.mi ]; then 452 echo $setdir/lkm.mi 453 fi 454 fi 455 456 if [ -f $setdir/rescue.mi ]; then 457 echo $setdir/rescue.mi 458 fi 459 if [ -f $setdir/rescue.${MACHINE} ]; then 460 echo $setdir/rescue.${MACHINE} 461 fi 462 if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then 463 # Prefer a rescue.ad.${MACHINE_ARCH} over a 464 # rescue.ad.${MACHINE_CPU}, since the arch- 465 # specific one will be more specific than the 466 # cpu-specific one. 467 if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then 468 echo $setdir/rescue.ad.${MACHINE_ARCH} 469 elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then 470 echo $setdir/rescue.ad.${MACHINE_CPU} 471 fi 472 if [ "$shlib" != "no" -a \ 473 -f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then 474 echo $setdir/rescue.ad.${MACHINE_CPU}.shl 475 fi 476 fi 477} 478 479# arch_to_cpu mach 480# 481# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach, 482# as determined by <bsd.own.mk>. 483# 484arch_to_cpu() 485{ 486 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 487.include <bsd.own.mk> 488all: 489 @echo \${MACHINE_CPU} 490EOMAKE 491} 492 493# arch_to_endian mach 494# 495# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach, 496# as determined by <bsd.endian.mk>. 497# 498arch_to_endian() 499{ 500 MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE 501.include <bsd.endian.mk> 502all: 503 @echo \${TARGET_ENDIANNESS} 504EOMAKE 505} 506