Imported Upstream version 1.8.7
[debian/sudo] / mkpkg
1 #!/bin/sh
2 #
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 #
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
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"
133         fi
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
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: 
146                 --with-sendmail=/usr/sbin/sendmail
147                 $configure_opts"
148         ;;
149     sles*)
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"
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
164         configure_opts="--prefix=/usr
165                 --libexecdir=/usr/$libexec
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: 
178                 --with-sendmail=/usr/sbin/sendmail
179                 $configure_opts"
180
181         make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
182         ;;
183     deb*|ubu*)
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
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
198         configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
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
216                 --libexecdir=/usr/lib
217                 --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
218                 $configure_opts"
219         ;;
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/'`
229             SDK_FLAGS="-isysroot /Developer/SDKs/MacOSX${sdkvers}.sdk -mmacosx-version-min=${sdkvers}"
230         fi
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
236                 --enable-zlib=system
237                 --with-ldap
238                 --with-insults=disabled
239                 --with-logging=syslog
240                 --with-logfac=authpriv
241                 --with-editor=/usr/bin/vim
242                 --with-env-editor
243                 $configure_opts"
244         ;;
245     aix*)
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.
249         configure_opts="
250                 --prefix=/opt/freeware
251                 --mandir=/opt/freeware/man
252                 --with-insults=disabled
253                 --with-logging=syslog
254                 --with-logfac=auth
255                 --with-editor=/usr/bin/vi
256                 --with-env-editor
257                 --enable-zlib=builtin
258                 --disable-nls
259                 --with-sendmail=/usr/sbin/sendmail
260                 $configure_opts"
261         PPVARS="${PPVARS}${PPVARS+$space}aix_freeware=true"
262         ;;
263     *)
264         # For Solaris, add project support and use let configure choose zlib.
265         # For all others, use the builtin zlib and disable NLS support.
266         case "$osversion" in
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";;
269         esac
270         if test "$flavor" = "ldap"; then
271             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
272         fi
273         # Note, must indent with tabs, not spaces due to IFS trickery
274         configure_opts="
275                 --with-insults=disabled
276                 --with-logging=syslog
277                 --with-logfac=auth
278                 --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
279                 --with-env-editor
280                 $configure_opts"
281         ;;
282 esac
283
284 # Remove spaces from IFS when setting $@ so that passprompt may include them
285 OIFS="$IFS"
286 IFS="   $nl"
287 set -- $configure_opts $extra_opts
288 IFS="$OIFS"
289 if [ -r Makefile ]; then
290     make $make_opts distclean
291 fi
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