]> diplodocus.org Git - nmh/blob - docs/contrib/build_nmh
Added check for successful decode of a different part with
[nmh] / docs / contrib / build_nmh
1 #! /bin/sh
2 #
3 # Configures and builds nmh.
4 # * This script must be invoked from an nmh source directory.
5 # * This script retrieves configuration from the first existing nmh
6 # installation on your $PATH, if any.
7 # * Unless the -y option is provided, this script then interactively
8 # walks you through confirmation of common configuration settings.
9 #
10 # Typical usage:
11 # The first time you invoke this script, use the -i option to install
12 # nmh in the specified location. The script will walk you through the
13 # common nmh configuration settings. The -v option will cause display
14 # of brief progress indicators. Be sure to add the bin directory of
15 # the install location to your $PATH, if not already there.
16 # Subsequently, invoke this script with the -y option, to use the
17 # relevant configuration settings from the installed nmh without
18 # confirmation.
19 #
20 # Option summary:
21 # First time use:
22 # -i to install nmh
23 # -v to display progress
24 # Subsequent uses, assuming installed nmh bin directory is on $PATH:
25 # -y to accept all configuration options without confirmation
26 # Output control:
27 # -l <logfile name>, default 'build_nmh.log'
28 # Advanced/developer use:
29 # -c to run 'make distcheck' instead of 'make check'
30 # -d to build nmh with debug enabled
31 # -s to use 'make superclean': requires recent autoconf and automake,
32 # see docs/README.developers
33 # -r to build rpm
34 #
35 # On Fedora, at least these rpms must be installed:
36 # gdbm-devel
37 # ncurses-devel
38 # cyrus-sasl-devel, if using sasl
39 # openssl-devel, if using TLS
40 # autoconf and automake, with -s (see docs/README.developers for versions)
41 # rpm-build, with -r
42
43
44 ####
45 #### Interpret command arguments.
46 ####
47 check=check
48 debug=0
49 install=0
50 logfile=build_nmh.log
51 build_rpm=0
52 superclean=0
53 verbose=0
54 yes=0
55 usage="usage: $0
56 [-c to run 'make distcheck' instead of 'make check']
57 [-d to build nmh with debug enabled]
58 [-i to install nmh]
59 [-l <logfile name>, default '$logfile']
60 [-r to build rpm]
61 [-s to use 'make superclean': requires recent autoconf and automake]
62 [-v to display progress]
63 [-y to accept all configuration options without confirmation]"
64
65 while getopts 'cdil:rsvy?' arg; do
66 case $arg in
67 c ) check=distcheck ;;
68 d ) debug=1 ;;
69 i ) install=1 ;;
70 l ) logfile=$OPTARG ;;
71 r ) build_rpm=1 ;;
72 s ) superclean=1 ;;
73 v ) verbose=1 ;;
74 y ) yes=1 ;;
75 '?') echo "$usage"; exit 0 ;;
76 esac
77 done
78 shift `expr $OPTIND - 1`
79
80 #### No command line arguments are supported.
81 if [ $# -gt 0 ]; then
82 echo "usage: $0"
83 exit 1
84 fi
85
86 #### Check to see that we're in a nmh source directory.
87 if ! grep 'the authors of nmh' COPYRIGHT >/dev/null; then
88 echo "$0: not in nmh source directory"
89 exit 1
90 fi
91
92 ####
93 #### Set up configure options. Handle options that can have embedded
94 #### spaces (currently just smtpservers) specially.
95 ####
96
97 #### Here are the config options that we will try to detect, then
98 #### confirm, and finally set.
99 config_prefix=/usr/local/nmh
100 config_locking=
101 config_mts=smtp
102 config_smtpservers=localhost
103 config_sasl=n
104 config_tls=n
105 config_debug=n
106
107
108 #### Find location of a program. Bourne shell just puts the name in
109 #### $0 if it's found from the PATH, so search that if necessary.
110 finddir() {
111 case $1 in
112 */*) dirname "$1" ;;
113 * ) IFS=:
114 for d in $PATH; do
115 [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s "$d" && break
116 done ;;
117 esac
118 }
119
120 #### Figure out whether or not to use -n with tail.
121 case `printf 'OK\n' | tail -n 1 2>&1` in
122 OK) tail='tail -n ' ;;
123 *) tail='tail -' ;;
124 esac
125
126 if install-mh -check >/dev/null 2>&1; then
127 # Determine config options from installed nmh.
128 mhbin=`finddir install-mh`
129
130 config_prefix=`cd $mhbin/.. && pwd`
131
132 mtsconf=`mhparam etcdir`/mts.conf
133 if [ -f "$mtsconf" ]; then
134 mts_entry=`grep '^mts:' "$mtsconf"`
135 if [ "$mts_entry" ]; then
136 mts=`echo "$mts_entry" | sed -e 's/^mts: *//'`
137 if [ "$mts" -a "$mts" != smtp ]; then
138 config_mts="$mts"
139 fi
140 fi
141
142 mtsconfservers=`grep '^servers:' "$mtsconf"`
143 if [ "$mtsconfservers" ]; then
144 servers=`echo "$mtsconfservers" | \
145 sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
146 [ "$servers" ] && config_smtpservers="$servers"
147 fi
148 fi
149
150 if test -x "$mhbin/mhparam"; then
151 if mhparam sasl >/dev/null; then
152 case `$mhbin/mhparam sasl` in
153 *sasl*) config_sasl=y ;;
154 esac
155
156 case `$mhbin/mhparam tls` in
157 *tls*) config_tls=y ;;
158 esac
159 else
160 tput smso
161 echo "$0: SASL and TLS detection not supported with current nmh"
162 [ $yes -eq 1 ] && echo "will not configure either one in"
163 tput rmso
164 fi
165 fi
166 fi
167
168 [ $debug -ge 1 ] && config_debug=y
169
170 if [ $yes -eq 0 ]; then
171 #### Confirm each config setting with user.
172 printf 'Install prefix [%s]: ' $config_prefix
173 read prefix
174 [ "$prefix" ] && config_prefix="$prefix"
175
176 printf 'Locking type (dot|fcntl|flock|lockf) [determined by configure]: '
177 read locking
178 [ "$locking" ] && config_locking="$locking"
179
180 printf 'MTS (smtp|sendmail/smtp|sendmail/pipe) [%s]: ' $config_mts
181 read mts
182 [ "$mts" ] && config_mts="$mts"
183
184 if [ "$config_mts" = smtp ]; then
185 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers
186 read response
187 servers=`echo $response | sed -e 's/ /\\\ /g'`
188 [ "$servers" ] && config_smtpservers="$servers"
189 fi
190
191 printf 'Cyrus SASL support [%s]: ' $config_sasl
192 read response
193 if [ "$response" = y -o "$response" = Y ]; then
194 config_sasl=y
195 elif [ "$response" = n -o "$response" = N ]; then
196 config_sasl=n
197 fi
198
199 printf 'TLS support [%s]: ' $config_tls
200 read response
201 if [ "$response" = y -o "$response" = Y ]; then
202 config_tls=y
203 elif [ "$response" = n -o "$response" = N ]; then
204 config_tls=n
205 fi
206
207 #### Don't confirm debug here: obey the -d option to this script.
208 fi
209
210 smtpservers=
211 config_opts="--prefix=$config_prefix"
212
213 [ "$config_locking" ] && \
214 config_opts="$config_opts --with-locking=$config_locking"
215 [ "$config_mts" -a "$config_mts" != smtp ] && \
216 config_opts="$config_opts --with-mts=$config_mts"
217 [ "$config_smtpservers" -a "$config_smtpservers" != localhost ] && \
218 smtpservers="--with-smtpservers=$config_smtpservers"
219 [ "$config_sasl" = y ] && \
220 config_opts="$config_opts --with-cyrus-sasl"
221 [ "$config_tls" = y ] && \
222 config_opts="$config_opts --with-tls"
223 [ $config_debug = y ] && \
224 config_opts="$config_opts --enable-debug --enable-assert"
225
226
227 #### dotlocking, the usual default, requires chgrp and chmod of inc.
228 installpriv=
229 if [ $install -ge 1 -a `id -u` -ne 0 ]; then
230 if [ "$config_locking" = dot ]; then
231 echo "$0: "'install requires chgrp and chmod 2755'
232 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
233 installpriv=sudo
234 fi
235 fi
236
237
238 ####
239 #### Clean up, and set up with autoconfig if necessary.
240 ####
241 if [ -f Makefile ]; then
242 [ $verbose -ge 1 ] && echo cleaning . . .
243 if [ $superclean -ge 1 ]; then
244 make superclean >/dev/null
245 else
246 make distclean >/dev/null
247 fi
248 fi
249
250 /bin/rm -f "$logfile"
251 if [ ! -f configure -o ! -f Makefile.in ]; then
252 [ $verbose -ge 1 ] && echo autoconfiguring . . .
253 ./autogen.sh >>"$logfile" 2>&1
254 fi
255
256
257 ####
258 #### Build.
259 ####
260 [ $verbose -ge 1 ] && echo configuring . . .
261 echo ./configure $config_opts ${smtpservers:+"$smtpservers"} >>"$logfile" 2>&1
262 ./configure CFLAGS="${CFLAGS:+$CFLAGS }-g -O2 -ansi -pedantic" \
263 $config_opts ${smtpservers:+"$smtpservers"} >>"$logfile" 2>&1
264 status=$?
265
266 if [ $status -eq 0 ]; then
267 [ $verbose -ge 1 ] && echo building . . .
268 make >>"$logfile" 2>&1
269 status=$?
270
271 if [ $status -eq 0 ]; then
272 if [ "$TESTS_SHELL"x = x ]; then
273 #### Bonus: use heirloom shell to test, if available, and if
274 #### TESTS_SHELL hadn't already been set.
275 heirloom_shell=/usr/lib/heirloom/5bin/sh
276 if [ -x "$heirloom_shell" ]; then
277 TESTS_SHELL="$heirloom_shell"; export TESTS_SHELL
278 fi
279 fi
280
281 [ $verbose -ge 1 ] && echo testing . . .
282 checkoutput=`make $check AM_COLOR_TESTS=always 2>>"$logfile"`
283 status=$?
284
285 tests_summary=`echo "$checkoutput" | grep tests`
286 #### If multiple tests not run, that line will be caught by the
287 #### "grep tests" above.
288 test_not_run=`echo "$checkoutput" | grep 'test was not run'`
289 fails=`echo "$checkoutput" | grep FAIL`
290 if [ "$tests_summary" ]; then
291 echo '===================' >>"$logfile"
292 [ "$test_not_run" ] && echo "$test_not_run" >>"$logfile"
293 [ "$fails" ] && echo "$fails" >>"$logfile"
294 echo "$tests_summary" >>"$logfile"
295 echo '===================' >>"$logfile"
296 [ "$check" = distcheck ] && \
297 echo "$checkoutput" | ${tail}4 >>"$logfile"
298 fi
299
300 if [ $status -eq 0 ]; then
301 if [ $install -ge 1 ]; then
302 [ $verbose -ge 1 ] && echo installing . . .
303 ($installpriv make install) >/dev/null 2>>"$logfile"
304 status=$?
305 fi
306
307 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
308 [ $verbose -ge 1 ] && echo building rpm . . .
309 make rpm >/dev/null 2>>"$logfile"
310 status=$?
311 fi
312 fi
313 fi
314 fi
315
316 grep Error "$logfile"
317 grep warn "$logfile"
318
319 if [ $status -eq 0 ]; then
320 [ $verbose -ge 1 ] && echo build completed successfully
321 else
322 echo build failed!
323 echo build log is in "$logfile"
324 fi
325
326 exit $status