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.
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
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
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
35 # On Fedora, at least these rpms must be installed:
38 # cyrus-sasl-devel, if using sasl
39 # openssl-devel, if using TLS
40 # libcurl-devel, if using oauth
41 # autoconf and automake, with -s (see docs/README.developers for versions)
46 #### Interpret command arguments.
57 [-c to run 'make distcheck' instead of 'make check']
58 [-d to build nmh with debug enabled]
60 [-l <logfile name>, default '$logfile']
62 [-s to use 'make superclean': requires recent autoconf and automake]
63 [-v to display progress]
64 [-y to accept all configuration options without confirmation]"
66 while getopts 'cdil:rsvy?' arg; do
68 c ) check=distcheck ;;
71 l ) logfile=$OPTARG ;;
76 '?') echo "$usage"; exit 0 ;;
79 shift `expr $OPTIND - 1`
81 #### No command line arguments are supported.
87 #### Check to see that we're in a nmh source directory.
88 if ! grep 'the authors of nmh' COPYRIGHT >/dev/null; then
89 echo "$0: not in nmh source directory"
94 #### Set up configure options. Handle options that can have embedded
95 #### spaces (currently just smtpservers) specially.
98 #### Here are the config options that we will try to detect, then
99 #### confirm, and finally set.
100 config_prefix=/usr/local/nmh
103 config_smtpservers=localhost
110 #### Find location of a program. Bourne shell just puts the name in
111 #### $0 if it's found from the PATH, so search that if necessary.
117 [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s "$d" && break
122 #### Figure out whether or not to use -n with tail.
123 case `printf 'OK\n' | tail -n 1 2>&1` in
124 OK) tail='tail -n ' ;;
128 if install-mh -check >/dev/null 2>&1; then
129 # Determine config options from installed nmh.
130 mhbin=`finddir install-mh`
132 config_prefix=`cd $mhbin/.. && pwd`
134 mtsconf=`mhparam etcdir`/mts.conf
135 if [ -f "$mtsconf" ]; then
136 mts_entry=`grep '^mts:' "$mtsconf"`
137 if [ "$mts_entry" ]; then
138 mts=`echo "$mts_entry" | sed -e 's/^mts: *//'`
139 if [ "$mts" -a "$mts" != smtp ]; then
144 mtsconfservers=`grep '^servers:' "$mtsconf"`
145 if [ "$mtsconfservers" ]; then
146 servers=`echo "$mtsconfservers" | \
147 sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
148 [ "$servers" ] && config_smtpservers="$servers"
152 if test -x "$mhbin/mhparam"; then
153 if mhparam sasl >/dev/null; then
154 case `$mhbin/mhparam sasl` in
155 *sasl*) config_sasl=y ;;
158 case `$mhbin/mhparam tls` in
159 *tls*) config_tls=y ;;
162 case `$mhbin/mhparam oauth` in
163 *oauth*) config_oauth=y ;;
167 echo "$0: SASL, TLS, and OAuth2 detection not supported with current nmh"
168 [ $yes -eq 1 ] && echo "will not configure them in"
174 [ $debug -ge 1 ] && config_debug=y
176 if [ $yes -eq 0 ]; then
177 #### Confirm each config setting with user.
178 printf 'Install prefix [%s]: ' $config_prefix
180 [ "$prefix" ] && config_prefix="$prefix"
182 printf 'Locking type (dot|fcntl|flock|lockf) [determined by configure]: '
184 [ "$locking" ] && config_locking="$locking"
186 printf 'MTS (smtp|sendmail/smtp|sendmail/pipe) [%s]: ' $config_mts
188 [ "$mts" ] && config_mts="$mts"
190 if [ "$config_mts" = smtp ]; then
191 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers
193 servers=`echo $response | sed -e 's/ /\\\ /g'`
194 [ "$servers" ] && config_smtpservers="$servers"
197 printf 'Cyrus SASL support [%s]: ' $config_sasl
199 if [ "$response" = y -o "$response" = Y ]; then
201 elif [ "$response" = n -o "$response" = N ]; then
205 printf 'TLS support [%s]: ' $config_tls
207 if [ "$response" = y -o "$response" = Y ]; then
209 elif [ "$response" = n -o "$response" = N ]; then
213 printf 'OAuth2 support [%s]: ' $config_oauth
215 if [ "$response" = y -o "$response" = Y ]; then
217 elif [ "$response" = n -o "$response" = N ]; then
221 #### Don't confirm debug here: obey the -d option to this script.
225 config_opts="--prefix=$config_prefix"
227 [ "$config_locking" ] && \
228 config_opts="$config_opts --with-locking=$config_locking"
229 [ "$config_mts" -a "$config_mts" != smtp ] && \
230 config_opts="$config_opts --with-mts=$config_mts"
231 [ "$config_smtpservers" -a "$config_smtpservers" != localhost ] && \
232 smtpservers="--with-smtpservers=$config_smtpservers"
233 [ "$config_sasl" = y ] && \
234 config_opts="$config_opts --with-cyrus-sasl"
235 [ "$config_tls" = y ] && \
236 config_opts="$config_opts --with-tls"
237 [ "$config_oauth" = y ] && \
238 config_opts="$config_opts --with-oauth"
239 [ $config_debug = y ] && \
240 config_opts="$config_opts --enable-debug --enable-assert"
242 #### dotlocking, the usual default, requires chgrp and chmod of inc.
244 if [ $install -ge 1 -a `id -u` -ne 0 ]; then
245 if [ "$config_locking" = dot ]; then
246 echo "$0: "'install requires chgrp and chmod 2755'
247 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
254 #### Clean up, and set up with autoconfig if necessary.
256 if [ -f Makefile ]; then
257 [ $verbose -ge 1 ] && echo cleaning . . .
258 if [ $superclean -ge 1 ]; then
259 make superclean >/dev/null
261 make distclean >/dev/null
265 /bin/rm -f "$logfile"
266 if [ ! -f configure -o ! -f Makefile.in ]; then
267 [ $verbose -ge 1 ] && echo autoconfiguring . . .
268 ./autogen.sh >>"$logfile" 2>&1
275 [ $verbose -ge 1 ] && echo configuring . . .
276 echo ./configure $config_opts ${smtpservers:+"$smtpservers"} >>"$logfile" 2>&1
277 ./configure CFLAGS="${CFLAGS:+$CFLAGS }-g -O2 -ansi -pedantic" \
278 $config_opts ${smtpservers:+"$smtpservers"} >>"$logfile" 2>&1
281 if [ $status -eq 0 ]; then
282 [ $verbose -ge 1 ] && echo building . . .
283 make >>"$logfile" 2>&1
286 if [ $status -eq 0 ]; then
287 if [ "$TESTS_SHELL"x = x ]; then
288 #### Bonus: use heirloom shell to test, if available, and if
289 #### TESTS_SHELL hadn't already been set.
290 heirloom_shell=/usr/lib/heirloom/5bin/sh
291 if [ -x "$heirloom_shell" ]; then
292 TESTS_SHELL="$heirloom_shell"; export TESTS_SHELL
296 [ $verbose -ge 1 ] && echo testing . . .
297 checkoutput=`make $check AM_COLOR_TESTS=always 2>>"$logfile"`
300 tests_summary=`echo "$checkoutput" | grep tests`
301 #### If multiple tests not run, that line will be caught by the
302 #### "grep tests" above.
303 test_not_run=`echo "$checkoutput" | grep 'test was not run'`
304 fails=`echo "$checkoutput" | grep FAIL`
305 if [ "$tests_summary" ]; then
306 echo '===================' >>"$logfile"
307 [ "$test_not_run" ] && echo "$test_not_run" >>"$logfile"
308 [ "$fails" ] && echo "$fails" >>"$logfile"
309 echo "$tests_summary" >>"$logfile"
310 echo '===================' >>"$logfile"
311 [ "$check" = distcheck ] && \
312 echo "$checkoutput" | ${tail}4 >>"$logfile"
315 if [ $status -eq 0 ]; then
316 if [ $install -ge 1 ]; then
317 [ $verbose -ge 1 ] && echo installing . . .
318 ($installpriv make install) >/dev/null 2>>"$logfile"
322 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
323 [ $verbose -ge 1 ] && echo building rpm . . .
324 make rpm >/dev/null 2>>"$logfile"
331 grep Error "$logfile"
334 if [ $status -eq 0 ]; then
335 [ $verbose -ge 1 ] && echo build completed successfully
338 echo build log is in "$logfile"