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/docs/contrib/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 debug enabled
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.
48 [-b <branch>, only if downloading]
49 [-c to run 'make distcheck' instead of 'make check']
50 [-d to build nmh with debug enabled]
52 [-l <logfile name>, default '$logfile']
54 [-s to use 'make superclean': requires recent autoconf and automake]
55 [-v to display progress]
56 [-y to accept all configuration options without confirmation]"
58 #### Exit with error message.
61 exec 1>&3 3>&- 2>&4 4>&-
67 #### Find location of a program. Bourne shell just puts the name in
68 #### $0 if it's found from the PATH, so search that if necessary.
74 [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s
"$d" && break
79 #### Make sure user sees error output even on early termination. Assumes
80 #### that called programs exit with non-zero status when terminated.
82 if [ $status -eq 0 ]; then
85 [ $logfile = - ] && cat "$tmpfile" 1>&3 || mv "$tmpfile" "$logfile"
91 gitrepo
=git.savannah.nongnu.org
93 tmpfile
=/tmp
/build_nmh-$$.log
97 #### Interpret command arguments.
103 logfile
=build_nmh.log
109 while getopts 'cb:dil:rsvy?' arg
; do
111 b
) branch
="$OPTARG" ;;
112 c
) check
=distcheck
;;
115 l
) logfile
=$OPTARG ;;
120 '?') echo "$usage"; exit 0 ;;
123 shift `expr $OPTIND - 1`
125 #### Redirect all output to tmp file. Then at end of script, copy
126 #### it to either logfile or stdout. Also, grep it for errors and
128 exec 3>&1 4>&2 >"$tmpfile" 2>&1
132 #### No non-option command line arguments are supported.
133 [ $# -gt 0 ] && die
"$usage"
135 #### Check to see that we're in a nmh source directory.
136 if grep 'the authors of nmh' COPYRIGHT
>/dev
/null
2>&1; then
139 #### Download sources from repo.
140 [ $verbose -ge 1 ] && echo downloading . . .
>&3
142 if [ "$gitdir" ]; then
144 [ "$verbose" -eq 0 ] && git_opts
=--quiet
145 [ "$branch" == master
] ||
146 git_opts
="${git_opts:+$git_opts }--branch $branch"
147 if "$gitdir"/git clone
--depth 1 $git_opts "git://$gitrepo/nmh.git" >&3; then
149 cd "$directory" || die
"failed to clone $directory"
150 printf "commit %s\n" `git log --max-count=1 --pretty=format:%H`
152 die
'failed to clone git repo'
155 [ -e nmh-
"$branch" ] && die
"nmh-$branch exists, will not overrwrite"
158 tarball
="nmh-$branch.tar.gz"
159 repo
="http://$gitrepo/cgit/nmh.git/snapshot"
160 snapshot
="$repo/$tarball"
161 if [ "`finddir wget`" ]; then
162 [ "$verbose" -eq 0 ] && wget_opts
='--quiet'
163 wget
--output-document - $wget_opts "$snapshot" 2>&3 | gzip -d | tar xf
-
164 elif [ "`finddir curl`" ]; then
165 [ "$verbose" -eq 0 ] && curl_opts
='--silent --show-error'
166 curl
--location $curl_opts "$snapshot" 2>&3 | gzip -d | tar xf
-
168 die
'unable to find program to download nmh sources'
171 if [ -d nmh-
"$branch" ]; then
172 directory
=nmh-
"$branch"
173 cd "$directory" || die
"failed to download and extract $directory"
175 die
"failed to download nmh-$branch sources"
181 #### Set up configure options. Handle options that can have embedded
182 #### spaces (currently just smtpservers) specially.
185 #### Here are the config options that we will try to detect, then
186 #### confirm, and finally set.
187 config_prefix
=/usr
/local
/nmh
190 config_smtpservers
=localhost
197 #### Figure out whether or not to use -n with tail.
198 case `printf 'OK\n' | tail -n 1 2>&1` in
199 OK
) tail='tail -n ' ;;
203 if install-mh
-check >/dev
/null
2>&1; then
204 #### Determine config options from installed nmh.
205 mhbin
=`finddir install-mh`
207 config_prefix
=`cd $mhbin/.. && pwd`
209 mtsconf
=`mhparam etcdir`/mts.conf
210 if [ -f "$mtsconf" ]; then
211 mts_entry
=`grep '^mts:' "$mtsconf"`
212 if [ "$mts_entry" ]; then
213 mts
=`echo "$mts_entry" | sed -e 's/^mts: *//'`
214 if [ "$mts" -a "$mts" != smtp
]; then
219 mtsconfservers
=`grep '^servers:' "$mtsconf"`
220 if [ "$mtsconfservers" ]; then
221 servers
=`echo "$mtsconfservers" | \
222 sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
223 [ "$servers" ] && config_smtpservers
="$servers"
227 if test -x "$mhbin/mhparam"; then
228 if mhparam sasl
>/dev
/null
; then
229 case `$mhbin/mhparam sasl` in
230 *sasl
*) config_sasl
=y
;;
233 case `$mhbin/mhparam tls` in
234 *tls
*) config_tls
=y
;;
237 case `$mhbin/mhparam oauth` in
238 *oauth
*) config_oauth
=y
;;
242 echo "$0: SASL, TLS, and OAuth2 detection not supported with current nmh"
243 [ $yes -eq 1 ] && echo "will not configure them in"
249 [ $debug -ge 1 ] && config_debug
=y
251 if [ $yes -eq 0 ]; then
252 #### Confirm each config setting with user.
253 printf 'Install prefix [%s]: ' $config_prefix >&3
255 [ "$prefix" ] && config_prefix
="$prefix"
257 printf 'Locking type (dot|fcntl|flock|lockf) [determined by configure]: ' >&3
259 [ "$locking" ] && config_locking
="$locking"
261 printf 'MTS (smtp|sendmail/smtp|sendmail/pipe) [%s]: ' $config_mts >&3
263 [ "$mts" ] && config_mts
="$mts"
265 if [ "$config_mts" = smtp
]; then
266 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers >&3
268 servers
=`echo $response | sed -e 's/ /\\\ /g'`
269 [ "$servers" ] && config_smtpservers
="$servers"
272 printf 'Cyrus SASL support [%s]: ' $config_sasl >&3
274 [ "$response" = y
-o "$response" = Y
] && config_sasl
=y
276 printf 'TLS support [%s]: ' $config_tls >&3
278 [ "$response" = y
-o "$response" = Y
] && config_tls
=y
280 printf 'OAuth2 support [%s]: ' $config_oauth >&3
282 [ "$response" = y
-o "$response" = Y
] && config_oauth
=y
284 #### Don't confirm debug here: obey the -d option to this script.
288 config_opts
="--prefix=$config_prefix"
290 [ "$config_locking" ] &&
291 config_opts
="$config_opts --with-locking=$config_locking"
292 [ "$config_mts" -a "$config_mts" != smtp
] &&
293 config_opts
="$config_opts --with-mts=$config_mts"
294 [ "$config_smtpservers" -a "$config_smtpservers" != localhost
] &&
295 smtpservers
="--with-smtpservers=$config_smtpservers"
296 [ "$config_sasl" = y
] && config_opts
="$config_opts --with-cyrus-sasl"
297 [ "$config_tls" = y
] && config_opts
="$config_opts --with-tls"
298 [ "$config_oauth" = y
] && config_opts
="$config_opts --with-oauth"
299 [ $config_debug = y
] && config_opts
="$config_opts --enable-assert"
301 #### dotlocking, the usual default, requires chgrp and chmod of inc.
303 if [ $install -ge 1 -a "$LOGNAME" != root
]; then
304 if [ "$config_locking" = dot
]; then
305 echo "$0: "'install requires chgrp and chmod 2755'
306 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
311 printf '\n%s %s %s %s\n\n' "`uname -m`" "`uname -s`" "`uname -r`" "`uname -v`"
312 [ -f /etc
/os-release
] && printf '%s\n\n' "`cat /etc/os-release`"
315 #### Set up with autoconfig if necessary.
317 if [ -f Makefile
]; then
318 [ $verbose -ge 1 ] && echo cleaning . . .
>&3
319 if [ $superclean -ge 1 ]; then
320 make superclean
>/dev
/null
322 make distclean
>/dev
/null
326 if [ ! -f configure
-o ! -f Makefile.
in ]; then
327 [ $verbose -ge 1 ] && echo autoconfiguring . . .
>&3
330 die
"autogen failed, see MACHINES file for autoconf,
331 automake, flex, and bison requirements"
338 [ $verbose -ge 1 ] && echo configuring . . .
>&3
339 if [ -z "$CFLAGS" ]; then
340 #### Only use these flags with gcc.
341 if cc
-dM -E - </dev
/null
2>&1 | grep __GNUC__
>/dev
/null
; then
342 #### configure will supply -g -O2 with gcc, but only if CFLAGS
344 CFLAGS
='-g -O2 -ansi -pedantic'
348 printf '\n./configure %s\n' "$config_opts${smtpservers:+ $smtpservers}"
349 .
/configure CFLAGS
="${CFLAGS}" $config_opts${smtpservers:+" $smtpservers"}
352 if [ $status -eq 0 ]; then
353 [ $verbose -ge 1 ] && echo building . . .
>&3
357 if [ $status -eq 0 ]; then
358 if [ "$TESTS_SHELL"x
= x
]; then
359 #### Bonus: use heirloom shell to test, if available, and if
360 #### TESTS_SHELL hadn't already been set.
361 heirloom_shell
=/usr
/lib
/heirloom
/5bin
/sh
362 if [ -x "$heirloom_shell" ]; then
363 TESTS_SHELL
="$heirloom_shell"; export TESTS_SHELL
367 if [ "$CFLAGS" ]; then
368 #### Pass DISTCHECK_CONFIGURE_FLAGS through an environment
369 #### variable to avoid automake's quoting.
370 DISTCHECK_CONFIGURE_FLAGS
="CFLAGS='${CFLAGS}'"
371 export DISTCHECK_CONFIGURE_FLAGS
374 [ $verbose -ge 1 ] && echo testing . . .
>&3
375 [ "${TERM:-dumb}" = dumb
] && color
=no
|| color
=always
376 checkoutput
=`make $check AM_COLOR_TESTS=$color`
379 tests_summary
=`echo "$checkoutput" | grep tests`
380 #### If multiple tests not run, that line will be caught by the
381 #### "grep tests" above.
382 test_not_run
=`echo "$checkoutput" | grep 'test was not run'`
383 fails
=`echo "$checkoutput" | grep FAIL`
384 if [ "$tests_summary" ]; then
385 echo '==================='
386 [ "$test_not_run" ] && echo "$test_not_run"
387 [ "$fails" ] && echo "$fails"
388 echo "$tests_summary"
389 echo '==================='
390 [ "$check" = distcheck
] && echo "$checkoutput" | ${tail}4
393 if [ $status -eq 0 ]; then
394 if [ $install -ge 1 ]; then
395 [ $verbose -ge 1 ] && echo installing . . .
>&3
396 ($installpriv make install) >/dev
/null
400 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
401 [ $verbose -ge 1 ] && echo building rpm . . .
>&3
408 echo "see nmh MACHINES file for build dependences"
415 #### Disable output redirection (and flush) so that we can grep.
416 exec 1>&3 3>&- 2>&4 4>&-
418 if [ "$logfile" != - ]; then
420 exec 3>&1 >"$logfile" 2>&1
423 [ -f "$tmpfile" ] && cat "$tmpfile"
424 [ -f "$tmpfile" ] && grep -E 'Error|warn' "$tmpfile"
426 #### Put message on stdout, and in log if different.
427 if [ $status -ne 0 -o $verbose -ge 1 -o "$directory" ]; then
428 [ $status -eq 0 ] && indication
=succeeded
|| indication
=failed
429 message
="build $indication, build log is in ${directory:+$directory/}$logfile"
431 [ "$logfile" = - ] || echo "$message" >&3