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 # On Fedora, at least these rpms must be installed:
44 # cyrus-sasl-devel, if using sasl
45 # openssl-devel, if using TLS
46 # libcurl-devel, if using oauth
47 # autoconf and automake, with -s (see docs/README.developers for versions)
51 [-b <branch>, only if downloading]
52 [-c to run 'make distcheck' instead of 'make check']
53 [-d to build nmh with debug enabled]
55 [-l <logfile name>, default '$logfile']
57 [-s to use 'make superclean': requires recent autoconf and automake]
58 [-v to display progress]
59 [-y to accept all configuration options without confirmation]"
61 #### Exit with error message.
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 gitrepo
=git.savannah.nongnu.org
81 tmpfile
=/tmp
/build_nmh
-$$.log
82 trap 'rm -f "$tmpfile"' EXIT
85 #### Interpret command arguments.
97 while getopts 'cb:dil:rsvy?' arg
; do
99 b
) branch
="$OPTARG" ;;
100 c
) check
=distcheck
;;
103 l
) logfile
=$OPTARG ;;
108 '?') echo "$usage"; exit 0 ;;
111 shift `expr $OPTIND - 1`
113 #### Redirect all output to tmp file. Then at end of script, copy
114 #### it to either logfile or stdout. Also, grep it for errors and
116 exec 3>&1 >"$tmpfile" 2>&1
120 #### No non-option command line arguments are supported.
121 [ $# -gt 0 ] && die
"$usage"
123 #### Check to see that we're in a nmh source directory.
124 if grep 'the authors of nmh' COPYRIGHT
>/dev
/null
2>&1; then
127 #### Download sources from repo.
129 if [ "$gitdir" ]; then
131 [ "$verbose" -eq 0 ] && git_opts
=--quiet
132 [ "$branch" == master
] ||
133 git_opts
="${git_opts:+$git_opts }--branch $branch"
134 if "$gitdir"/git clone
--depth 1 $git_opts "git://$gitrepo/nmh.git"; then
135 cd nmh
|| die
"failed to clone nmh"
136 printf "commit %s\n" `git log --max-count=1 --pretty=format:%H`
138 die
'failed to clone git repo'
141 [ -e nmh
-"$branch" ] && die
"nmh-$branch exists, will not overrwrite"
144 tarball
="nmh-$branch.tar.gz"
145 repo
="http://$gitrepo/cgit/nmh.git/snapshot"
146 snapshot
="$repo/$tarball"
147 if [ "`finddir wget`" ]; then
148 [ "$verbose" -eq 0 ] && wget_opts
='--quiet'
149 wget
--output-document - $wget_opts "$snapshot" | gzip -d | tar xf
-
150 elif [ "`finddir curl`" ]; then
151 [ "$verbose" -eq 0 ] && curl_opts
='--silent --show-error'
152 curl
--location $curl_opts "$snapshot" | gzip -d | tar xf
-
154 die
'unable to find program to download nmh sources'
157 if [ -d nmh
-"$branch" ]; then
158 cd nmh
-"$branch" || die
"failed to download and extract nmh-$branch"
160 die
"failed to download nmh-$branch sources"
166 #### Set up configure options. Handle options that can have embedded
167 #### spaces (currently just smtpservers) specially.
170 #### Here are the config options that we will try to detect, then
171 #### confirm, and finally set.
172 config_prefix
=/usr
/local
/nmh
175 config_smtpservers
=localhost
182 #### Figure out whether or not to use -n with tail.
183 case `printf 'OK\n' | tail -n 1 2>&1` in
184 OK
) tail='tail -n ' ;;
188 if install-mh -check >/dev
/null
2>&1; then
189 #### Determine config options from installed nmh.
190 mhbin
=`finddir install-mh`
192 config_prefix
=`cd $mhbin/.. && pwd`
194 mtsconf
=`mhparam etcdir`/mts.conf
195 if [ -f "$mtsconf" ]; then
196 mts_entry
=`grep '^mts:' "$mtsconf"`
197 if [ "$mts_entry" ]; then
198 mts
=`echo "$mts_entry" | sed -e 's/^mts: *//'`
199 if [ "$mts" -a "$mts" != smtp
]; then
204 mtsconfservers
=`grep '^servers:' "$mtsconf"`
205 if [ "$mtsconfservers" ]; then
206 servers
=`echo "$mtsconfservers" | \
207 sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
208 [ "$servers" ] && config_smtpservers
="$servers"
212 if test -x "$mhbin/mhparam"; then
213 if mhparam sasl
>/dev
/null
; then
214 case `$mhbin/mhparam sasl` in
215 *sasl
*) config_sasl
=y
;;
218 case `$mhbin/mhparam tls` in
219 *tls
*) config_tls
=y
;;
222 case `$mhbin/mhparam oauth` in
223 *oauth
*) config_oauth
=y
;;
227 echo "$0: SASL, TLS, and OAuth2 detection not supported with current nmh"
228 [ $yes -eq 1 ] && echo "will not configure them in"
234 [ $debug -ge 1 ] && config_debug
=y
236 if [ $yes -eq 0 ]; then
237 #### Confirm each config setting with user.
238 printf 'Install prefix [%s]: ' $config_prefix >&3
240 [ "$prefix" ] && config_prefix
="$prefix"
242 printf 'Locking type (dot|fcntl|flock|lockf) [determined by configure]: ' >&3
244 [ "$locking" ] && config_locking
="$locking"
246 printf 'MTS (smtp|sendmail/smtp|sendmail/pipe) [%s]: ' $config_mts >&3
248 [ "$mts" ] && config_mts
="$mts"
250 if [ "$config_mts" = smtp
]; then
251 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers >&3
253 servers
=`echo $response | sed -e 's/ /\\\ /g'`
254 [ "$servers" ] && config_smtpservers
="$servers"
257 printf 'Cyrus SASL support [%s]: ' $config_sasl >&3
259 [ "$response" = y
-o "$response" = Y
] && config_sasl
=y
261 printf 'TLS support [%s]: ' $config_tls >&3
263 [ "$response" = y
-o "$response" = Y
] && config_tls
=y
265 printf 'OAuth2 support [%s]: ' $config_oauth >&3
267 [ "$response" = y
-o "$response" = Y
] && config_oauth
=y
269 #### Don't confirm debug here: obey the -d option to this script.
273 config_opts
="--prefix=$config_prefix"
275 [ "$config_locking" ] &&
276 config_opts
="$config_opts --with-locking=$config_locking"
277 [ "$config_mts" -a "$config_mts" != smtp
] &&
278 config_opts
="$config_opts --with-mts=$config_mts"
279 [ "$config_smtpservers" -a "$config_smtpservers" != localhost
] &&
280 smtpservers
="--with-smtpservers=$config_smtpservers"
281 [ "$config_sasl" = y
] && config_opts
="$config_opts --with-cyrus-sasl"
282 [ "$config_tls" = y
] && config_opts
="$config_opts --with-tls"
283 [ "$config_oauth" = y
] && config_opts
="$config_opts --with-oauth"
284 [ $config_debug = y
] && config_opts
="$config_opts --enable-assert"
286 #### dotlocking, the usual default, requires chgrp and chmod of inc.
288 if [ $install -ge 1 -a "$LOGNAME" != root
]; then
289 if [ "$config_locking" = dot
]; then
290 echo "$0: "'install requires chgrp and chmod 2755'
291 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
296 [ -x tools
/showbuildenv
] && tools
/showbuildenv
| grep -Ev 'PID=|SHLVL'
300 #### Set up with autoconfig if necessary.
302 if [ -f Makefile
]; then
303 [ $verbose -ge 1 ] && echo cleaning . . .
>&3
304 if [ $superclean -ge 1 ]; then
305 make superclean
>/dev
/null
307 make distclean
>/dev
/null
311 if [ ! -f configure
-o ! -f Makefile.
in ]; then
312 [ $verbose -ge 1 ] && echo autoconfiguring . . .
>&3
315 die
"autogen failed, see MACHINES file for autoconf,
316 automake, flex, and bison requirements"
323 [ $verbose -ge 1 ] && echo configuring . . .
>&3
324 if [ -z "$CFLAGS" ]; then
325 #### Only use these flags with gcc.
326 if cc
-dM -E - </dev
/null
2>&1 | grep __GNUC__
>/dev
/null
; then
327 #### configure will supply -g -O2 with gcc, but only if CFLAGS
329 CFLAGS
='-g -O2 -ansi -pedantic'
333 printf '\n./configure %s\n' "$config_opts${smtpservers:+ $smtpservers}"
334 .
/configure CFLAGS
="${CFLAGS}" $config_opts${smtpservers:+" $smtpservers"}
337 if [ $status -eq 0 ]; then
338 [ $verbose -ge 1 ] && echo building . . .
>&3
342 if [ $status -eq 0 ]; then
343 if [ "$TESTS_SHELL"x
= x
]; then
344 #### Bonus: use heirloom shell to test, if available, and if
345 #### TESTS_SHELL hadn't already been set.
346 heirloom_shell
=/usr
/lib
/heirloom
/5bin
/sh
347 if [ -x "$heirloom_shell" ]; then
348 TESTS_SHELL
="$heirloom_shell"; export TESTS_SHELL
352 if [ "$CFLAGS" ]; then
353 #### Pass DISTCHECK_CONFIGURE_FLAGS through an environment
354 #### variable to avoid automake's quoting.
355 DISTCHECK_CONFIGURE_FLAGS
="CFLAGS='${CFLAGS}'"
356 export DISTCHECK_CONFIGURE_FLAGS
359 [ $verbose -ge 1 ] && echo testing . . .
>&3
360 checkoutput
=`make $check AM_COLOR_TESTS=always`
363 tests_summary
=`echo "$checkoutput" | grep tests`
364 #### If multiple tests not run, that line will be caught by the
365 #### "grep tests" above.
366 test_not_run
=`echo "$checkoutput" | grep 'test was not run'`
367 fails
=`echo "$checkoutput" | grep FAIL`
368 if [ "$tests_summary" ]; then
369 echo '==================='
370 [ "$test_not_run" ] && echo "$test_not_run"
371 [ "$fails" ] && echo "$fails"
372 echo "$tests_summary"
373 echo '==================='
374 [ "$check" = distcheck
] && echo "$checkoutput" | ${tail}4
377 if [ $status -eq 0 ]; then
378 if [ $install -ge 1 ]; then
379 [ $verbose -ge 1 ] && echo installing . . .
>&3
380 ($installpriv make install) >/dev
/null
384 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
385 [ $verbose -ge 1 ] && echo building rpm . . .
>&3
397 #### Disable output redirection (and flush) so that we can grep.
400 if [ "$logfile" != - ]; then
402 exec 3>&1 >"$logfile" 2>&1
406 grep -E 'Error|warn' "$tmpfile"
408 if [ $status -eq 0 ]; then
409 [ $verbose -ge 1 ] && echo build completed successfully
>&3
412 [ "$logfile" = - ] || echo "build failed, build log is in $logfile" >&3