NetBSD/distrib/sets/sets.subr
apb f328a72950 Print debug messages only when MAKEVERBOSE >= 3, not when
it is >= 2.  MAKEVERBOSE=2 is teh default, and the messages
are too noisy.
2009-04-07 20:46:20 +00:00

529 lines
12 KiB
Plaintext

# $NetBSD: sets.subr,v 1.83 2009/04/07 20:46:20 apb Exp $
#
#
# The following variables contain defaults for sets.subr functions and callers:
# setsdir path to src/distrib/sets
# nlists list of base sets
# xlists list of x11 sets
# obsolete controls if obsolete files are selected instead
# module if != "no", enable MODULE sets
# shlib shared library format (a.out, elf, or "")
# stlib static library format (a.out, elf)
#
# The following <bsd.own.mk> variables are exported to the environment:
# MACHINE
# MACHINE_ARCH
# MACHINE_CPU
# HAVE_GCC
# HAVE_GDB
# TOOLCHAIN_MISSING
# OBJECT_FMT
# as well as:
#
MKVARS="\
MKBFD \
MKCATPAGES \
MKCOMPAT \
MKCRYPTO \
MKCRYPTO_IDEA \
MKCRYPTO_MDC2 \
MKCRYPTO_RC5 \
MKCVS \
MKDEBUG \
MKDEBUGLIB \
MKDOC \
MKDYNAMICROOT \
MKGCC \
MKGCCCMDS \
MKGDB \
MKHESIOD \
MKHTML \
MKINET6 \
MKINFO \
MKIPFILTER \
MKISCSI \
MKKERBEROS \
MKLDAP \
MKLINT \
MKLVM \
MKMAN \
MKMANPAGES \
MKMANZ \
MKNLS \
MKNVI \
MKPAM \
MKPF \
MKPIC \
MKPOSTFIX \
MKPROFILE \
MKSHARE \
MKSKEY \
MKX11 \
MKXORG \
MKYP \
USE_INET6 \
USE_KERBEROS \
USE_LDAP \
USE_YP \
NETBSDSRCDIR \
MAKEVERBOSE \
"
#
# The following variables refer to tools that are used when building sets:
#
: ${AWK:=awk}
: ${CKSUM:=cksum}
: ${COMM:=comm}
: ${DATE:=date}
: ${DB:=db}
: ${EGREP:=egrep}
: ${ENV_CMD:=env} # ${ENV} is special to sh(1), ksh(1), etc.
: ${FGREP:=fgrep}
: ${FIND:=find}
: ${GREP:=grep}
: ${GZIP_CMD:=gzip} # ${GZIP} is special to gzip(1)
: ${HOSTNAME:=hostname}
: ${HOST_SH:=sh}
: ${IDENT:=ident}
: ${JOIN:=join}
: ${LS:=ls}
: ${MAKE:=make}
: ${MKTEMP:=mktemp}
: ${MTREE:=mtree}
: ${PASTE:=paste}
: ${PAX:=pax}
: ${PKG_CREATE:=pkg_create}
: ${PRINTF:=printf}
: ${SED:=sed}
: ${SORT:=sort}
: ${STAT:=stat}
: ${TSORT:=tsort}
: ${UNAME:=uname}
: ${WC:=wc}
#
# If printf is a shell builtin command, then we can
# implement cheaper versions of basename and dirname
# that do not involve any fork/exec overhead.
# If printf is not builtin, approximate it using echo,
# and hope there are no weird file names that cause
# some versions of echo to do the wrong thing.
# (Converting to this version of dirname speeded up the
# syspkgdeps script by an order of magnitude, from 68
# seconds to 6.3 seconds on one particular host.)
#
# Note that naive approximations for dirname
# using ${foo%/*} do not do the right thing in cases
# where the result should be "/" or ".".
#
case "$(type printf)" in
*builtin*)
basename ()
{
local bn
bn="${1##*/}"
bn="${bn%$2}"
printf "%s\n" "$bn"
}
dirname ()
{
local dn
case "$1" in
?*/*) dn="${1%/*}" ;;
/*) dn=/ ;;
*) dn=. ;;
esac
printf "%s\n" "$dn"
}
;;
*)
basename ()
{
local bn
bn="${1##*/}"
bn="${bn%$2}"
echo "$bn"
}
dirname ()
{
local dn
case "$1" in
?*/*) dn="${1%/*}" ;;
/*) dn=/ ;;
*) dn=. ;;
esac
echo "$dn"
}
;;
esac
oIFS=$IFS
IFS="
"
for x in $(
${MAKE} -B -f- all <<EOMAKE
.include <bsd.own.mk>
.if (\${MKMAN} == "no" || empty(MANINSTALL:Mmaninstall))
MKMANPAGES=no
.else
MKMANPAGES=yes
.endif
.if \${MKX11} != "no"
. if \${X11FLAVOUR} == "Xorg"
MKXORG:=yes
MKX11:=no
. else
MKXORG:=no
. endif
.endif
all:
.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
HAVE_GCC HAVE_GDB OBJECT_FMT TOOLCHAIN_MISSING \
${MKVARS}
@echo "export \$i=\${\$i}"
.endfor
EOMAKE
); do
# echo 1>&2 "DEBUG: read $x"
eval $x
done
IFS=$oIFS
setsdir=${0%/*}
nlists="base comp etc games man misc tests text"
xlists="xbase xcomp xetc xfont xserver"
obsolete=0
module=yes
if [ "${MACHINE}" = "evbppc" ]; then
module=no # Turn off MODULEs for some ports.
fi
# Determine lib type. Do this first so stlib also gets set.
if [ "${OBJECT_FMT}" = "ELF" ]; then
shlib=elf
else
shlib=aout
fi
stlib=$shlib
# Now check for MKPIC or specials and turn off shlib if need be.
if [ "${MKPIC}" = "no" ]; then
shlib=no
fi
if [ "${MACHINE_ARCH}" = "m68000" ]; then
shlib=no # Turn off shlibs for some ports.
fi
OSRELEASE=`${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh`
MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
SUBST="s#@MODULEDIR@#${MODULEDIR}#g"
SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
#
# list_set_files setfile [...]
#
# Produce a packing list for setfile(s).
# In each file, a record consists of a path and a System Package name,
# separated by whitespace. E.g.,
#
# # $NetBSD: sets.subr,v 1.83 2009/04/07 20:46:20 apb Exp $
# . base-sys-root [keyword[,...]]
# ./altroot base-sys-root
# ./bin base-sys-root
# ./bin/[ base-util-root
# ./bin/cat base-util-root
# [...]
#
# A # in the first column marks a comment.
#
# If ${obsolete} != 0, only entries with an "obsolete" keyword will
# be printed. All other keywords must be present.
#
# The third field is an optional comma separated list of keywords to
# control if a record is printed; every keyword listed must be enabled
# for the record to be printed. The following keywords are available:
# dummy dummy entry (ignored)
# obsolete file is obsolete, and only printed if
# ${obsolete} != 0
#
# bfd ${MKBFD} != no
# catpages ${MKCATPAGES} != no
# compat ${MKCOMPAT} != no
# crypto ${MKCRYPTO} != no
# crypto_idea ${MKCRYPTO_IDEA} != no
# crypto_mdc2 ${MKCRYPTO_MDC2} != no
# crypto_rc5 ${MKCRYPTO_RC5} != no
# cvs ${MKCVS} != no
# debug ${MKDEBUG} != no
# debuglib ${MKDEBUGLIB} != no
# doc ${MKDOC} != no
# dynamicroot ${MKDYNAMICROOT} != no
# gcc ${MKGCC} != no
# gcccmds ${MKGCCCMDS} != no
# gdb ${MKGDB} != no
# hesiod ${MKHESIOD} != no
# html ${MKHTML} != no
# inet6 ${MKINET6} != no
# info ${MKINFO} != no
# ipfilter ${MKIPFILTER} != no
# iscsi ${MKISCSI} != no
# kerberos ${MKKERBEROS} != no
# ldap ${MKLDAP} != no
# lint ${MKLINT} != no
# lvm ${MKLVM} != no
# man ${MKMAN} != no
# manpages ${MKMANPAGES} != no
# manz ${MKMANZ} != no
# nls ${MKNLS} != no
# nvi ${MKNVI} != no
# pam ${MKPAM} != no
# pf ${MKPF} != no
# pic ${MKPIC} != no
# postfix ${MKPOSTFIX} != no
# profile ${MKPROFILE} != no
# share ${MKSHARE} != no
# skey ${MKSKEY} != no
# x11 ${MKX11} != no && ${X11FLAVOUR} != "Xorg"
# xorg ${MKX11} != no && ${X11FLAVOUR} == "Xorg"
# yp ${MKYP} != no
#
# gcc=<n> <n> = value of ${HAVE_GCC}
# gdb=<n> <n> = value of ${HAVE_GDB}
#
# use_inet6 ${USE_INET6} != no
# use_kerberos ${USE_KERBEROS} != no
# use_yp ${USE_YP} != no
#
# .cat if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
# automatically append ".gz" to the filename
#
# .man if ${MKMANZ} != "no" && ${MKMAN} != "no"
# automatically append ".gz" to the filename
#
list_set_files()
{
if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
verbose=false
else
verbose=true
fi
for setname; do
list=`list_set_lists $setname`
for l in $list; do
echo $l
if $verbose; then
echo >&2 "DEBUG: list_set_files: $l"
fi
done
done | xargs cat | ${SED} ${SUBST} | \
${AWK} -v obsolete=${obsolete} '
BEGIN {
if (obsolete)
wanted["obsolete"] = 1
split("'"${MKVARS}"'", needvars)
for (vi in needvars) {
nv = needvars[vi]
kw = tolower(nv)
sub(/^mk/, "", kw)
if (ENVIRON[nv] != "no")
wanted[kw] = 1
}
if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
}
if (("man" in wanted) && ("catpages" in wanted))
wanted[".cat"] = 1
if (("man" in wanted) && ("manpages" in wanted))
wanted[".man"] = 1
}
/^#/ {
next;
}
NF > 2 && $3 != "-" {
split($3, keywords, ",")
show = 1
haveobs = 0
for (ki in keywords) {
kw = keywords[ki]
if (("manz" in wanted) &&
(kw == ".cat" || kw == ".man"))
$1 = $1 ".gz"
negated = match(kw, "! *")
if (negated > 0) {
kw = substr(kw, RSTART + RLENGTH)
if (kw in wanted)
show = 0
} else {
if (! (kw in wanted))
show = 0
}
if (kw == "obsolete")
haveobs = 1
}
if (obsolete && ! haveobs)
next
if (show)
print
next
}
{
if (! obsolete)
print
}'
}
#
# list_set_lists setname
#
# Print to stdout a list of files, one filename per line, which
# concatenate to create the packing list for setname. E.g.,
#
# .../lists/base/mi
# .../lists/base/rescue.mi
# .../lists/base/md.i386
# [...]
#
# For a given setname $set, the following files may be selected from
# .../list/$set:
# mi
# ad.${MACHINE_ARCH}
# (or) ad.${MACHINE_CPU}
# ad.${MACHINE_CPU}.shl
# md.${MACHINE}.${MACHINE_ARCH}
# (or) md.${MACHINE}
# stl.mi
# stl.stlib
# shl.mi
# shl.shlib
# module.mi if ${module} != no
# module.${MACHINE} if ${module} != no
# module.ad.${MACHINE_ARCH} if ${module} != no
# (or) module.ad.${MACHINE_CPU} if ${module} != no
# rescue.shl
# rescue.${MACHINE}
# rescue.ad.${MACHINE_ARCH}
# (or) rescue.ad.${MACHINE_CPU}
# rescue.ad.${MACHINE_CPU}.shl
#
# Environment:
# shlib
# stlib
#
list_set_lists()
{
setname=$1
setdir=$setsdir/lists/$setname
echo $setdir/mi
if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
# Prefer an ad.${MACHINE_ARCH} over an ad.${MACHINE_CPU},
# since the arch-specific one will be more specific than
# the cpu-specific one.
if [ -f $setdir/ad.${MACHINE_ARCH} ]; then
echo $setdir/ad.${MACHINE_ARCH}
elif [ -f $setdir/ad.${MACHINE_CPU} ]; then
echo $setdir/ad.${MACHINE_CPU}
fi
if [ "$shlib" != "no" -a \
-f $setdir/ad.${MACHINE_CPU}.shl ]; then
echo $setdir/ad.${MACHINE_CPU}.shl
fi
fi
if [ -f $setdir/md.${MACHINE}.${MACHINE_ARCH} ]; then
echo $setdir/md.${MACHINE}.${MACHINE_ARCH}
elif [ -f $setdir/md.${MACHINE} ]; then
echo $setdir/md.${MACHINE}
fi
if [ -f $setdir/stl.mi ]; then
echo $setdir/stl.mi
fi
if [ -f $setdir/stl.${stlib} ]; then
echo $setdir/stl.${stlib}
fi
if [ "$shlib" != "no" ]; then
if [ -f $setdir/shl.mi ]; then
echo $setdir/shl.mi
fi
if [ -f $setdir/shl.${shlib} ]; then
echo $setdir/shl.${shlib}
fi
fi
if [ "$module" != "no" ]; then
if [ -f $setdir/module.mi ]; then
echo $setdir/module.mi
fi
if [ -f $setdir/module.${MACHINE} ]; then
echo $setdir/module.${MACHINE}
fi
if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
# Prefer a module.ad.${MACHINE_ARCH} over a
# module.ad.${MACHINE_CPU}, since the arch-
# specific one will be more specific than the
# cpu-specific one.
if [ -f $setdir/module.ad.${MACHINE_ARCH} ]; then
echo $setdir/module.ad.${MACHINE_ARCH}
elif [ -f $setdir/module.ad.${MACHINE_CPU} ]; then
echo $setdir/module.ad.${MACHINE_CPU}
fi
fi
fi
if [ -f $setdir/rescue.mi ]; then
echo $setdir/rescue.mi
fi
if [ -f $setdir/rescue.${MACHINE} ]; then
echo $setdir/rescue.${MACHINE}
fi
if [ "${MACHINE}" != "${MACHINE_ARCH}" ]; then
# Prefer a rescue.ad.${MACHINE_ARCH} over a
# rescue.ad.${MACHINE_CPU}, since the arch-
# specific one will be more specific than the
# cpu-specific one.
if [ -f $setdir/rescue.ad.${MACHINE_ARCH} ]; then
echo $setdir/rescue.ad.${MACHINE_ARCH}
elif [ -f $setdir/rescue.ad.${MACHINE_CPU} ]; then
echo $setdir/rescue.ad.${MACHINE_CPU}
fi
if [ "$shlib" != "no" -a \
-f $setdir/rescue.ad.${MACHINE_CPU}.shl ]; then
echo $setdir/rescue.ad.${MACHINE_CPU}.shl
fi
fi
}
# arch_to_cpu mach
#
# Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
# as determined by <bsd.own.mk>.
#
arch_to_cpu()
{
MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
.include <bsd.own.mk>
all:
@echo \${MACHINE_CPU}
EOMAKE
}
# arch_to_endian mach
#
# Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
# as determined by <bsd.endian.mk>.
#
arch_to_endian()
{
MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
.include <bsd.endian.mk>
all:
@echo \${TARGET_ENDIANNESS}
EOMAKE
}