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