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