#!/bin/sh
space=' '
tab=' '
nl='
'
IFS=" $nl"
usage="usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]"
debug=0
flavor=vanilla
crossbuild=false
while test $ case "$1" in
--debug)
set -x
debug=1
PPFLAGS="--debug${PPFLAGS+$space}${PPFLAGS}"
;;
--flavor=?*)
flavor=`echo "$1" | sed -n 's/^--flavor=\(.*\)/\1/p'`
PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
;;
--flavor)
if [ $ echo "$usage" 1>&2
exit 1
fi
flavor="$2"
PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
shift
;;
--platform=?*)
arg=`echo "$1" | sed -n 's/^--platform=\(.*\)/\1/p'`
PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $arg"
;;
--platform)
if [ $ echo "$usage" 1>&2
exit 1
fi
PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $2"
shift
;;
--osversion=?*)
arg=`echo "$1" | sed -n 's/^--osversion=\(.*\)/\1/p'`
osversion="$arg"
;;
--osversion)
if [ $ echo "$usage" 1>&2
exit 1
fi
osversion="$2"
shift
;;
--build|--host)
crossbuild=true
configure_opts="${configure_opts}${configure_opts+$tab}$1"
;;
*)
configure_opts="${configure_opts}${configure_opts+$tab}$1"
;;
esac
shift
done
top_srcdir=`dirname $0`
: ${osversion="`$top_srcdir/pp --probe`"}
test -n "$osversion" || exit 1
osrelease=`echo "$osversion" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
: ${MAKE=make}
if ${MAKE} --version 2>&1 | grep GNU >/dev/null; then
NJOBS=0
case "`uname`" in
Darwin)
NJOBS=`sysctl -n hw.ncpu`
;;
Linux)
if [ -r /proc/cpuinfo ]; then
for c in `sed -n 's/^cpu cores[ ]*: *//p' /proc/cpuinfo`; do
NJOBS=`expr $NJOBS + $c`
done
fi
;;
SunOS)
if [ -x /usr/sbin/psrinfo ]; then
NJOBS=`/usr/sbin/psrinfo | wc -l`
fi
;;
HP-UX)
NJOBS=`sar -Mu 1 1 | awk 'END {print NR-5}'`
;;
AIX)
NJOBS=`bindprocessor -q | awk '{print NF-4}'`
;;
esac
if [ $NJOBS -gt 1 ]; then
make_opts="-j$NJOBS"
fi
fi
if [ "$crossbuild" = "false" ]; then
case "$osversion" in
macos*)
if [ -z "$CC" -a -x /usr/bin/clang ]; then
CC=/usr/bin/clang; export CC
fi
;;
sol[0-9]*)
if [ -z "$CC" -a -x /usr/bin/cc ]; then
CC=/usr/bin/cc; export CC
if [ -z "$CFLAGS" ]; then
CFLAGS=-O; export CFLAGS
fi
fi
;;
esac
fi
configure_opts="${configure_opts}${configure_opts+$tab}--enable-package-build"
case "$osversion" in
centos*|rhel*|f[0-9]*)
case "$osversion" in
centos*|rhel*)
osmajor=`sed -n -e 's/^.*release \([0-9]*\)[^0-9].*$/\1/p' /etc/redhat-release`
if [ $osmajor -ge 4 ]; then
with_selinux=true
if [ $osmajor -ge 5 ]; then
with_linux_audit=true
with_pam_login=true
if [ $osmajor -ge 6 ]; then
with_sssd=true
with_sudo_ldap_conf=true
fi
fi
fi
;;
f[0-9]*)
with_selinux=true
with_linux_audit=true
with_pam_login=true
with_sssd=true
;;
esac
if [ X"$with_selinux" = X"true" ]; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
fi
if [ X"$with_linux_audit" = X"true" ]; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
PPVARS="${PPVARS}${PPVARS+$space}linux_audit=1.4.0"
fi
if [ X"$with_pam_login" = X"true" ]; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-pam-login"
fi
if [ X"$with_sssd" = X"true" ]; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-sssd"
if test "`getconf LONG_BIT`" = "64"; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-sssd-lib=/usr/lib64"
fi
fi
if [ X"$with_sudo_ldap_conf" = X"true" ]; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap-conf-file=/etc/sudo-ldap.conf"
fi
configure_opts="--prefix=/usr
--with-logging=syslog
--with-logfac=authpriv
--with-pam
--enable-zlib=system
--with-editor=/bin/vi
--with-env-editor
--with-ignore-dot
--with-tty-tickets
--with-ldap
--with-passprompt=[sudo] password for %p:
--with-sendmail=/usr/sbin/sendmail
$configure_opts"
;;
sles*)
if [ $osrelease -ge 10 ]; then
if [ $osrelease -ge 11 ]; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
fi
fi
libexec=lib
case "$osversion" in
*64*) gcc -v 2>&1 | grep "with-cpu=[^ ]*32" >/dev/null || libexec=lib64
;;
esac
configure_opts="--prefix=/usr
--libexecdir=/usr/$libexec
--with-logging=syslog
--with-logfac=auth
--with-all-insults
--with-ignore-dot
--with-tty-tickets
--enable-shell-sets-home
--with-sudoers-mode=0440
--with-pam
--enable-zlib=system
--with-ldap
--with-env-editor
--with-passprompt=%p\'s password:
--with-sendmail=/usr/sbin/sendmail
$configure_opts"
make_opts="${make_opts}${make_opts+ }"'docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
;;
deb*|ubu*)
export MANCOMPRESS='gzip -9'
export MANCOMPRESSEXT='.gz'
case "$osversion" in
ubu*)
configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
;;
esac
MULTIARCH=`dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null`
if test "$flavor" = "ldap"; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
--with-ldap-conf-file=/etc/sudo-ldap.conf"
else
configure_opts="${configure_opts}${configure_opts+$tab}--with-sssd"
if test -n "$MULTIARCH"; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-sssd-lib=/usr/lib/$MULTIARCH"
fi
fi
configure_opts="--prefix=/usr
--with-all-insults
--with-pam
--enable-zlib=system
--with-fqdn
--with-logging=syslog
--with-logfac=authpriv
--with-env-editor
--with-editor=/usr/bin/editor
--with-timeout=15
--with-password-timeout=0
--with-passprompt=[sudo] password for %p:
--disable-root-mailer
--with-sendmail=/usr/sbin/sendmail
--mandir=/usr/share/man
--libexecdir=/usr/lib
--with-selinux
--with-linux-audit
$configure_opts"
for f in /lib/${MULTIARCH}${MULTIARCH:+/}libaudit.so.[0-9]* /lib/libaudit.so.[0-9]*; do
if test -f "$f"; then
linux_audit=`dpkg-query -S "$f" 2>/dev/null | sed -n 's/:.*//p'`
test -n "$linux_audit" && break;
fi
done
if [ -z "$linux_audit" ]; then
echo "unable to determine package for libaudit" 1>&2
exit 1
fi
PPVARS="${PPVARS}${PPVARS+$space}linux_audit=$linux_audit"
;;
macos*)
case "$osversion" in
macos10[0-6]-i386|macos10[0-6]-x86_64)
ARCH_FLAGS="-arch i386 -arch x86_64"
;;
esac
if test "${osversion}" != "`$top_srcdir/pp --probe`"; then
sdkvers=`echo "${osversion}" | sed 's/^macos\([0-9][0-9]\)\([0-9]*\)-.*$/\1.\2/'`
if [ -d "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs" ]; then
SDK_DIR="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs"
elif [ -d "/Library/Developer/CommandLineTools/SDKs" ]; then
SDK_DIR="/Library/Developer/CommandLineTools/SDKs"
else
echo "unable to find macOS SDKs directory" 1>&2
exit 1
fi
SDK_DIR="${SDK_DIR}/MacOSX${sdkvers}.sdk"
if test -d "${SDK_DIR}"; then
SDK_FLAGS="-isysroot ${SDK_DIR} -mmacosx-version-min=${sdkvers}"
else
echo "unable to find SDKs directory for macOS $sdkvers" 1>&2
exit 1
fi
fi
export CFLAGS="-O2 -g $ARCH_FLAGS $SDK_FLAGS"
export LDFLAGS="$ARCH_FLAGS $SDK_FLAGS"
configure_opts="--with-pam
--with-bsm-audit
--without-tty-tickets
--enable-zlib=system
--with-ldap
--with-insults=disabled
--with-logging=syslog
--with-logfac=authpriv
--with-editor=/usr/bin/vim
--with-env-editor
$configure_opts"
;;
aix*)
if test -z "$CC" && gcc -v >/dev/null 2>&1; then
CFLAGS="-O2 -gxcoff"; export CFLAGS
fi
configure_opts="
--prefix=/opt/freeware
--mandir=/opt/freeware/man
--with-insults=disabled
--with-logging=syslog
--with-logfac=auth
--with-editor=/usr/bin/vi
--with-env-editor
--enable-zlib=builtin
--disable-nls
--with-sendmail=/usr/sbin/sendmail
$configure_opts"
PPVARS="${PPVARS}${PPVARS+$space}aix_freeware=true"
;;
*)
case "$osversion" in
sol*)
configure_opts="${configure_opts}${configure_opts+$tab}--with-project"
if [ $osrelease -ge 11 ]; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-bsm-audit"
fi
;;
*)
configure_opts="${configure_opts}${configure_opts+$tab}--enable-zlib=builtin${tab}--disable-nls"
;;
esac
if test "$flavor" = "ldap"; then
configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
fi
configure_opts="
--with-insults=disabled
--with-logging=syslog
--with-logfac=auth
--with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
--with-env-editor
$configure_opts"
;;
esac
configure_opts="${configure_opts}${configure_opts+$tab}--disable-tmpfiles.d"
OIFS="$IFS"
IFS=" $nl"
set -- $configure_opts $extra_opts
IFS="$OIFS"
if [ -r Makefile ]; then
${MAKE} $make_opts distclean
fi
$top_srcdir/configure "$@" || exit 1
${MAKE} $make_opts && ${MAKE} $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
test $debug -eq 0 && rm -rf destdir