3 # Configures and builds nmh.
4 # * If this script is not invoked from an nmh source directory, it
5 # will attempt to download the nmh sources.
6 # * This script retrieves configuration from the first existing nmh
7 # installation on your $PATH, if any.
8 # * Unless the -y option is provided, this script then interactively
9 # walks you through confirmation of common configuration settings.
12 # The first time you invoke this script, use the -i option to install
13 # nmh in the specified location. The script will walk you through the
14 # common nmh configuration settings. The -v option will cause display
15 # of brief progress indicators. Be sure to add the bin directory of
16 # the install location to your $PATH, if not already there.
17 # Subsequently, invoke this script with the -y option, to use the
18 # relevant configuration settings from the installed nmh without
23 # -b <branch> to specify branch to check out, only if downloading sources
25 # -v to display progress
26 # Subsequent uses, assuming installed nmh bin directory is on $PATH:
27 # -y to accept all configuration options without confirmation
29 # -l <logfile name>, default 'build_nmh.log', - for stdout/stderr
30 # Advanced/developer use:
31 # -c to run 'make distcheck' instead of 'make check'
32 # -d to build nmh with debug enabled
33 # -s to use 'make superclean': requires recent autoconf and automake,
34 # see docs/README.developers
37 # On Fedora, at least these rpms must be installed:
40 # cyrus-sasl-devel, if using sasl
41 # openssl-devel, if using TLS
42 # libcurl-devel, if using oauth
43 # autoconf and automake, with -s (see docs/README.developers for versions)
47 [-b <branch>, only if downloading]
48 [-c to run 'make distcheck' instead of 'make check']
49 [-d to build nmh with debug enabled]
51 [-l <logfile name>, default '$logfile']
53 [-s to use 'make superclean': requires recent autoconf and automake]
54 [-v to display progress]
55 [-y to accept all configuration options without confirmation]"
57 #### Exit with error message.
63 #### Find location of a program. Bourne shell just puts the name in
64 #### $0 if it's found from the PATH, so search that if necessary.
70 [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s
"$d" && break
75 gitrepo
=git.savannah.nongnu.org
77 tmpfile
=/tmp
/build_nmh-$$.log
78 trap 'rm -f "$tmpfile"' EXIT
81 #### Interpret command arguments.
93 while getopts 'cb:dil:rsvy?' arg
; do
95 b
) branch
="$OPTARG" ;;
96 c
) check
=distcheck
;;
99 l
) logfile
=$OPTARG ;;
104 '?') echo "$usage"; exit 0 ;;
107 shift `expr $OPTIND - 1`
109 #### Redirect all output to tmp file. Then at end of script, copy
110 #### it to either logfile or stdout. Also, grep it for errors and
112 exec 3>&1 >"$tmpfile" 2>&1
116 #### No non-option command line arguments are supported.
117 [ $# -gt 0 ] && die
"$usage"
119 #### Check to see that we're in a nmh source directory.
120 if grep 'the authors of nmh' COPYRIGHT
>/dev
/null
2>&1; then
123 #### Download sources from repo.
125 if [ "$gitdir" ]; then
127 [ "$verbose" -eq 0 ] && git_opts
=--quiet
128 [ "$branch" == master
] ||
129 git_opts
="${git_opts:+$git_opts }--branch $branch"
130 if "$gitdir"/git clone
$git_opts "git://$gitrepo/nmh.git"; then
131 cd nmh
|| die
"failed to clone nmh"
132 git log
--max-count=1 --pretty-format:%H
134 die
'failed to clone git repo'
137 [ -e nmh-
"$branch" ] && die
"nmh-$branch exists, will not overrwrite"
140 tarball
="nmh-$branch.tar.gz"
141 repo
="http://$gitrepo/cgit/nmh.git/snapshot"
142 snapshot
="$repo/$tarball"
143 if [ "`finddir wget`" ]; then
144 [ "$verbose" -eq 0 ] && wget_opts
='--quiet'
145 wget
--output-document - $wget_opts "$snapshot" | tar xzf
-
146 elif [ "`finddir curl`" ]; then
147 [ "$verbose" -eq 0 ] && curl_opts
=--silent
148 curl
--location $curl_opts "$snapshot" | tar xzf
-
150 die
'unable to find program to download nmh sources'
153 if [ -d nmh-
"$branch" ]; then
154 cd nmh-
"$branch" || die
"failed to download and extract nmh-$branch"
156 die
"failed to download nmh-$branch sources"
162 #### Set up configure options. Handle options that can have embedded
163 #### spaces (currently just smtpservers) specially.
166 #### Here are the config options that we will try to detect, then
167 #### confirm, and finally set.
168 config_prefix
=/usr
/local
/nmh
171 config_smtpservers
=localhost
178 #### Figure out whether or not to use -n with tail.
179 case `printf 'OK\n' | tail -n 1 2>&1` in
180 OK
) tail='tail -n ' ;;
184 if install-mh
-check >/dev
/null
2>&1; then
185 #### Determine config options from installed nmh.
186 mhbin
=`finddir install-mh`
188 config_prefix
=`cd $mhbin/.. && pwd`
190 mtsconf
=`mhparam etcdir`/mts.conf
191 if [ -f "$mtsconf" ]; then
192 mts_entry
=`grep '^mts:' "$mtsconf"`
193 if [ "$mts_entry" ]; then
194 mts
=`echo "$mts_entry" | sed -e 's/^mts: *//'`
195 if [ "$mts" -a "$mts" != smtp
]; then
200 mtsconfservers
=`grep '^servers:' "$mtsconf"`
201 if [ "$mtsconfservers" ]; then
202 servers
=`echo "$mtsconfservers" | \
203 sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
204 [ "$servers" ] && config_smtpservers
="$servers"
208 if test -x "$mhbin/mhparam"; then
209 if mhparam sasl
>/dev
/null
; then
210 case `$mhbin/mhparam sasl` in
211 *sasl
*) config_sasl
=y
;;
214 case `$mhbin/mhparam tls` in
215 *tls
*) config_tls
=y
;;
218 case `$mhbin/mhparam oauth` in
219 *oauth
*) config_oauth
=y
;;
223 echo "$0: SASL, TLS, and OAuth2 detection not supported with current nmh"
224 [ $yes -eq 1 ] && echo "will not configure them in"
230 [ $debug -ge 1 ] && config_debug
=y
232 if [ $yes -eq 0 ]; then
233 #### Confirm each config setting with user.
234 printf 'Install prefix [%s]: ' $config_prefix >&3
236 [ "$prefix" ] && config_prefix
="$prefix"
238 printf 'Locking type (dot|fcntl|flock|lockf) [determined by configure]: ' >&3
240 [ "$locking" ] && config_locking
="$locking"
242 printf 'MTS (smtp|sendmail/smtp|sendmail/pipe) [%s]: ' $config_mts >&3
244 [ "$mts" ] && config_mts
="$mts"
246 if [ "$config_mts" = smtp
]; then
247 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers >&3
249 servers
=`echo $response | sed -e 's/ /\\\ /g'`
250 [ "$servers" ] && config_smtpservers
="$servers"
253 printf 'Cyrus SASL support [%s]: ' $config_sasl >&3
255 [ "$response" = y
-o "$response" = Y
] && config_sasl
=y
257 printf 'TLS support [%s]: ' $config_tls >&3
259 [ "$response" = y
-o "$response" = Y
] && config_tls
=y
261 printf 'OAuth2 support [%s]: ' $config_oauth >&3
263 [ "$response" = y
-o "$response" = Y
] && config_oauth
=y
265 #### Don't confirm debug here: obey the -d option to this script.
269 config_opts
="--prefix=$config_prefix"
271 [ "$config_locking" ] &&
272 config_opts
="$config_opts --with-locking=$config_locking"
273 [ "$config_mts" -a "$config_mts" != smtp
] &&
274 config_opts
="$config_opts --with-mts=$config_mts"
275 [ "$config_smtpservers" -a "$config_smtpservers" != localhost
] &&
276 smtpservers
="--with-smtpservers=$config_smtpservers"
277 [ "$config_sasl" = y
] && config_opts
="$config_opts --with-cyrus-sasl"
278 [ "$config_tls" = y
] && config_opts
="$config_opts --with-tls"
279 [ "$config_oauth" = y
] && config_opts
="$config_opts --with-oauth"
280 [ $config_debug = y
] && config_opts
="$config_opts --enable-assert"
282 #### dotlocking, the usual default, requires chgrp and chmod of inc.
284 if [ $install -ge 1 -a "$LOGNAME" != root
]; then
285 if [ "$config_locking" = dot
]; then
286 echo "$0: "'install requires chgrp and chmod 2755'
287 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
292 tools
/showbuildenv
| grep -Ev 'PID=|SHLVL'
296 #### Set up with autoconfig if necessary.
298 if [ -f Makefile
]; then
299 [ $verbose -ge 1 ] && echo cleaning . . .
300 if [ $superclean -ge 1 ]; then
301 make superclean
>/dev
/null
303 make distclean
>/dev
/null
307 if [ ! -f configure
-o ! -f Makefile.
in ]; then
308 [ $verbose -ge 1 ] && echo autoconfiguring . . .
311 die
"autogen failed, see MACHINES file for autoconf,
312 automake, flex, and bison requirements"
319 [ $verbose -ge 1 ] && echo configuring . . .
320 if [ -z "$CFLAGS" ]; then
321 #### Only use these flags with gcc.
322 if cc
-dM -E - </dev
/null
2>&1 | grep __GNUC__
>/dev
/null
; then
323 #### configure will supply -g -O2 with gcc, but only if CFLAGS
325 CFLAGS
='-g -O2 -ansi -pedantic'
329 printf '\n./configure %s\n' "$config_opts${smtpservers:+ $smtpservers}"
330 .
/configure CFLAGS
="${CFLAGS}" $config_opts${smtpservers:+" $smtpservers"}
333 if [ $status -eq 0 ]; then
334 [ $verbose -ge 1 ] && echo building . . .
338 if [ $status -eq 0 ]; then
339 if [ "$TESTS_SHELL"x
= x
]; then
340 #### Bonus: use heirloom shell to test, if available, and if
341 #### TESTS_SHELL hadn't already been set.
342 heirloom_shell
=/usr
/lib
/heirloom
/5bin
/sh
343 if [ -x "$heirloom_shell" ]; then
344 TESTS_SHELL
="$heirloom_shell"; export TESTS_SHELL
348 if [ "$CFLAGS" ]; then
349 #### Pass DISTCHECK_CONFIGURE_FLAGS through an environment
350 #### variable to avoid automake's quoting.
351 DISTCHECK_CONFIGURE_FLAGS
="CFLAGS='${CFLAGS}'"
352 export DISTCHECK_CONFIGURE_FLAGS
355 [ $verbose -ge 1 ] && echo testing . . .
356 checkoutput
=`make $check AM_COLOR_TESTS=always`
359 tests_summary
=`echo "$checkoutput" | grep tests`
360 #### If multiple tests not run, that line will be caught by the
361 #### "grep tests" above.
362 test_not_run
=`echo "$checkoutput" | grep 'test was not run'`
363 fails
=`echo "$checkoutput" | grep FAIL`
364 if [ "$tests_summary" ]; then
365 echo '==================='
366 [ "$test_not_run" ] && echo "$test_not_run"
367 [ "$fails" ] && echo "$fails"
368 echo "$tests_summary"
369 echo '==================='
370 [ "$check" = distcheck
] && echo "$checkoutput" | ${tail}4
373 if [ $status -eq 0 ]; then
374 if [ $install -ge 1 ]; then
375 [ $verbose -ge 1 ] && echo installing . . .
376 ($installpriv make install) >/dev
/null
380 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
381 [ $verbose -ge 1 ] && echo building rpm . . .
393 #### Disable output redirection (and flush) so that we can grep.
396 if [ "$logfile" != - ]; then
398 exec 3>&1 >"$logfile" 2>&1
402 grep -E 'Error|warn' "$tmpfile"
404 if [ $status -eq 0 ]; then
405 [ $verbose -ge 1 ] && echo build completed successfully
408 [ "$logfile" = - ] || echo "build failed, build log is in $logfile" >&3