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