Imported Upstream version 1.7.6p1
[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 and have audit support
126             export CFLAGS="-O2 $F_PIE" LDFLAGS="-pie"
127             configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
128             PPVARS="${PPVARS}${PPVARS+$space}linux_audit=1.4.0"
129         fi
130         # Note, must indent with tabs, not spaces due to IFS trickery
131         configure_opts="$configure_opts
132                 --prefix=$prefix
133                 --with-logging=syslog
134                 --with-logfac=authpriv
135                 --with-pam
136                 --with-pam-login
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         ;;
146     sles*)
147         prefix=/usr
148         if [ $osrelease -ge 10 ]; then
149             # SLES 10 and higher build pies
150             export CFLAGS="-O2 $F_PIE" LDFLAGS="-pie"
151             if [ $osrelease -ge 11 ]; then
152                 # SLES 11 and higher has SELinux
153                 configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
154             fi
155         fi
156         # SuSE doesn't have /usr/libexec
157         case "$osversion" in
158             *64*)       libexec=lib64;;
159             *)          libexec=lib;;
160         esac
161         # Note, must indent with tabs, not spaces due to IFS trickery
162         # XXX - SuSE uses secure path but only for env_reset
163         configure_opts="$configure_opts
164                 --prefix=$prefix
165                 --libexecdir=$prefix/$libexec/sudo
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
179         make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
180         ;;
181     deb*|ubu*)
182         prefix=/usr
183         # If Ubuntu, add --enable-admin-flag
184         case "$osversion" in
185             ubu*)
186                 configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
187                 ;;
188         esac
189         # Note, must indent with tabs, not spaces due to IFS trickery
190         if test "$flavor" = "ldap"; then
191             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
192                 --with-ldap-conf-file=/etc/sudo-ldap.conf"
193         fi
194         configure_opts="$configure_opts
195                 --prefix=/usr
196                 --with-all-insults
197                 --with-exempt=sudo
198                 --with-pam
199                 --enable-zlib=system
200                 --with-fqdn
201                 --with-logging=syslog
202                 --with-logfac=authpriv
203                 --with-env-editor
204                 --with-editor=/usr/bin/editor
205                 --with-timeout=15
206                 --with-password-timeout=0
207                 --with-passprompt=[sudo] password for %p: 
208                 --with-timedir=/var/lib/sudo
209                 --disable-root-mailer
210                 --disable-setresuid
211                 --with-sendmail=/usr/sbin/sendmail
212                 --mandir=/usr/share/man
213                 --libexecdir=/usr/lib/sudo
214                 --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin"
215         ;;
216     *)
217         # For Solaris, add project support and use let configure choose zlib.
218         # For all others, use the builtin zlib.
219         case "$osversion" in
220             sol*) configure_opts="${configure_opts}${configure_opts+$tab}--with-project";;
221             *) configure_opts="${configure_opts}${configure_opts+$tab}--enable-zlib=builtin";;
222         esac
223         if test "$flavor" = "ldap"; then
224             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
225         fi
226         # Note, must indent with tabs, not spaces due to IFS trickery
227         configure_opts="$configure_opts
228                 --prefix=$prefix
229                 --with-insults=disabled
230                 --with-logging=syslog
231                 --with-logfac=auth
232                 --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
233                 --with-env-editor"
234         ;;
235 esac
236
237 # Remove spaces from IFS when setting $@ so that passprompt may include them
238 OIFS="$IFS"
239 IFS="   $nl"
240 set -- $configure_opts $extra_opts
241 IFS="$OIFS"
242 if [ -r Makefile ]; then
243     make $make_opts distclean
244 fi
245 $top_srcdir/configure "$@" || exit 1
246 make $make_opts && make $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
247 test $debug -eq 0 && rm -rf destdir