Annotation of embedaddon/sudo/mkpkg, revision 1.1.1.5

1.1       misho       1: #!/bin/sh
                      2: #
1.1.1.4   misho       3: # Copyright (c) 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
                      4: #
                      5: # Permission to use, copy, modify, and distribute this software for any
                      6: # purpose with or without fee is hereby granted, provided that the above
                      7: # copyright notice and this permission notice appear in all copies.
                      8: #
                      9: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16: #
1.1       misho      17: # Build a binary package using polypkg
                     18: # Usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]
                     19: #
                     20: 
                     21: # Make sure IFS is set to space, tab, newline in that order.
                     22: space=' '
                     23: tab='  '
                     24: nl='
                     25: '
                     26: IFS="  $nl"
                     27: 
                     28: # Parse arguments
                     29: usage="usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]"
                     30: debug=0
                     31: flavor=vanilla
                     32: crossbuild=false
                     33: while test $# -gt 0; do
                     34:     case "$1" in
                     35:        --debug)
                     36:            set -x
                     37:            debug=1
                     38:            PPFLAGS="--debug${PPFLAGS+$space}${PPFLAGS}"
                     39:            ;;
                     40:        --flavor=?*)
                     41:            flavor=`echo "$1" | sed -n 's/^--flavor=\(.*\)/\1/p'`
                     42:            PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
                     43:            ;;
                     44:        --flavor)
                     45:            if [ $# -lt 2 ]; then
                     46:                echo "$usage" 1>&2
                     47:                exit 1
                     48:            fi
                     49:            flavor="$2"
                     50:            PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
                     51:            shift
                     52:            ;;
                     53:        --platform=?*)
                     54:            arg=`echo "$1" | sed -n 's/^--platform=\(.*\)/\1/p'`
                     55:            PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $arg"
                     56:            ;;
                     57:        --platform)
                     58:            if [ $# -lt 2 ]; then
                     59:                echo "$usage" 1>&2
                     60:                exit 1
                     61:            fi
                     62:            PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $2"
                     63:            shift
                     64:            ;;
                     65:        --osversion=?*)
                     66:            arg=`echo "$1" | sed -n 's/^--osversion=\(.*\)/\1/p'`
                     67:            osversion="$arg"
                     68:            ;;
                     69:        --osversion)
                     70:            if [ $# -lt 2 ]; then
                     71:                echo "$usage" 1>&2
                     72:                exit 1
                     73:            fi
                     74:            osversion="$2"
                     75:            shift
                     76:            ;;
                     77:        --build|--host)
                     78:            crossbuild=true
                     79:            configure_opts="${configure_opts}${configure_opts+$tab}$1"
                     80:            ;;
                     81:        *)
                     82:            # Pass unknown options to configure
                     83:            configure_opts="${configure_opts}${configure_opts+$tab}$1"
                     84:            ;;
                     85:     esac
                     86:     shift
                     87: done
                     88: 
                     89: top_srcdir=`dirname $0`
                     90: 
                     91: : ${osversion="`$top_srcdir/pp --probe`"}
                     92: test -n "$osversion" || exit 1
                     93: osrelease=`echo "$osversion" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
                     94: 
                     95: # Choose compiler options by osversion if not cross-compiling.
                     96: if [ "$crossbuild" = "false" ]; then
                     97:     case "$osversion" in
                     98:        hpux*)
                     99:            # Use the HP ANSI C compiler on HP-UX if possible
                    100:            if [ -z "$CC" -a -x /opt/ansic/bin/cc ]; then
                    101:                CC=/opt/ansic/bin/cc; export CC
                    102:                if [ -z "$CFLAGS" ]; then
                    103:                    CFLAGS=-O; export CFLAGS
                    104:                fi
                    105:            fi
                    106:            ;;
                    107:        sol[0-9]*)
                    108:            # Use the Sun Studio C compiler on Solaris if possible
                    109:            if [ -z "$CC" -a -x /usr/bin/cc ]; then
                    110:                CC=/usr/bin/cc; export CC
                    111:                if [ -z "$CFLAGS" ]; then
                    112:                    CFLAGS=-O; export CFLAGS
                    113:                fi
                    114:            fi
                    115:            ;;
                    116:     esac
                    117: fi
                    118: 
                    119: # Choose configure options by osversion.
                    120: # We use the same configure options as vendor packages when possible.
                    121: case "$osversion" in
                    122:     centos*|rhel*)
                    123:        if [ $osrelease -ge 40 ]; then
                    124:            # RHEL 4 and up support SELinux
                    125:            configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
                    126:        fi
                    127:        if [ $osrelease -ge 50 ]; then
1.1.1.3   misho     128:            # RHEL 5 and up has audit support and uses a separate PAM
                    129:            # config file for "sudo -i".
1.1       misho     130:            configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
                    131:            configure_opts="${configure_opts}${configure_opts+$tab}--with-pam-login"
                    132:            PPVARS="${PPVARS}${PPVARS+$space}linux_audit=1.4.0"
                    133:        fi
                    134:        # Note, must indent with tabs, not spaces due to IFS trickery
1.1.1.3   misho     135:        configure_opts="--prefix=/usr
1.1       misho     136:                --with-logging=syslog
                    137:                --with-logfac=authpriv
                    138:                --with-pam
                    139:                --enable-zlib=system
                    140:                --with-editor=/bin/vi
                    141:                --with-env-editor
                    142:                --with-ignore-dot
                    143:                --with-tty-tickets
                    144:                --with-ldap
                    145:                --with-passprompt=[sudo] password for %p: 
1.1.1.4   misho     146:                --with-sendmail=/usr/sbin/sendmail
1.1       misho     147:                $configure_opts"
                    148:        ;;
                    149:     sles*)
                    150:        if [ $osrelease -ge 10 ]; then
1.1.1.3   misho     151:            # SLES 11 and higher has SELinux
1.1       misho     152:            if [ $osrelease -ge 11 ]; then
                    153:                configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
                    154:            fi
                    155:        fi
                    156:        # SuSE doesn't have /usr/libexec
                    157:        libexec=lib
                    158:        case "$osversion" in
                    159:            *64*)       gcc -v 2>&1 | grep "with-cpu=[^ ]*32" >/dev/null || libexec=lib64
                    160:                        ;;
                    161:        esac
                    162:        # Note, must indent with tabs, not spaces due to IFS trickery
                    163:        # XXX - SuSE uses secure path but only for env_reset
1.1.1.3   misho     164:        configure_opts="--prefix=/usr
1.1.1.4   misho     165:                --libexecdir=/usr/$libexec
1.1       misho     166:                --with-logging=syslog
                    167:                --with-logfac=auth
                    168:                --with-all-insults
                    169:                --with-ignore-dot
                    170:                --with-tty-tickets
                    171:                --enable-shell-sets-home
                    172:                --with-sudoers-mode=0440
                    173:                --with-pam
                    174:                --enable-zlib=system
                    175:                --with-ldap
                    176:                --with-env-editor
                    177:                --with-passprompt=%p\'s password: 
1.1.1.4   misho     178:                --with-sendmail=/usr/sbin/sendmail
1.1       misho     179:                $configure_opts"
                    180: 
                    181:        make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
                    182:        ;;
                    183:     deb*|ubu*)
1.1.1.3   misho     184:        # Man pages should be compressed in .deb files
                    185:        export MANCOMPRESS='gzip -9'
                    186:        export MANCOMPRESSEXT='.gz'
1.1       misho     187:        # If Ubuntu, add --enable-admin-flag
                    188:        case "$osversion" in
                    189:            ubu*)
                    190:                configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
                    191:                ;;
                    192:        esac
                    193:        # Note, must indent with tabs, not spaces due to IFS trickery
                    194:        if test "$flavor" = "ldap"; then
                    195:            configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
                    196:                --with-ldap-conf-file=/etc/sudo-ldap.conf"
                    197:        fi
1.1.1.3   misho     198:        configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
1.1       misho     199:        configure_opts="--prefix=/usr
                    200:                --with-all-insults
                    201:                --with-pam
                    202:                --enable-zlib=system
                    203:                --with-fqdn
                    204:                --with-logging=syslog
                    205:                --with-logfac=authpriv
                    206:                --with-env-editor
                    207:                --with-editor=/usr/bin/editor
                    208:                --with-timeout=15
                    209:                --with-password-timeout=0
                    210:                --with-passprompt=[sudo] password for %p: 
                    211:                --with-timedir=/var/lib/sudo
                    212:                --disable-root-mailer
                    213:                --disable-setresuid
                    214:                --with-sendmail=/usr/sbin/sendmail
                    215:                --mandir=/usr/share/man
1.1.1.4   misho     216:                --libexecdir=/usr/lib
1.1       misho     217:                --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
                    218:                $configure_opts"
                    219:        ;;
1.1.1.2   misho     220:     macos*)
                    221:        case "$osversion" in
                    222:            *i386|*x86_64)
                    223:                # Build intel-only universal binaries
                    224:                ARCH_FLAGS="-arch i386 -arch x86_64"
                    225:                ;;
                    226:        esac
                    227:        if test "${osversion}" != "`$top_srcdir/pp --probe`"; then
                    228:            sdkvers=`echo "${osversion}" | sed 's/^macos\([0-9][0-9]\)\([0-9]*\)-.*$/\1.\2/'`
1.1.1.5 ! misho     229:            # Newer Xcode puts /Developer under the app Contents dir.
        !           230:            SDK_DIR="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs"
        !           231:            if test -d "${SDK_DIR}/MacOSX${sdkvers}.sdk"; then
        !           232:                SDK_DIR="${SDK_DIR}/MacOSX${sdkvers}.sdk"
        !           233:            elif test -d "/Developer/SDKs/MacOSX${sdkvers}.sdk"; then
        !           234:                SDK_DIR="/Developer/SDKs/MacOSX${sdkvers}.sdk"
        !           235:            fi
        !           236:            SDK_FLAGS="-isysroot ${SDK_DIR} -mmacosx-version-min=${sdkvers}"
1.1.1.2   misho     237:        fi
                    238:        export CFLAGS="-O2 -g $ARCH_FLAGS $SDK_FLAGS"
                    239:        export LDFLAGS="$ARCH_FLAGS $SDK_FLAGS"
                    240:        # Note, must indent with tabs, not spaces due to IFS trickery
1.1.1.3   misho     241:        configure_opts="--with-pam
1.1.1.5 ! misho     242:                --with-bsm-audit
1.1.1.2   misho     243:                --without-tty-tickets
                    244:                --enable-zlib=system
                    245:                --with-ldap
                    246:                --with-insults=disabled
                    247:                --with-logging=syslog
                    248:                --with-logfac=authpriv
                    249:                --with-editor=/usr/bin/vim
                    250:                --with-env-editor
                    251:                $configure_opts"
                    252:        ;;
1.1.1.3   misho     253:     aix*)
1.1.1.5 ! misho     254:        # Use -gxcoff with gcc instead of -g for dbx-style debugging symbols.
        !           255:        if test -z "$CC" && gcc -v >/dev/null 2>&1; then
        !           256:            CFLAGS=-gxcoff; export CFLAGS
        !           257:        fi
1.1.1.3   misho     258:        # Note, must indent with tabs, not spaces due to IFS trickery
                    259:        # Note: we include our own zlib instead of relying on the
                    260:        #       AIX freeware version being installed.
                    261:        configure_opts="
                    262:                --prefix=/opt/freeware
                    263:                --mandir=/opt/freeware/man
                    264:                --with-insults=disabled
                    265:                --with-logging=syslog
                    266:                --with-logfac=auth
                    267:                --with-editor=/usr/bin/vi
                    268:                --with-env-editor
                    269:                --enable-zlib=builtin
                    270:                --disable-nls
1.1.1.4   misho     271:                --with-sendmail=/usr/sbin/sendmail
1.1.1.3   misho     272:                $configure_opts"
                    273:        PPVARS="${PPVARS}${PPVARS+$space}aix_freeware=true"
                    274:        ;;
1.1       misho     275:     *)
                    276:        # For Solaris, add project support and use let configure choose zlib.
                    277:        # For all others, use the builtin zlib and disable NLS support.
                    278:        case "$osversion" in
1.1.1.5 ! misho     279:            sol*)
        !           280:                configure_opts="${configure_opts}${configure_opts+$tab}--with-project"
        !           281: 
        !           282:                if [ $osrelease -ge 11 ]; then
        !           283:                    configure_opts="${configure_opts}${configure_opts+$tab}--with-bsm-audit"
        !           284:                fi
        !           285:                ;;
        !           286:            *)
        !           287:                configure_opts="${configure_opts}${configure_opts+$tab}--enable-zlib=builtin${tab}--disable-nls"
        !           288:                ;;
1.1       misho     289:        esac
                    290:        if test "$flavor" = "ldap"; then
                    291:            configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
                    292:        fi
                    293:        # Note, must indent with tabs, not spaces due to IFS trickery
1.1.1.3   misho     294:        configure_opts="
1.1       misho     295:                --with-insults=disabled
                    296:                --with-logging=syslog
                    297:                --with-logfac=auth
                    298:                --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
                    299:                --with-env-editor
                    300:                $configure_opts"
                    301:        ;;
                    302: esac
                    303: 
                    304: # Remove spaces from IFS when setting $@ so that passprompt may include them
                    305: OIFS="$IFS"
                    306: IFS="  $nl"
                    307: set -- $configure_opts $extra_opts
                    308: IFS="$OIFS"
                    309: if [ -r Makefile ]; then
                    310:     make $make_opts distclean
                    311: fi
                    312: $top_srcdir/configure "$@" || exit 1
                    313: make $make_opts && make $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
                    314: test $debug -eq 0 && rm -rf destdir

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>