be more direct
[debian/sudo] / mkpkg
diff --git a/mkpkg b/mkpkg
index ae4135681715b832d0c8a481995a134ac14229a1..ad4eca3033c12b7ac618c9a034f4030469e54cc6 100755 (executable)
--- a/mkpkg
+++ b/mkpkg
@@ -1,7 +1,7 @@
 #!/bin/sh
 #
 # Build a binary package using polypkg
-# Usage: mkpkg [--debug] [--flavor flavor] [--platform platform]
+# Usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]
 #
 
 # Make sure IFS is set to space, tab, newline in that order.
@@ -12,9 +12,10 @@ nl='
 IFS="  $nl"
 
 # Parse arguments
-usage="usage: mkpkg [--debug] [--flavor flavor] [--platform platform]"
+usage="usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]"
 debug=0
 flavor=vanilla
+crossbuild=false
 while test $# -gt 0; do
     case "$1" in
        --debug)
@@ -47,6 +48,22 @@ while test $# -gt 0; do
            PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $2"
            shift
            ;;
+       --osversion=?*)
+           arg=`echo "$1" | sed -n 's/^--osversion=\(.*\)/\1/p'`
+           osversion="$arg"
+           ;;
+       --osversion)
+           if [ $# -lt 2 ]; then
+               echo "$usage" 1>&2
+               exit 1
+           fi
+           osversion="$2"
+           shift
+           ;;
+       --build|--host)
+           crossbuild=true
+           configure_opts="${configure_opts}${configure_opts+$tab}$1"
+           ;;
        *)
            # Pass unknown options to configure
            configure_opts="${configure_opts}${configure_opts+$tab}$1"
@@ -57,15 +74,16 @@ done
 
 top_srcdir=`dirname $0`
 
-platform=`$top_srcdir/pp --probe` || exit 1
-osrelease=`echo "$platform" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
+: ${osversion="`$top_srcdir/pp --probe`"}
+test -n "$osversion" || exit 1
+osrelease=`echo "$osversion" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
 
 # Default paths
 prefix=/usr/local
 
 # Linux distros may build binaries as pie files.
 # This is really something libtool should figure out, but it does not.
-case "$platform" in
+case "$osversion" in
     *-s390*|*-sparc*|*-alpha*)
        F_PIE=-fPIE
        ;;
@@ -74,66 +92,80 @@ case "$platform" in
        ;;
 esac
 
-# Choose compiler options by platform.
-case "$platform" in
-    hpux*)
-       # Use the HP ANSI C compiler on HP-UX if possible
-       if [ -z "$CC" -a -x /opt/ansic/bin/cc ]; then
-           CC=/opt/ansic/bin/cc; export CC
-           if [ -z "$CFLAGS" ]; then
-               CFLAGS=-O; export CFLAGS
+# Choose compiler options by osversion if not cross-compiling.
+if [ "$crossbuild" = "false" ]; then
+    case "$osversion" in
+       hpux*)
+           # Use the HP ANSI C compiler on HP-UX if possible
+           if [ -z "$CC" -a -x /opt/ansic/bin/cc ]; then
+               CC=/opt/ansic/bin/cc; export CC
+               if [ -z "$CFLAGS" ]; then
+                   CFLAGS=-O; export CFLAGS
+               fi
            fi
-       else
-           configure_opts="${configure_opts}${configure_opts+$tab}--disable-zlib"
-       fi
-       ;;
-esac
+           ;;
+       sol[0-9]*)
+           # Use the Sun Studio C compiler on Solaris if possible
+           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
 
-# Choose configure options by platform.
+# Choose configure options by osversion.
 # We use the same configure options as vendor packages when possible.
-case "$platform" in
+case "$osversion" in
     centos*|rhel*)
        prefix=/usr
+       if [ $osrelease -ge 40 ]; then
+           # RHEL 4 and up support SELinux
+           configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
+       fi
        if [ $osrelease -ge 50 ]; then
-           # RHEL 5 and up build pies and have audit support
-           export CFLAGS="$F_PIE" LDFLAGS="-pie"
+           # RHEL 5 and up build pies, have audit support and use a
+           # separate PAM config file for "sudo -i".
+           export CFLAGS="-O2 -g $F_PIE" LDFLAGS="-pie"
            configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
+           configure_opts="${configure_opts}${configure_opts+$tab}--with-pam-login"
+           PPVARS="${PPVARS}${PPVARS+$space}linux_audit=1.4.0"
        fi
        # Note, must indent with tabs, not spaces due to IFS trickery
-       configure_opts="$configure_opts
-               --prefix=$prefix
+       configure_opts="--prefix=$prefix
                --with-logging=syslog
                --with-logfac=authpriv
                --with-pam
-               --with-pam-login
-               --enable-zlib
+               --enable-zlib=system
                --with-editor=/bin/vi
                --with-env-editor
                --with-ignore-dot
                --with-tty-tickets
                --with-ldap
-               --with-selinux
-               --with-passprompt=[sudo] password for %p: "
+               --with-passprompt=[sudo] password for %p: 
+               $configure_opts"
        ;;
     sles*)
        prefix=/usr
        if [ $osrelease -ge 10 ]; then
            # SLES 10 and higher build pies
-           export CFLAGS="$F_PIE" LDFLAGS="-pie"
+           export CFLAGS="-O2 -g $F_PIE" LDFLAGS="-pie"
            if [ $osrelease -ge 11 ]; then
                # SLES 11 and higher has SELinux
                configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
            fi
        fi
        # SuSE doesn't have /usr/libexec
-       case "$platform" in
-           *64*)       libexec=lib64;;
-           *)          libexec=lib;;
+       libexec=lib
+       case "$osversion" in
+           *64*)       gcc -v 2>&1 | grep "with-cpu=[^ ]*32" >/dev/null || libexec=lib64
+                       ;;
        esac
        # Note, must indent with tabs, not spaces due to IFS trickery
        # XXX - SuSE uses secure path but only for env_reset
-       configure_opts="$configure_opts
-               --prefix=$prefix
+       configure_opts="--prefix=$prefix
                --libexecdir=$prefix/$libexec/sudo
                --with-logging=syslog
                --with-logfac=auth
@@ -143,17 +175,18 @@ case "$platform" in
                --enable-shell-sets-home
                --with-sudoers-mode=0440
                --with-pam
-               --enable-zlib
+               --enable-zlib=system
                --with-ldap
                --with-env-editor
-               --with-passprompt=%p\'s password: "
+               --with-passprompt=%p\'s password: 
+               $configure_opts"
 
        make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
        ;;
     deb*|ubu*)
        prefix=/usr
        # If Ubuntu, add --enable-admin-flag
-       case "$platform" in
+       case "$osversion" in
            ubu*)
                configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
                ;;
@@ -163,12 +196,11 @@ case "$platform" in
            configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
                --with-ldap-conf-file=/etc/sudo-ldap.conf"
        fi
-       configure_opts="$configure_opts
-               --prefix=/usr
+       configure_opts="--prefix=/usr
                --with-all-insults
                --with-exempt=sudo
                --with-pam
-               --enable-zlib
+               --enable-zlib=system
                --with-fqdn
                --with-logging=syslog
                --with-logfac=authpriv
@@ -183,20 +215,27 @@ case "$platform" in
                --with-sendmail=/usr/sbin/sendmail
                --mandir=/usr/share/man
                --libexecdir=/usr/lib/sudo
-               --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin"
+               --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
+               $configure_opts"
        ;;
     *)
+       # For Solaris, add project support and use let configure choose zlib.
+       # For all others, use the builtin zlib and disable NLS support.
+       case "$osversion" in
+           sol*) configure_opts="${configure_opts}${configure_opts+$tab}--with-project";;
+           *) 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
        # Note, must indent with tabs, not spaces due to IFS trickery
-       configure_opts="$configure_opts
-               --prefix=$prefix
+       configure_opts="--prefix=$prefix
                --with-insults=disabled
                --with-logging=syslog
                --with-logfac=auth
                --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
-               --with-env-editor"
+               --with-env-editor
+               $configure_opts"
        ;;
 esac