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.
11 # This file can be downloaded and immediately run using, e.g.,
12 # wget http://git.savannah.gnu.org/cgit/nmh.git/plain/build_nmh
16 # The first time you invoke this script, use the -i option to install
17 # nmh in the specified location. The script will walk you through the
18 # common nmh configuration settings. The -v option will cause display
19 # of brief progress indicators. Be sure to add the bin directory of
20 # the install location to your $PATH, if not already there.
21 # Subsequently, invoke this script with the -y option, to use the
22 # relevant configuration settings from the installed nmh without
27 # -b <branch> to specify branch to check out, only if downloading sources
29 # -v to display progress
30 # Subsequent uses, assuming installed nmh bin directory is on $PATH:
31 # -y to accept all configuration options without confirmation
33 # -l <logfile name>, default 'build_nmh.log', - for stdout/stderr
34 # Advanced/developer use:
35 # -c to run 'make distcheck' instead of 'make check'
36 # -d to build nmh with asserts enabled and optimization disabled
37 # -s to use 'make superclean': requires recent autoconf and automake,
38 # see docs/README.developers
41 # To disable colorization of the test summary, either unset the TERM
42 # environment variable or set it to dumb, e.g., TERM=dumb build_nmh.
44 # See the nmh MACHINES file for build prerequisites. In addition, the rpmbuild
45 # is required to be available if the -r option is used.
49 [-b <branch>, only if downloading]
50 [-c to run 'make distcheck' instead of 'make check']
51 [-d to build nmh with asserts enabled and optimization disabled]
53 [-l <logfile name>, default '$logfile']
55 [-s to use 'make superclean': requires recent autoconf and automake]
56 [-v to display progress]
57 [-y to accept all configuration options without confirmation]"
59 #### Find location of a program. Bourne shell just puts the name in
60 #### $0 if it's found from the PATH, so search that if necessary.
66 [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s
"$d" && break
71 #### Make sure user sees error output even on early termination.
73 if [ "$tmpfile" ]; then
74 #### Disable output redirection (and flush) so that we can grep.
75 #### If $tmpfile is null, don't need to do this because the
76 #### outputs weren't redirected, modulo a small race condition
77 #### between setting tmpfile and redirecting the outputs.
78 exec 1>&3 3>&- 2>&4 4>&-
80 if [ "$logfile" != - ]; then
81 exec 3>&1 >"$logfile" 2>&1
84 if [ -f "$tmpfile" ]; then
86 grep -E 'Error|warn' "$tmpfile"
91 #### Put info message on stdout, and in log if not stdout.
92 if [ $status -ne 0 -o $verbose -ge 1 -o "$directory" ]; then
93 [ $status -eq 0 ] && result
=succeeded
|| result
=failed
94 if [ "$logfile" = - ]; then
97 message
="build $result, build log is in ${directory:+$directory/}$logfile"
102 #### Heirloom shell does not like "trap - signal".
107 #### Exit with error message.
109 status
=1 # It should already be, but just in case the code below changes.
114 #### Download sources from repo. With git and on master, the
115 #### directory will be nmh, but with snapshot, it will be
118 [ $verbose -ge 1 ] && echo downloading . . .
>&3
120 if [ "$gitdir" ]; then
122 [ "$verbose" -eq 0 ] && git_opts
=--quiet
123 [ "$branch" = master
] ||
124 git_opts
="${git_opts:+$git_opts }--branch $branch"
125 if "$gitdir"/git clone
--depth 1 $git_opts "git://$gitrepo/nmh.git" >&3
128 cd "$directory" || die
"failed to clone $directory"
129 printf "commit %s\n" `git log --max-count=1 --pretty=format:%H`
131 die
'failed to clone git repo'
134 [ -e nmh
-"$branch" ] && die
"nmh-$branch exists, will not overrwrite"
137 tarball
="nmh-$branch.tar.gz"
138 repo
="http://$gitrepo/cgit/nmh.git/snapshot"
139 snapshot
="$repo/$tarball"
140 if [ "`finddir wget`" ]; then
141 [ "$verbose" -eq 0 ] && wget_opts
='--quiet'
142 wget
--output-document - $wget_opts "$snapshot" 2>&3 | gzip -d | tar xf
-
143 elif [ "`finddir curl`" ]; then
144 [ "$verbose" -eq 0 ] && curl_opts
='--silent --show-error'
145 curl
--location $curl_opts "$snapshot" 2>&3 | gzip -d | tar xf
-
147 die
'unable to find program to download nmh sources'
150 if [ -d nmh
-"$branch" ]; then
151 directory
=nmh
-"$branch"
152 cd "$directory" || die
"failed to download and extract $directory"
154 die
"failed to download nmh-$branch sources"
161 gitrepo
=git.savannah.nongnu.org
164 tmpfile
=/tmp
/build_nmh
-$$.log
166 #### Redirect all output to tmp file. Then on EXIT, copy it to either
167 #### logfile or stdout. Also, grep it for errors and warnings. Set
168 #### tmpfile just prior to this, see cleanup().
169 exec 3>&1 4>&2 >"$tmpfile" 2>&1
173 #### Interpret command arguments.
184 #### With dash, heirloom shell, and posh, need to catch INT and QUIT
185 #### in order for cleanup to be call: just EXIT isn't sufficient.
186 trap cleanup EXIT INT QUIT
188 while getopts 'cb:dil:rsvy?' arg
; do
190 b
) branch
="$OPTARG" ;;
191 c
) check
=distcheck
;;
194 l
) logfile
=$OPTARG ;;
199 '?') echo "$0: $usage"; logfile
=-; status
=0; exit ;;
202 shift `expr $OPTIND - 1`
206 #### No non-option command line arguments are supported.
207 [ $# -gt 0 ] && die
"$usage"
209 #### Check to see that we're in a nmh source directory.
210 if grep 'the authors of nmh' COPYRIGHT
>/dev
/null
2>&1; then
217 #### Set up configure options. Handle options that can have embedded
218 #### spaces (currently just smtpservers) specially.
221 #### Here are the config options that we will try to detect, then
222 #### confirm, and finally set.
223 config_prefix
=/usr
/local
/nmh
226 config_smtpservers
=localhost
227 config_sasl
='determined by configure'
228 config_tls
='determined by configure'
232 #### Figure out whether or not to use -n with tail.
233 case `printf 'OK\n' | tail -n 1 2>&1` in
234 OK
) tail='tail -n ' ;;
238 if install-mh -check >/dev
/null
2>&1; then
239 #### Determine config options from installed nmh.
240 mhbin
=`finddir install-mh`
242 config_prefix
=`cd $mhbin/.. && pwd`
244 mtsconf
=`mhparam etcdir`/mts.conf
245 if [ -f "$mtsconf" ]; then
246 mts_entry
=`grep '^mts:' "$mtsconf"`
247 if [ "$mts_entry" ]; then
248 mts
=`echo "$mts_entry" | sed -e 's/^mts: *//'`
249 if [ "$mts" -a "$mts" != smtp
]; then
254 mtsconfservers
=`grep '^servers:' "$mtsconf"`
255 if [ "$mtsconfservers" ]; then
256 servers
=`echo "$mtsconfservers" | \
257 sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
258 [ "$servers" ] && config_smtpservers
="$servers"
262 if test -x "$mhbin/mhparam"; then
263 if mhparam sasl
>/dev
/null
; then
264 case `$mhbin/mhparam sasl` in
265 *sasl
*) config_sasl
=y
;;
268 case `$mhbin/mhparam tls` in
269 *tls
*) config_tls
=y
;;
273 echo "$0: SASL and TLS detection not supported with current nmh"
274 [ $yes -eq 1 ] && echo "configure will determine whether to enable"
280 #### Don't confirm debug interactively below; obey the -d option.
281 [ $debug -ge 1 ] && config_debug
=y
283 if [ $yes -eq 0 ]; then
284 #### Confirm each config setting with user.
285 printf 'Install prefix [%s]: ' $config_prefix >&3
287 [ "$prefix" ] && config_prefix
="$prefix"
289 printf 'Locking type (dot|fcntl|flock|lockf) [determined by configure]: ' >&3
291 [ "$locking" ] && config_locking
="$locking"
293 printf 'MTS (smtp|sendmail/smtp|sendmail/pipe) [%s]: ' $config_mts >&3
295 [ "$mts" ] && config_mts
="$mts"
297 if [ "$config_mts" = smtp
]; then
298 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers >&3
300 servers
=`echo $response | sed -e 's/ /\\\ /g'`
301 [ "$servers" ] && config_smtpservers
="$servers"
304 printf 'Cyrus SASL support (y|n) [%s]: ' "$config_sasl" >&3
306 [ "$response" = y
-o "$response" = Y
] && config_sasl
=y
308 printf 'TLS support (y|n) [%s]: ' "$config_tls" >&3
310 [ "$response" = y
-o "$response" = Y
] && config_tls
=y
314 config_opts
="--prefix=$config_prefix"
316 [ "$config_locking" ] &&
317 config_opts
="$config_opts --with-locking=$config_locking"
318 [ "$config_mts" -a "$config_mts" != smtp
] &&
319 config_opts
="$config_opts --with-mts=$config_mts"
320 [ "$config_smtpservers" -a "$config_smtpservers" != localhost
] &&
321 smtpservers
="--with-smtpservers=$config_smtpservers"
322 [ "$config_sasl" = y
] && config_opts
="$config_opts --with-cyrus-sasl"
323 [ "$config_tls" = y
] && config_opts
="$config_opts --with-tls"
324 [ $config_debug = y
] && config_opts
="$config_opts --enable-assert"
326 #### dotlocking, the usual default, requires chgrp and chmod of inc.
328 if [ $install -ge 1 -a "$LOGNAME" != root
]; then
329 if [ "$config_locking" = dot
]; then
330 echo "$0: "'install requires chgrp and chmod 2755'
331 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
336 printf '\n%s %s %s %s\n\n' "`uname -m`" "`uname -s`" "`uname -r`" "`uname -v`"
337 [ -f /etc
/os
-release ] && printf '%s\n\n' "`cat /etc/os-release`"
339 [ $download -eq 1 ] && download_sources
342 #### Set up with autoconfig if necessary.
344 if [ -f Makefile
]; then
345 [ $verbose -ge 1 ] && echo cleaning . . .
>&3
346 if [ $superclean -ge 1 ]; then
347 make superclean
>/dev
/null
349 make distclean
>/dev
/null
353 if [ ! -f configure
-o ! -f Makefile.
in ]; then
354 [ $verbose -ge 1 ] && echo autoconfiguring . . .
>&3
357 die
"autogen failed, see MACHINES file for autoconf,
358 automake, flex, and bison requirements"
365 [ $verbose -ge 1 ] && echo configuring . . .
>&3
366 if [ -z "$CFLAGS" ]; then
367 #### Only use these flags with gcc.
368 if cc
-dM -E - </dev
/null
2>&1 | grep __GNUC__
>/dev
/null
; then
369 #### configure will supply -g -O2 with gcc, but only if CFLAGS
371 CFLAGS
='-g -ansi -pedantic'
372 if [ "$config_debug" = n
]; then
380 printf '\n./configure %s\n' "$config_opts${smtpservers:+ $smtpservers}"
381 .
/configure CFLAGS
="${CFLAGS}" $config_opts${smtpservers:+" $smtpservers"}
384 if [ $status -eq 0 ]; then
385 [ $verbose -ge 1 ] && echo building . . .
>&3
389 if [ $status -eq 0 ]; then
390 if [ "$TESTS_SHELL"x
= x
]; then
391 #### Bonus: use heirloom shell to test, if available, and if
392 #### TESTS_SHELL hadn't already been set.
393 heirloom_shell
=/usr
/lib
/heirloom
/5bin
/sh
394 if [ -x "$heirloom_shell" ]; then
395 TESTS_SHELL
="$heirloom_shell"; export TESTS_SHELL
399 if [ "$CFLAGS" ]; then
400 #### Pass DISTCHECK_CONFIGURE_FLAGS through an environment
401 #### variable to avoid automake's quoting.
402 DISTCHECK_CONFIGURE_FLAGS
="CFLAGS='${CFLAGS}'"
403 export DISTCHECK_CONFIGURE_FLAGS
406 [ $verbose -ge 1 ] && echo testing . . .
>&3
407 [ "${TERM:-dumb}" = dumb
] && color
=no
|| color
=always
408 checkoutput
=`make $check AM_COLOR_TESTS=$color`
411 tests_summary
=`echo "$checkoutput" | grep tests`
412 #### If multiple tests not run, that line will be caught by the
413 #### "grep tests" above.
414 test_not_run
=`echo "$checkoutput" | grep 'test was not run'`
415 fails
=`echo "$checkoutput" | grep FAIL`
416 if [ "$tests_summary" ]; then
417 echo '==================='
418 [ "$test_not_run" ] && echo "$test_not_run"
419 [ "$fails" ] && echo "$fails"
420 echo "$tests_summary"
421 echo '==================='
422 [ "$check" = distcheck
] && echo "$checkoutput" | ${tail}4
425 if [ $status -eq 0 ]; then
426 if [ $install -ge 1 ]; then
427 [ $verbose -ge 1 ] && echo installing . . .
>&3
428 ($installpriv make install) >/dev
/null
432 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
433 [ $verbose -ge 1 ] && echo building rpm . . .
>&3
440 echo "see nmh MACHINES file for build dependences"
443 #### Will call cleanup, which will exit with $status.