NetBSD/distrib/sets/sets.subr

477 lines
10 KiB
Plaintext

# $NetBSD: sets.subr,v 1.56 2007/02/05 18:26:01 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
# lkm if != "no", enable LKM sets
# shlib shared library format (a.out, elf, or "")
# stlib static library format (a.out, elf)
# x11_version version of XFree86. one of:
# "" cross built from src/x11
# 3 XFree86 3.x from xsrc/xc
# 4 XFree86 4.x from xsrc/xfree/xc
#
# 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 \
MKCRYPTO \
MKCRYPTO_IDEA \
MKCRYPTO_MDC2 \
MKCRYPTO_RC5 \
MKCVS \
MKGCC \
MKGCCCMDS \
MKDEBUG \
MKDOC \
MKGDB \
MKHESIOD \
MKINFO \
MKIPFILTER \
MKINET6 \
MKISCSI \
MKKERBEROS \
MKLINT \
MKMAN \
MKMANPAGES \
MKMANZ \
MKNLS \
MKPAM \
MKPF \
MKPIC \
MKPOSTFIX \
MKPROFILE \
MKPUFFS \
MKSENDMAIL \
MKSHARE \
MKSKEY \
MKUUCP \
MKX11 \
MKYP \
USE_INET6 \
USE_KERBEROS \
USE_YP \
"
#
# 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
all:
.for i in MACHINE MACHINE_ARCH MACHINE_CPU \
HAVE_GCC HAVE_GDB OBJECT_FMT TOOLCHAIN_MISSING \
${MKVARS}
@echo "export \$i=\${\$i}"
.endfor
.if (\${MKX11:Uno} != "no")
@echo x11_version=""
.else
@echo x11_version=4
.endif
EOMAKE
); do
# echo 1>&2 "DEBUG: read $x"
eval $x
done
IFS=$oIFS
setsdir=${0%/*}
nlists="base comp etc games man misc text"
case $x11_version in
3) xlists="xbase3 xcomp3 xcontrib3 xfont3 xmisc3 xserver3" ;;
4) xlists="xbase4 xcomp4 xcontrib4 xfont4 xmisc4 xserver4" ;;
"") xlists="xbase xcomp xetc xfont xserver" ;;
*) xlists="" ;; # unknown!
esac
obsolete=0
lkm=yes
if [ "${MACHINE}" = "evbppc" ]; then
lkm=no # Turn off LKMs 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
#
# 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.56 2007/02/05 18:26:01 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
# crypto ${MKCRYPTO} != no
# crypto_idea ${MKCRYPTO_IDEA} != no
# crypto_mdc2 ${MKCRYPTO_MDC2} != no
# crypto_rc5 ${MKCRYPTO_RC5} != no
# cvs ${MKCVS} != no
# debug ${MKDEBUG} != no
# doc ${MKDOC} != no
# gcc ${MKGCC} != no
# gcccmds ${MKGCCCMDS} != no
# gdb ${MKGDB} != no
# hesiod ${MKHESIOD} != no
# info ${MKINFO} != no
# ipfilter ${MKIPFILTER} != no
# inet6 ${MKINET6} != no
# iscsi ${MKISCSI} != no
# kerberos ${MKKERBEROS} != no
# lint ${MKLINT} != no
# man ${MKMAN} != no
# manz ${MKMANZ} != no
# nls ${MKNLS} != no
# pam ${MKPAM} != no
# pf ${MKPF} != no
# postfix ${MKPOSTFIX} != no
# profile ${MKPROFILE} != no
# puffs ${MKPUFFS} != no
# sendmail ${MKSENDMAIL} != no
# share ${MKSHARE} != no
# skey ${MKSKEY} != no
# 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()
{
for setname; do
list_set_lists $setname
done | xargs cat | \
${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"
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
# lkm.mi if ${lkm} != 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 [ "$lkm" != "no" ]; then
if [ -f $setdir/lkm.mi ]; then
echo $setdir/lkm.mi
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
}