06e54fc17c4fe2684d75b6e4a077bc9c94ae1064
[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 # Choose compiler options by osversion if not cross-compiling.
82 if [ "$crossbuild" = "false" ]; then
83     case "$osversion" in
84         hpux*)
85             # Use the HP ANSI C compiler on HP-UX if possible
86             if [ -z "$CC" -a -x /opt/ansic/bin/cc ]; then
87                 CC=/opt/ansic/bin/cc; export CC
88                 if [ -z "$CFLAGS" ]; then
89                     CFLAGS=-O; export CFLAGS
90                 fi
91             fi
92             ;;
93         sol[0-9]*)
94             # Use the Sun Studio C compiler on Solaris if possible
95             if [ -z "$CC" -a -x /usr/bin/cc ]; then
96                 CC=/usr/bin/cc; export CC
97                 if [ -z "$CFLAGS" ]; then
98                     CFLAGS=-O; export CFLAGS
99                 fi
100             fi
101             ;;
102     esac
103 fi
104
105 # Choose configure options by osversion.
106 # We use the same configure options as vendor packages when possible.
107 case "$osversion" in
108     centos*|rhel*)
109         if [ $osrelease -ge 40 ]; then
110             # RHEL 4 and up support SELinux
111             configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
112         fi
113         if [ $osrelease -ge 50 ]; then
114             # RHEL 5 and up has audit support and uses a separate PAM
115             # config file for "sudo -i".
116             configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
117             configure_opts="${configure_opts}${configure_opts+$tab}--with-pam-login"
118             PPVARS="${PPVARS}${PPVARS+$space}linux_audit=1.4.0"
119         fi
120         # Note, must indent with tabs, not spaces due to IFS trickery
121         configure_opts="--prefix=/usr
122                 --with-logging=syslog
123                 --with-logfac=authpriv
124                 --with-pam
125                 --enable-zlib=system
126                 --with-editor=/bin/vi
127                 --with-env-editor
128                 --with-ignore-dot
129                 --with-tty-tickets
130                 --with-ldap
131                 --with-passprompt=[sudo] password for %p: 
132                 $configure_opts"
133         ;;
134     sles*)
135         if [ $osrelease -ge 10 ]; then
136             # SLES 11 and higher has SELinux
137             if [ $osrelease -ge 11 ]; then
138                 configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
139             fi
140         fi
141         # SuSE doesn't have /usr/libexec
142         libexec=lib
143         case "$osversion" in
144             *64*)       gcc -v 2>&1 | grep "with-cpu=[^ ]*32" >/dev/null || libexec=lib64
145                         ;;
146         esac
147         # Note, must indent with tabs, not spaces due to IFS trickery
148         # XXX - SuSE uses secure path but only for env_reset
149         configure_opts="--prefix=/usr
150                 --libexecdir=/usr/$libexec/sudo
151                 --with-logging=syslog
152                 --with-logfac=auth
153                 --with-all-insults
154                 --with-ignore-dot
155                 --with-tty-tickets
156                 --enable-shell-sets-home
157                 --with-sudoers-mode=0440
158                 --with-pam
159                 --enable-zlib=system
160                 --with-ldap
161                 --with-env-editor
162                 --with-passprompt=%p\'s password: 
163                 $configure_opts"
164
165         make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
166         ;;
167     deb*|ubu*)
168         # Man pages should be compressed in .deb files
169         export MANCOMPRESS='gzip -9'
170         export MANCOMPRESSEXT='.gz'
171         # If Ubuntu, add --enable-admin-flag
172         case "$osversion" in
173             ubu*)
174                 configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
175                 ;;
176         esac
177         # Note, must indent with tabs, not spaces due to IFS trickery
178         if test "$flavor" = "ldap"; then
179             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
180                 --with-ldap-conf-file=/etc/sudo-ldap.conf"
181         fi
182         configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
183         configure_opts="--prefix=/usr
184                 --with-all-insults
185                 --with-pam
186                 --enable-zlib=system
187                 --with-fqdn
188                 --with-logging=syslog
189                 --with-logfac=authpriv
190                 --with-env-editor
191                 --with-editor=/usr/bin/editor
192                 --with-timeout=15
193                 --with-password-timeout=0
194                 --with-passprompt=[sudo] password for %p: 
195                 --with-timedir=/var/lib/sudo
196                 --disable-root-mailer
197                 --disable-setresuid
198                 --with-sendmail=/usr/sbin/sendmail
199                 --mandir=/usr/share/man
200                 --libexecdir=/usr/lib/sudo
201                 --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
202                 $configure_opts"
203         ;;
204     macos*)
205         case "$osversion" in
206             *i386|*x86_64)
207                 # Build intel-only universal binaries
208                 ARCH_FLAGS="-arch i386 -arch x86_64"
209                 ;;
210         esac
211         if test "${osversion}" != "`$top_srcdir/pp --probe`"; then
212             sdkvers=`echo "${osversion}" | sed 's/^macos\([0-9][0-9]\)\([0-9]*\)-.*$/\1.\2/'`
213             SDK_FLAGS="-isysroot /Developer/SDKs/MacOSX${sdkvers}.sdk -mmacosx-version-min=${sdkvers}"
214         fi
215         export CFLAGS="-O2 -g $ARCH_FLAGS $SDK_FLAGS"
216         export LDFLAGS="$ARCH_FLAGS $SDK_FLAGS"
217         # Note, must indent with tabs, not spaces due to IFS trickery
218         configure_opts="--with-pam
219                 --without-tty-tickets
220                 --enable-zlib=system
221                 --with-ldap
222                 --with-insults=disabled
223                 --with-logging=syslog
224                 --with-logfac=authpriv
225                 --with-editor=/usr/bin/vim
226                 --with-env-editor
227                 $configure_opts"
228         ;;
229     aix*)
230         # Note, must indent with tabs, not spaces due to IFS trickery
231         # Note: we include our own zlib instead of relying on the
232         #       AIX freeware version being installed.
233         configure_opts="
234                 --prefix=/opt/freeware
235                 --mandir=/opt/freeware/man
236                 --with-insults=disabled
237                 --with-logging=syslog
238                 --with-logfac=auth
239                 --with-editor=/usr/bin/vi
240                 --with-env-editor
241                 --enable-zlib=builtin
242                 --disable-nls
243                 $configure_opts"
244         PPVARS="${PPVARS}${PPVARS+$space}aix_freeware=true"
245         ;;
246     *)
247         # For Solaris, add project support and use let configure choose zlib.
248         # For all others, use the builtin zlib and disable NLS support.
249         case "$osversion" in
250             sol*) configure_opts="${configure_opts}${configure_opts+$tab}--with-project${tab}--disable-pie";;
251             *) configure_opts="${configure_opts}${configure_opts+$tab}--enable-zlib=builtin${tab}--disable-nls";;
252         esac
253         if test "$flavor" = "ldap"; then
254             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
255         fi
256         # Note, must indent with tabs, not spaces due to IFS trickery
257         configure_opts="
258                 --with-insults=disabled
259                 --with-logging=syslog
260                 --with-logfac=auth
261                 --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
262                 --with-env-editor
263                 $configure_opts"
264         ;;
265 esac
266
267 # Remove spaces from IFS when setting $@ so that passprompt may include them
268 OIFS="$IFS"
269 IFS="   $nl"
270 set -- $configure_opts $extra_opts
271 IFS="$OIFS"
272 if [ -r Makefile ]; then
273     make $make_opts distclean
274 fi
275 $top_srcdir/configure "$@" || exit 1
276 make $make_opts && make $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
277 test $debug -eq 0 && rm -rf destdir