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