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