]> diplodocus.org Git - nmh/blob - docs/contrib/build_nmh
Wrap local part (username) of address with double quotes if needed.
[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, as well as any $EDITOR/$VISUAL
7 # and $PAGER environment variable settings.
8 # * Unless the -y option is provided, this script then interactively
9 # walks you through confirmation of common configuration settings.
10 #
11 # Typical usage:
12 # The first time you invoke this script, use the -i option to install
13 # nmh in the specified location. The script will walk you through the
14 # common nmh configuration settings. The -v option will cause display
15 # of brief progress indicators. Be sure to add the bin directory of
16 # the install location to your $PATH, if not already there.
17 # Subsequently, invoke this script with the -y option, to use the
18 # relevant configuration settings from the installed nmh without
19 # confirmation.
20 #
21 # Option summary:
22 # First time use:
23 # -i to install nmh
24 # -v to display progress
25 # Subsequent uses, assuming installed nmh bin directory is on $PATH:
26 # -y to accept all configuration options without confirmation
27 # Output control:
28 # -l <logfile name>, default 'build_nmh.log'
29 # Advanced/developer use:
30 # -c to run 'make distcheck' instead of 'make check'
31 # -d to build nmh with debug enabled
32 # -s to use 'make superclean': requires recent autoconf and automake,
33 # see docs/README.developers
34 # -r to build rpm
35 #
36 # On Fedora, at least these rpms must be installed:
37 # gdbm-devel
38 # ncurses-devel
39 # cyrus-sasl-devel, if using sasl
40 # openssl-devel, if using TLS
41 # autoconf and automake, with -s (see docs/README.developers for versions)
42 # rpm-build, with -r
43
44
45 ####
46 #### OS-specific setup.
47 ####
48 which=which
49 ldd=ldd
50
51 ####
52 #### Interpret command arguments.
53 ####
54 check=check
55 debug=0
56 install=0
57 logfile=build_nmh.log
58 build_rpm=0
59 superclean=0
60 verbose=0
61 yes=0
62 usage="usage: $0
63 [-c to run 'make distcheck' instead of 'make check']
64 [-d to build nmh with debug enabled]
65 [-i to install nmh]
66 [-l <logfile name>, default '$logfile']
67 [-r to build rpm]
68 [-s to use 'make superclean': requires recent autoconf and automake]
69 [-v to display progress]
70 [-y to accept all configuration options without confirmation]"
71
72 while getopts 'cdil:rsvy?' arg; do
73 case $arg in
74 c ) check=distcheck ;;
75 d ) debug=1 ;;
76 i ) install=1 ;;
77 l ) logfile=$OPTARG ;;
78 r ) build_rpm=1 ;;
79 s ) superclean=1 ;;
80 v ) verbose=1 ;;
81 y ) yes=1 ;;
82 '?') echo "$usage"; exit 0 ;;
83 esac
84 done
85 shift `expr $OPTIND - 1`
86
87 #### No command line arguments are supported.
88 if [ $# -gt 0 ]; then
89 echo "usage: $0"
90 exit 1
91 fi
92
93 #### Check to see that we're in a nmh source directory.
94 if grep 'the authors of nmh' COPYRIGHT >/dev/null; then
95 :
96 else
97 echo "$0: not in nmh source directory"
98 exit 1
99 fi
100
101 ####
102 #### Set up configure options. Handle options that can have embedded
103 #### spaces (currently just smtpservers) specially.
104 ####
105
106 #### Here are the config options that we will try to detect, then
107 #### confirm, and finally set.
108 config_prefix=/usr/local/nmh
109 config_mts=smtp
110 config_smtpservers=localhost
111 config_sasl=n
112 config_tls=n
113 config_editor=vi
114 for i in more less most cat; do
115 if which $i >/dev/null 2>&1; then
116 config_pager=$i
117 break
118 fi
119 done
120 config_debug=n
121
122 if install-mh -check >/dev/null 2>&1; then
123 # Determine config options from installed nmh.
124 mhparam=`which mhparam`
125 mhbin=`dirname "$mhparam"`
126
127 config_prefix=`cd $mhbin/.. && pwd`
128
129 mtsconf=`dirname "$mhbin"`/etc/mts.conf
130 if [ -f "$mtsconf" ]; then
131 mts_entry=`grep '^mts:' $mtsconf`
132 if [ "mts_entry" ]; then
133 mts=`echo $mts_entry | sed -e 's/^mts: *//'`
134 if [ "$mts" -a "$mts" != smtp ]; then
135 config_mts="$mts"
136 fi
137 fi
138
139 mtsconfservers=`grep '^servers:' $mtsconf`
140 if [ "$mtsconfservers" ]; then
141 servers=`echo $mtsconfservers | sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
142 [ "$servers" ] && config_smtpservers="$servers"
143 fi
144 fi
145
146 if $ldd $mhbin/inc | grep sasl >/dev/null; then
147 config_sasl=y
148 fi
149
150 if $ldd $mhbin/inc | grep ssl >/dev/null; then
151 config_tls=y
152 fi
153 fi
154
155 if [ "$EDITOR" ]; then
156 config_editor="$EDITOR"
157 elif [ "$VISUAL" ]; then
158 config_editor="$VISUAL"
159 fi
160
161 [ "$PAGER" ] && config_pager="$PAGER"
162
163 [ $debug -ge 1 ] && config_debug=y
164
165 if [ $yes -eq 0 ]; then
166 #### Confirm each config setting with user.
167 printf 'Install prefix [%s]: ' $config_prefix
168 read prefix
169 [ "$prefix" ] && config_prefix="$prefix"
170
171 printf 'MTS (smtp|sendmail) [%s]: ' $config_mts
172 read mts
173 [ "$mts" ] && config_mts="$mts"
174
175 if [ "$mts" -o "$mts" = smtp ]; then
176 :
177 else
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 printf 'Default editor [%s]: ' $config_editor
201 read editor
202 [ "$editor" ] && config_editor=$editor
203
204 printf 'Pager [%s]: ' $config_pager
205 read pager
206 [ "$pager" ] && config_pager=$pager
207
208 #### Don't confirm debug here: obey the -d option to this script.
209 fi
210
211 smtpservers=
212 config_opts="--prefix=$config_prefix"
213
214 [ "$config_mts" -a "$config_mts" != smtp ] && \
215 config_opts="$config_opts --with-mts=$config_mts"
216 [ "$config_smtpservers" -a "$config_smtpservers" != localhost ] && \
217 smtpservers="--with-smtpservers=$config_smtpservers"
218 [ "$config_sasl" = y ] && \
219 config_opts="$config_opts --with-cyrus-sasl"
220 [ "$config_tls" = y ] && \
221 config_opts="$config_opts --with-tls"
222 [ "$config_editor" ] && \
223 config_opts="$config_opts --with-editor=$config_editor"
224 [ "$config_pager" ] && \
225 config_opts="$config_opts --with-pager=$config_pager"
226 [ $config_debug = y ] && \
227 config_opts="$config_opts --enable-debug"
228
229
230 ####
231 #### Clean up, and set up with autoconfig if necessary.
232 ####
233 if [ -f Makefile ]; then
234 [ $verbose -ge 1 ] && echo cleaning . . .
235 if [ $superclean -ge 1 ]; then
236 make superclean >/dev/null
237 else
238 make distclean >/dev/null
239 fi
240 fi
241
242 /bin/rm -f $logfile
243 if [ -f configure -a -f Makefile.in ]; then
244 :
245 else
246 [ $verbose -ge 1 ] && echo autoconfiguring . . .
247 ./autogen.sh >>$logfile 2>&1
248 fi
249
250
251 ####
252 #### Build.
253 ####
254 [ $verbose -ge 1 ] && echo configuring . . .
255 echo ./configure $config_opts ${smtpservers:+"$smtpservers"} >>$logfile 2>&1
256 ./configure $config_opts ${smtpservers:+"$smtpservers"} >>$logfile 2>&1
257 status=$?
258
259 if [ $status -eq 0 ]; then
260 [ $verbose -ge 1 ] && echo building . . .
261 make >>$logfile 2>&1
262 status=$?
263
264 if [ $status -eq 0 ]; then
265 [ $verbose -ge 1 ] && echo testing . . .
266 checkoutput=`make $check 2>>$logfile`
267 status=$?
268
269 tests_summary=`echo "$checkoutput" | grep tests`
270 if [ "$tests_summary" ]; then
271 echo '===================' >>$logfile
272 echo $tests_summary >>$logfile
273 echo '===================' >>$logfile
274 [ "$check" = distcheck ] && \
275 echo "$checkoutput" | tail -n 4 >>$logfile
276 fi
277
278 if [ $status -eq 0 ]; then
279 if [ $install -ge 1 ]; then
280 [ $verbose -ge 1 ] && echo installing . . .
281 (make install) >/dev/null 2>>$logfile
282 status=$?
283 fi
284
285 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
286 [ $verbose -ge 1 ] && echo building rpm . . .
287 make rpm >/dev/null 2>>$logfile
288 status=$?
289 fi
290 fi
291 fi
292 fi
293
294 grep 'Error' $logfile
295 grep 'warn' $logfile
296 [ $status -ne 0 ] && echo build failed!
297 [ $status -eq 0 -a $verbose -ge 1 ] && echo build completed successfully
298
299 exit $status