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