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