3 # Copyright (c) 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
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.
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.
17 # Build a binary package using polypkg
18 # Usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]
21 # Make sure IFS is set to space, tab, newline in that order.
29 usage="usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]"
33 while test $# -gt 0; do
38 PPFLAGS="--debug${PPFLAGS+$space}${PPFLAGS}"
41 flavor=`echo "$1" | sed -n 's/^--flavor=\(.*\)/\1/p'`
42 PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
50 PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
54 arg=`echo "$1" | sed -n 's/^--platform=\(.*\)/\1/p'`
55 PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $arg"
62 PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $2"
66 arg=`echo "$1" | sed -n 's/^--osversion=\(.*\)/\1/p'`
79 configure_opts="${configure_opts}${configure_opts+$tab}$1"
82 # Pass unknown options to configure
83 configure_opts="${configure_opts}${configure_opts+$tab}$1"
89 top_srcdir=`dirname $0`
91 : ${osversion="`$top_srcdir/pp --probe`"}
92 test -n "$osversion" || exit 1
93 osrelease=`echo "$osversion" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
95 # Choose compiler options by osversion if not cross-compiling.
96 if [ "$crossbuild" = "false" ]; then
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
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
119 # Choose configure options by osversion.
120 # We use the same configure options as vendor packages when possible.
123 if [ $osrelease -ge 40 ]; then
124 # RHEL 4 and up support SELinux
125 configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
127 if [ $osrelease -ge 50 ]; then
128 # RHEL 5 and up has audit support and uses a separate PAM
129 # config file for "sudo -i".
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"
134 # Note, must indent with tabs, not spaces due to IFS trickery
135 configure_opts="--prefix=/usr
136 --with-logging=syslog
137 --with-logfac=authpriv
140 --with-editor=/bin/vi
145 --with-passprompt=[sudo] password for %p:
146 --with-sendmail=/usr/sbin/sendmail
150 if [ $osrelease -ge 10 ]; then
151 # SLES 11 and higher has SELinux
152 if [ $osrelease -ge 11 ]; then
153 configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
156 # SuSE doesn't have /usr/libexec
159 *64*) gcc -v 2>&1 | grep "with-cpu=[^ ]*32" >/dev/null || libexec=lib64
162 # Note, must indent with tabs, not spaces due to IFS trickery
163 # XXX - SuSE uses secure path but only for env_reset
164 configure_opts="--prefix=/usr
165 --libexecdir=/usr/$libexec
166 --with-logging=syslog
171 --enable-shell-sets-home
172 --with-sudoers-mode=0440
177 --with-passprompt=%p\'s password:
178 --with-sendmail=/usr/sbin/sendmail
181 make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
184 # Man pages should be compressed in .deb files
185 export MANCOMPRESS='gzip -9'
186 export MANCOMPRESSEXT='.gz'
187 # If Ubuntu, add --enable-admin-flag
190 configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
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"
198 configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
199 configure_opts="--prefix=/usr
204 --with-logging=syslog
205 --with-logfac=authpriv
207 --with-editor=/usr/bin/editor
209 --with-password-timeout=0
210 --with-passprompt=[sudo] password for %p:
211 --with-timedir=/var/lib/sudo
212 --disable-root-mailer
214 --with-sendmail=/usr/sbin/sendmail
215 --mandir=/usr/share/man
216 --libexecdir=/usr/lib
217 --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
223 # Build intel-only universal binaries
224 ARCH_FLAGS="-arch i386 -arch x86_64"
227 if test "${osversion}" != "`$top_srcdir/pp --probe`"; then
228 sdkvers=`echo "${osversion}" | sed 's/^macos\([0-9][0-9]\)\([0-9]*\)-.*$/\1.\2/'`
229 SDK_FLAGS="-isysroot /Developer/SDKs/MacOSX${sdkvers}.sdk -mmacosx-version-min=${sdkvers}"
231 export CFLAGS="-O2 -g $ARCH_FLAGS $SDK_FLAGS"
232 export LDFLAGS="$ARCH_FLAGS $SDK_FLAGS"
233 # Note, must indent with tabs, not spaces due to IFS trickery
234 configure_opts="--with-pam
235 --without-tty-tickets
238 --with-insults=disabled
239 --with-logging=syslog
240 --with-logfac=authpriv
241 --with-editor=/usr/bin/vim
246 # Note, must indent with tabs, not spaces due to IFS trickery
247 # Note: we include our own zlib instead of relying on the
248 # AIX freeware version being installed.
250 --prefix=/opt/freeware
251 --mandir=/opt/freeware/man
252 --with-insults=disabled
253 --with-logging=syslog
255 --with-editor=/usr/bin/vi
257 --enable-zlib=builtin
259 --with-sendmail=/usr/sbin/sendmail
261 PPVARS="${PPVARS}${PPVARS+$space}aix_freeware=true"
264 # For Solaris, add project support and use let configure choose zlib.
265 # For all others, use the builtin zlib and disable NLS support.
267 sol*) configure_opts="${configure_opts}${configure_opts+$tab}--with-project";;
268 *) configure_opts="${configure_opts}${configure_opts+$tab}--enable-zlib=builtin${tab}--disable-nls";;
270 if test "$flavor" = "ldap"; then
271 configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
273 # Note, must indent with tabs, not spaces due to IFS trickery
275 --with-insults=disabled
276 --with-logging=syslog
278 --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
284 # Remove spaces from IFS when setting $@ so that passprompt may include them
287 set -- $configure_opts $extra_opts
289 if [ -r Makefile ]; then
290 make $make_opts distclean
292 $top_srcdir/configure "$@" || exit 1
293 make $make_opts && make $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
294 test $debug -eq 0 && rm -rf destdir