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