]> diplodocus.org Git - nmh/blob - docs/contrib/build_nmh
Prevent crash if editfile() is called and both "*ed" and editsave
[nmh] / docs / contrib / build_nmh
1 #! /bin/sh
2 #
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.
9 #
10 # Typical usage:
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
18 # confirmation.
19 #
20 # Option summary:
21 # First time use:
22 # -i to install nmh
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
26 # Output control:
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
33 # -r to build rpm
34 #
35 # On Fedora, at least these rpms must be installed:
36 # gdbm-devel
37 # ncurses-devel
38 # cyrus-sasl-devel, if using sasl
39 # openssl-devel, if using TLS
40 # autoconf and automake, with -s (see docs/README.developers for versions)
41 # rpm-build, with -r
42
43
44 ####
45 #### Interpret command arguments.
46 ####
47 check=check
48 debug=0
49 install=0
50 logfile=build_nmh.log
51 build_rpm=0
52 superclean=0
53 verbose=0
54 yes=0
55 usage="usage: $0
56 [-c to run 'make distcheck' instead of 'make check']
57 [-d to build nmh with debug enabled]
58 [-i to install nmh]
59 [-l <logfile name>, default '$logfile']
60 [-r to build rpm]
61 [-s to use 'make superclean': requires recent autoconf and automake]
62 [-v to display progress]
63 [-y to accept all configuration options without confirmation]"
64
65 while getopts 'cdil:rsvy?' arg; do
66 case $arg in
67 c ) check=distcheck ;;
68 d ) debug=1 ;;
69 i ) install=1 ;;
70 l ) logfile=$OPTARG ;;
71 r ) build_rpm=1 ;;
72 s ) superclean=1 ;;
73 v ) verbose=1 ;;
74 y ) yes=1 ;;
75 '?') echo "$usage"; exit 0 ;;
76 esac
77 done
78 shift `expr $OPTIND - 1`
79
80 #### No command line arguments are supported.
81 if [ $# -gt 0 ]; then
82 echo "usage: $0"
83 exit 1
84 fi
85
86 #### Check to see that we're in a nmh source directory.
87 if grep 'the authors of nmh' COPYRIGHT >/dev/null; then
88 :
89 else
90 echo "$0: not in nmh source directory"
91 exit 1
92 fi
93
94 ####
95 #### Set up configure options. Handle options that can have embedded
96 #### spaces (currently just smtpservers) specially.
97 ####
98
99 #### Here are the config options that we will try to detect, then
100 #### confirm, and finally set.
101 config_prefix=/usr/local/nmh
102 config_locking=
103 config_mts=smtp
104 config_smtpservers=localhost
105 config_sasl=n
106 config_tls=n
107 config_debug=n
108
109
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.
112 finddir() {
113 case $1 in
114 */*) dirname "$1" ;;
115 * ) IFS=:
116 for d in $PATH; do
117 [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s "$d" && break
118 done ;;
119 esac
120 }
121
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 ' ;;
125 *) tail='tail -' ;;
126 esac
127
128 if install-mh -check >/dev/null 2>&1; then
129 # Determine config options from installed nmh.
130 mhbin=`finddir install-mh`
131
132 config_prefix=`cd $mhbin/.. && pwd`
133
134 mtsconf=`dirname "$mhbin"`/etc/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
140 config_mts="$mts"
141 fi
142 fi
143
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"
149 fi
150 fi
151
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 ;;
156 esac
157
158 case `$mhbin/mhparam tls` in
159 *tls*) config_tls=y ;;
160 esac
161 else
162 tput smso
163 echo "$0: SASL and TLS detection not supported with current nmh"
164 [ $yes -eq 1 ] && echo "will not configure either one in"
165 tput rmso
166 fi
167 fi
168 fi
169
170 [ $debug -ge 1 ] && config_debug=y
171
172 if [ $yes -eq 0 ]; then
173 #### Confirm each config setting with user.
174 printf 'Install prefix [%s]: ' $config_prefix
175 read prefix
176 [ "$prefix" ] && config_prefix="$prefix"
177
178 printf 'Locking type (dot|fcntl|flock|lockf) [determined by configure]: '
179 read locking
180 [ "$locking" ] && config_locking="$locking"
181
182 printf 'MTS (smtp|sendmail/smtp|sendmail/pipe) [%s]: ' $config_mts
183 read mts
184 [ "$mts" ] && config_mts="$mts"
185
186 if [ "$config_mts" = smtp ]; then
187 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers
188 read response
189 servers=`echo $response | sed -e 's/ /\\\ /g'`
190 [ "$servers" ] && config_smtpservers="$servers"
191 fi
192
193 printf 'Cyrus SASL support [%s]: ' $config_sasl
194 read response
195 if [ "$response" = y -o "$response" = Y ]; then
196 config_sasl=y
197 elif [ "$response" = n -o "$response" = N ]; then
198 config_sasl=n
199 fi
200
201 printf 'TLS support [%s]: ' $config_tls
202 read response
203 if [ "$response" = y -o "$response" = Y ]; then
204 config_tls=y
205 elif [ "$response" = n -o "$response" = N ]; then
206 config_tls=n
207 fi
208
209 #### Don't confirm debug here: obey the -d option to this script.
210 fi
211
212 smtpservers=
213 config_opts="--prefix=$config_prefix"
214
215 [ "$config_locking" ] && \
216 config_opts="$config_opts --with-locking=$config_locking"
217 [ "$config_mts" -a "$config_mts" != smtp ] && \
218 config_opts="$config_opts --with-mts=$config_mts"
219 [ "$config_smtpservers" -a "$config_smtpservers" != localhost ] && \
220 smtpservers="--with-smtpservers=$config_smtpservers"
221 [ "$config_sasl" = y ] && \
222 config_opts="$config_opts --with-cyrus-sasl"
223 [ "$config_tls" = y ] && \
224 config_opts="$config_opts --with-tls"
225 [ $config_debug = y ] && \
226 config_opts="$config_opts --enable-debug --enable-assert"
227
228
229 #### dotlocking, the usual default, requires chgrp and chmod of inc.
230 installpriv=
231 if [ $install -ge 1 -a `id -u` -ne 0 ]; then
232 if [ "$config_locking" = dot ]; then
233 echo "$0: "'install requires chgrp and chmod 2755'
234 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
235 installpriv=sudo
236 fi
237 fi
238
239
240 ####
241 #### Clean up, and set up with autoconfig if necessary.
242 ####
243 if [ -f Makefile ]; then
244 [ $verbose -ge 1 ] && echo cleaning . . .
245 if [ $superclean -ge 1 ]; then
246 make superclean >/dev/null
247 else
248 make distclean >/dev/null
249 fi
250 fi
251
252 /bin/rm -f "$logfile"
253 if [ -f configure -a -f Makefile.in ]; then
254 :
255 else
256 [ $verbose -ge 1 ] && echo autoconfiguring . . .
257 ./autogen.sh >>"$logfile" 2>&1
258 fi
259
260
261 ####
262 #### Build.
263 ####
264 [ $verbose -ge 1 ] && echo configuring . . .
265 echo ./configure $config_opts ${smtpservers:+"$smtpservers"} >>"$logfile" 2>&1
266 ./configure $config_opts ${smtpservers:+"$smtpservers"} >>"$logfile" 2>&1
267 status=$?
268
269 if [ $status -eq 0 ]; then
270 [ $verbose -ge 1 ] && echo building . . .
271 make >>"$logfile" 2>&1
272 status=$?
273
274 if [ $status -eq 0 ]; then
275 if [ "$TESTS_SHELL"x = x ]; then
276 #### Bonus: use heirloom shell to test, if available, and if
277 #### TESTS_SHELL hadn't already been set.
278 heirloom_shell=/usr/lib/heirloom/5bin/sh
279 if [ -x "$heirloom_shell" ]; then
280 TESTS_SHELL="$heirloom_shell"; export TESTS_SHELL
281 fi
282 fi
283
284 [ $verbose -ge 1 ] && echo testing . . .
285 checkoutput=`make $check AM_COLOR_TESTS=always 2>>"$logfile"`
286 status=$?
287
288 tests_summary=`echo "$checkoutput" | grep tests`
289 #### If multiple tests not run, that line will be caught by the
290 #### "grep tests" above.
291 test_not_run=`echo "$checkoutput" | grep 'test was not run'`
292 fails=`echo "$checkoutput" | grep FAIL`
293 if [ "$tests_summary" ]; then
294 echo '===================' >>"$logfile"
295 [ "$test_not_run" ] && echo "$test_not_run" >>"$logfile"
296 [ "$fails" ] && echo "$fails" >>"$logfile"
297 echo "$tests_summary" >>"$logfile"
298 echo '===================' >>"$logfile"
299 [ "$check" = distcheck ] && \
300 echo "$checkoutput" | ${tail}4 >>"$logfile"
301 fi
302
303 if [ $status -eq 0 ]; then
304 if [ $install -ge 1 ]; then
305 [ $verbose -ge 1 ] && echo installing . . .
306 ($installpriv make install) >/dev/null 2>>"$logfile"
307 status=$?
308 fi
309
310 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
311 [ $verbose -ge 1 ] && echo building rpm . . .
312 make rpm >/dev/null 2>>"$logfile"
313 status=$?
314 fi
315 fi
316 fi
317 fi
318
319 grep Error "$logfile"
320 grep warn "$logfile"
321
322 if [ $status -eq 0 ]; then
323 [ $verbose -ge 1 ] && echo build completed successfully
324 else
325 echo build failed!
326 echo build log is in "$logfile"
327 fi
328
329 exit $status