Merge commit 'upstream/1.8.2'
[debian/sudo] / mkpkg
1 #!/bin/sh
2 #
3 # Build a binary package using polypkg
4 # Usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]
5 #
6
7 # Make sure IFS is set to space, tab, newline in that order.
8 space=' '
9 tab='   '
10 nl='
11 '
12 IFS="   $nl"
13
14 # Parse arguments
15 usage="usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]"
16 debug=0
17 flavor=vanilla
18 crossbuild=false
19 while test $# -gt 0; do
20     case "$1" in
21         --debug)
22             set -x
23             debug=1
24             PPFLAGS="--debug${PPFLAGS+$space}${PPFLAGS}"
25             ;;
26         --flavor=?*)
27             flavor=`echo "$1" | sed -n 's/^--flavor=\(.*\)/\1/p'`
28             PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
29             ;;
30         --flavor)
31             if [ $# -lt 2 ]; then
32                 echo "$usage" 1>&2
33                 exit 1
34             fi
35             flavor="$2"
36             PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
37             shift
38             ;;
39         --platform=?*)
40             arg=`echo "$1" | sed -n 's/^--platform=\(.*\)/\1/p'`
41             PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $arg"
42             ;;
43         --platform)
44             if [ $# -lt 2 ]; then
45                 echo "$usage" 1>&2
46                 exit 1
47             fi
48             PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $2"
49             shift
50             ;;
51         --osversion=?*)
52             arg=`echo "$1" | sed -n 's/^--osversion=\(.*\)/\1/p'`
53             osversion="$arg"
54             ;;
55         --osversion)
56             if [ $# -lt 2 ]; then
57                 echo "$usage" 1>&2
58                 exit 1
59             fi
60             osversion="$2"
61             shift
62             ;;
63         --build|--host)
64             crossbuild=true
65             configure_opts="${configure_opts}${configure_opts+$tab}$1"
66             ;;
67         *)
68             # Pass unknown options to configure
69             configure_opts="${configure_opts}${configure_opts+$tab}$1"
70             ;;
71     esac
72     shift
73 done
74
75 top_srcdir=`dirname $0`
76
77 : ${osversion="`$top_srcdir/pp --probe`"}
78 test -n "$osversion" || exit 1
79 osrelease=`echo "$osversion" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
80
81 # Default paths
82 prefix=/usr/local
83
84 # Linux distros may build binaries as pie files.
85 # This is really something libtool should figure out, but it does not.
86 case "$osversion" in
87     *-s390*|*-sparc*|*-alpha*)
88         F_PIE=-fPIE
89         ;;
90     *)
91         F_PIE=-fpie
92         ;;
93 esac
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         prefix=/usr
124         if [ $osrelease -ge 50 ]; then
125             # RHEL 5 and up build pies, have audit support and use a
126             # separate PAM config file for "sudo -i".
127             export CFLAGS="-O2 -g $F_PIE" LDFLAGS="-pie"
128             configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
129             configure_opts="${configure_opts}${configure_opts+$tab}--with-pam-login"
130             PPVARS="${PPVARS}${PPVARS+$space}linux_audit=1.4.0"
131         fi
132         # Note, must indent with tabs, not spaces due to IFS trickery
133         configure_opts="--prefix=$prefix
134                 --with-logging=syslog
135                 --with-logfac=authpriv
136                 --with-pam
137                 --enable-zlib=system
138                 --with-editor=/bin/vi
139                 --with-env-editor
140                 --with-ignore-dot
141                 --with-tty-tickets
142                 --with-ldap
143                 --with-selinux
144                 --with-passprompt=[sudo] password for %p: 
145                 $configure_opts"
146         ;;
147     sles*)
148         prefix=/usr
149         if [ $osrelease -ge 10 ]; then
150             # SLES 10 and higher build pies
151             export CFLAGS="-O2 -g $F_PIE" LDFLAGS="-pie"
152             if [ $osrelease -ge 11 ]; then
153                 # SLES 11 and higher has SELinux
154                 configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
155             fi
156         fi
157         # SuSE doesn't have /usr/libexec
158         libexec=lib
159         case "$osversion" in
160             *64*)       gcc -v 2>&1 | grep "with-cpu=[^ ]*32" >/dev/null || libexec=lib64
161                         ;;
162         esac
163         # Note, must indent with tabs, not spaces due to IFS trickery
164         # XXX - SuSE uses secure path but only for env_reset
165         configure_opts="--prefix=$prefix
166                 --libexecdir=$prefix/$libexec/sudo
167                 --with-logging=syslog
168                 --with-logfac=auth
169                 --with-all-insults
170                 --with-ignore-dot
171                 --with-tty-tickets
172                 --enable-shell-sets-home
173                 --with-sudoers-mode=0440
174                 --with-pam
175                 --enable-zlib=system
176                 --with-ldap
177                 --with-env-editor
178                 --with-passprompt=%p\'s password: 
179                 $configure_opts"
180
181         make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
182         ;;
183     deb*|ubu*)
184         prefix=/usr
185         # If Ubuntu, add --enable-admin-flag
186         case "$osversion" in
187             ubu*)
188                 configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
189                 ;;
190         esac
191         # Note, must indent with tabs, not spaces due to IFS trickery
192         if test "$flavor" = "ldap"; then
193             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
194                 --with-ldap-conf-file=/etc/sudo-ldap.conf"
195         fi
196         configure_opts="--prefix=/usr
197                 --with-all-insults
198                 --with-exempt=sudo
199                 --with-pam
200                 --enable-zlib=system
201                 --with-fqdn
202                 --with-logging=syslog
203                 --with-logfac=authpriv
204                 --with-env-editor
205                 --with-editor=/usr/bin/editor
206                 --with-timeout=15
207                 --with-password-timeout=0
208                 --with-passprompt=[sudo] password for %p: 
209                 --with-timedir=/var/lib/sudo
210                 --disable-root-mailer
211                 --disable-setresuid
212                 --with-sendmail=/usr/sbin/sendmail
213                 --mandir=/usr/share/man
214                 --libexecdir=/usr/lib/sudo
215                 --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
216                 $configure_opts"
217         ;;
218     *)
219         # For Solaris, add project support and use let configure choose zlib.
220         # For all others, use the builtin zlib and disable NLS support.
221         case "$osversion" in
222             sol*) configure_opts="${configure_opts}${configure_opts+$tab}--with-project";;
223             *) configure_opts="${configure_opts}${configure_opts+$tab}--enable-zlib=builtin${tab}--disable-nls";;
224         esac
225         if test "$flavor" = "ldap"; then
226             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
227         fi
228         # Note, must indent with tabs, not spaces due to IFS trickery
229         configure_opts="--prefix=$prefix
230                 --with-insults=disabled
231                 --with-logging=syslog
232                 --with-logfac=auth
233                 --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
234                 --with-env-editor
235                 $configure_opts"
236         ;;
237 esac
238
239 # Remove spaces from IFS when setting $@ so that passprompt may include them
240 OIFS="$IFS"
241 IFS="   $nl"
242 set -- $configure_opts $extra_opts
243 IFS="$OIFS"
244 if [ -r Makefile ]; then
245     make $make_opts distclean
246 fi
247 $top_srcdir/configure "$@" || exit 1
248 make $make_opts && make $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
249 test $debug -eq 0 && rm -rf destdir