patch from Svante Signell to fix build problem on GNU/Hurd, closes: #611290
[debian/sudo] / mkpkg
1 #!/bin/sh
2 #
3 # Build a binary package using polypkg
4 # Usage: mkpkg [--debug] [--flavor flavor] [--platform platform]
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]"
16 debug=0
17 flavor=vanilla
18 while test $# -gt 0; do
19     case "$1" in
20         --debug)
21             set -x
22             debug=1
23             PPFLAGS="--debug${PPFLAGS+$space}${PPFLAGS}"
24             ;;
25         --flavor=?*)
26             flavor=`echo "$1" | sed -n 's/^--flavor=\(.*\)/\1/p'`
27             PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
28             ;;
29         --flavor)
30             if [ $# -lt 2 ]; then
31                 echo "$usage" 1>&2
32                 exit 1
33             fi
34             flavor="$2"
35             PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
36             shift
37             ;;
38         --platform=?*)
39             arg=`echo "$1" | sed -n 's/^--platform=\(.*\)/\1/p'`
40             PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $arg"
41             ;;
42         --platform)
43             if [ $# -lt 2 ]; then
44                 echo "$usage" 1>&2
45                 exit 1
46             fi
47             PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $2"
48             shift
49             ;;
50         *)
51             # Pass unknown options to configure
52             configure_opts="${configure_opts}${configure_opts+$tab}$1"
53             ;;
54     esac
55     shift
56 done
57
58 top_srcdir=`dirname $0`
59
60 platform=`$top_srcdir/pp --probe` || exit 1
61 osrelease=`echo "$platform" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
62
63 # Default paths
64 prefix=/usr/local
65
66 # Linux distros may build binaries as pie files.
67 # This is really something libtool should figure out, but it does not.
68 case "$platform" in
69     *-s390*|*-sparc*|*-alpha*)
70         F_PIE=-fPIE
71         ;;
72     *)
73         F_PIE=-fpie
74         ;;
75 esac
76
77 # Choose compiler options by platform.
78 case "$platform" in
79     hpux*)
80         # Use the HP ANSI C compiler on HP-UX if possible
81         if [ -z "$CC" -a -x /opt/ansic/bin/cc ]; then
82             CC=/opt/ansic/bin/cc; export CC
83             if [ -z "$CFLAGS" ]; then
84                 CFLAGS=-O; export CFLAGS
85             fi
86         else
87             configure_opts="${configure_opts}${configure_opts+$tab}--disable-zlib"
88         fi
89         ;;
90 esac
91
92 # Choose configure options by platform.
93 # We use the same configure options as vendor packages when possible.
94 case "$platform" in
95     centos*|rhel*)
96         prefix=/usr
97         if [ $osrelease -ge 50 ]; then
98             # RHEL 5 and up build pies and have audit support
99             export CFLAGS="$F_PIE" LDFLAGS="-pie"
100             configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
101         fi
102         # Note, must indent with tabs, not spaces due to IFS trickery
103         configure_opts="$configure_opts
104                 --prefix=$prefix
105                 --with-logging=syslog
106                 --with-logfac=authpriv
107                 --with-pam
108                 --with-pam-login
109                 --enable-zlib
110                 --with-editor=/bin/vi
111                 --with-env-editor
112                 --with-ignore-dot
113                 --with-tty-tickets
114                 --with-ldap
115                 --with-selinux
116                 --with-passprompt=[sudo] password for %p: "
117         ;;
118     sles*)
119         prefix=/usr
120         if [ $osrelease -ge 10 ]; then
121             # SLES 10 and higher build pies
122             export CFLAGS="$F_PIE" LDFLAGS="-pie"
123             if [ $osrelease -ge 11 ]; then
124                 # SLES 11 and higher has SELinux
125                 configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
126             fi
127         fi
128         # SuSE doesn't have /usr/libexec
129         case "$platform" in
130             *64*)       libexec=lib64;;
131             *)          libexec=lib;;
132         esac
133         # Note, must indent with tabs, not spaces due to IFS trickery
134         # XXX - SuSE uses secure path but only for env_reset
135         configure_opts="$configure_opts
136                 --prefix=$prefix
137                 --libexecdir=$prefix/$libexec/sudo
138                 --with-logging=syslog
139                 --with-logfac=auth
140                 --with-all-insults
141                 --with-ignore-dot
142                 --with-tty-tickets
143                 --enable-shell-sets-home
144                 --with-sudoers-mode=0440
145                 --with-pam
146                 --enable-zlib
147                 --with-ldap
148                 --with-env-editor
149                 --with-passprompt=%p\'s password: "
150
151         make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
152         ;;
153     deb*|ubu*)
154         prefix=/usr
155         # If Ubuntu, add --enable-admin-flag
156         case "$platform" in
157             ubu*)
158                 configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
159                 ;;
160         esac
161         # Note, must indent with tabs, not spaces due to IFS trickery
162         if test "$flavor" = "ldap"; then
163             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
164                 --with-ldap-conf-file=/etc/sudo-ldap.conf"
165         fi
166         configure_opts="$configure_opts
167                 --prefix=/usr
168                 --with-all-insults
169                 --with-exempt=sudo
170                 --with-pam
171                 --enable-zlib
172                 --with-fqdn
173                 --with-logging=syslog
174                 --with-logfac=authpriv
175                 --with-env-editor
176                 --with-editor=/usr/bin/editor
177                 --with-timeout=15
178                 --with-password-timeout=0
179                 --with-passprompt=[sudo] password for %p: 
180                 --with-timedir=/var/lib/sudo
181                 --disable-root-mailer
182                 --disable-setresuid
183                 --with-sendmail=/usr/sbin/sendmail
184                 --mandir=/usr/share/man
185                 --libexecdir=/usr/lib/sudo
186                 --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin"
187         ;;
188     *)
189         if test "$flavor" = "ldap"; then
190             configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
191         fi
192         # Note, must indent with tabs, not spaces due to IFS trickery
193         configure_opts="$configure_opts
194                 --prefix=$prefix
195                 --with-insults=disabled
196                 --with-logging=syslog
197                 --with-logfac=auth
198                 --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
199                 --with-env-editor"
200         ;;
201 esac
202
203 # Remove spaces from IFS when setting $@ so that passprompt may include them
204 OIFS="$IFS"
205 IFS="   $nl"
206 set -- $configure_opts $extra_opts
207 IFS="$OIFS"
208 if [ -r Makefile ]; then
209     make $make_opts distclean
210 fi
211 $top_srcdir/configure "$@" || exit 1
212 make $make_opts && make $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
213 test $debug -eq 0 && rm -rf destdir