]> git.notmuchmail.org Git - notmuch/blob - configure
a0746dfa6790fd70de361eb3e987558505096209
[notmuch] / configure
1 #! /bin/sh
2
3 # Set several defaults (optionally specified by the user in
4 # environemnt variables)
5 CC=${CC:-gcc}
6 CXX=${CXX:-g++}
7 CFLAGS=${CFLAGS:--O2}
8 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
9 XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config-1.1 xapian-config}
10
11 # We don't allow the EMACS or GZIP Makefile variables inherit values
12 # from the environment as we do with CC and CXX above. The reason is
13 # that these names as environment variables have existing uses other
14 # than the program name that we want. (EMACS is set to 't' when a
15 # shell is running within emacs and GZIP specifies arguments to pass
16 # on the gzip command line).
17
18 # Set the defaults for values the user can specify with command-line
19 # options.
20 PREFIX=/usr/local
21 LIBDIR=
22
23 usage ()
24 {
25     cat <<EOF
26 Usage: ./configure [options]...
27
28 This script configures notmuch to build on your system.
29
30 It verifies that dependencies are available, determines flags needed
31 to compile and link against various required libraries, and identifies
32 whether various system functions can be used or if locally-provided
33 replacements will be built instead.
34
35 Finally, it allows you to control various aspects of the build and
36 installation process.
37
38 First, some common variables can specified via environment variables:
39
40         CC              The C compiler to use
41         CFLAGS          Flags to pass to the C compiler
42         CXX             The C++ compiler to use
43         CXXFLAGS        Flags to pass to the C compiler
44         LDFLAGS         Flags to pass when linking
45
46 Each of these values can further be controlled by specifying them
47 later on the "make" command line.
48
49 Other environment variables can be used to control configure itself,
50 (and for which there is no equivalent build-time control):
51
52         XAPIAN_CONFIG   The program to use to determine flags for
53                         compiling and linking against the Xapian
54                         library. [$XAPIAN_CONFIG]
55
56 Additionally, various options can be specified on the configure
57 command line.
58
59         --prefix=PREFIX Install files in PREFIX [$PREFIX]
60
61 By default, "make install" will install the resulting program to
62 $PREFIX/bin, documentation to $PREFIX/man, etc. You can
63 specify an installation prefix other than $PREFIX using
64 --prefix, for instance:
65
66         ./configure --prefix=\$HOME
67
68 Fine tuning of some installation directories is available:
69
70         --libdir=DIR            Install libraries to DIR [PREFIX/lib]
71         --includedir=DIR        Install header files to DIR [PREFIX/include]
72
73 Additional options are accepted for compatibility with other
74 configure-script calling conventions, but don't do anything yet:
75
76         --build=<cpu>-<vendor>-<os>     Currently ignored
77
78 EOF
79 }
80
81 # Parse command-line options
82 for option; do
83     if [ "${option}" = '--help' ] ; then
84         usage
85         exit 0
86     elif [ "${option%%=*}" = '--prefix' ] ; then
87         PREFIX="${option#*=}"
88     elif [ "${option%%=*}" = '--libdir' ] ; then
89         LIBDIR="${option#*=}"
90     elif [ "${option%%=*}" = '--includedir' ] ; then
91         INCLUDEDIR="${option#*=}"
92     elif [ "${option%%=*}" = '--build' ] ; then
93         build_option="${option#*=}"
94         case ${build_option} in
95             *-*-*) ;;
96             *)
97                 echo "Unrecognized value for --build option: ${build_option}"
98                 echo "Should be: <cpu>-<vendor>-<os>"
99                 echo "See:"
100                 echo "  $0 --help"
101                 echo ""
102                 exit 1
103         esac
104         build_cpu=${build_option%%-*}
105         build_option=${build_option#*-}
106         build_vendor=${build_option%%-*}
107         build_os=${build_option#*-}
108     else
109         echo "Unrecognized option: ${option}"
110         echo "See:"
111         echo "  $0 --help"
112         echo ""
113         exit 1
114     fi
115 done
116
117 cat <<EOF
118 Welcome to Notmuch, a system for indexing, searching and tagging your email.
119
120 We hope that the process of building and installing notmuch is quick
121 and smooth so that you can soon be reading and processing your email
122 more efficiently than ever.
123
124 If anything goes wrong in the configure process, you can override any
125 decisions it makes by manually editing the Makefile.config file that
126 it creates. Also please do as much as you can to figure out what could
127 be different on your machine compared to those of the notmuch
128 developers. Then, please email those details to the Notmuch list
129 (notmuch@notmuchmail.org) so that we can hopefully make future
130 versions of notmuch easier for you to use.
131
132 We'll now investigate your system to verify that all required
133 dependencies are available:
134
135 EOF
136
137 errors=0
138
139 if pkg-config --version > /dev/null 2>&1; then
140     have_pkg_config=1
141 else
142     have_pkg_config=0
143 fi
144
145 printf "Checking for Xapian development files... "
146 have_xapian=0
147 for xapian_config in ${XAPIAN_CONFIG}; do
148     if ${xapian_config} --version > /dev/null 2>&1; then
149         printf "Yes.\n"
150         have_xapian=1
151         xapian_cxxflags=$(${xapian_config} --cxxflags)
152         xapian_ldflags=$(${xapian_config} --libs)
153         break
154     fi
155 done
156 if [ ${have_xapian} = "0" ]; then
157     printf "No.\n"
158     errors=$((errors + 1))
159 fi
160
161 printf "Checking for GMime 2.4 development files... "
162 if pkg-config --modversion gmime-2.4 > /dev/null 2>&1; then
163     printf "Yes.\n"
164     have_gmime=1
165     gmime_cflags=$(pkg-config --cflags gmime-2.4)
166     gmime_ldflags=$(pkg-config --libs gmime-2.4)
167 else
168     printf "No.\n"
169     have_gmime=0
170     errors=$((errors + 1))
171 fi
172
173 printf "Checking for talloc development files... "
174 if pkg-config --modversion talloc > /dev/null 2>&1; then
175     printf "Yes.\n"
176     have_talloc=1
177     talloc_cflags=$(pkg-config --cflags talloc)
178     talloc_ldflags=$(pkg-config --libs talloc)
179 else
180     printf "No.\n"
181     have_talloc=0
182     talloc_cflags=
183     errors=$((errors + 1))
184 fi
185
186 printf "Checking for valgrind development files... "
187 if pkg-config --modversion valgrind > /dev/null 2>&1; then
188     printf "Yes.\n"
189     have_valgrind=1
190     valgrind_cflags=$(pkg-config --cflags valgrind)
191 else
192     printf "No (but that's fine).\n"
193     have_valgrind=0
194 fi
195
196 if pkg-config --modversion emacs > /dev/null 2>&1; then
197     emacs_lispdir=$(pkg-config emacs --variable sitepkglispdir)
198 else
199     emacs_lispdir='$(prefix)/share/emacs/site-lisp'
200 fi
201
202 printf "Checking if emacs is available... "
203 if emacs --quick --batch > /dev/null 2>&1; then
204     printf "Yes.\n"
205     have_emacs=1
206 else
207     printf "No (so will not byte-compile emacs code)\n"
208     have_emacs=0
209 fi
210
211 if [ $errors -gt 0 ]; then
212     cat <<EOF
213
214 *** Error: The dependencies of notmuch could not be satisfied. You will
215 need to install the following packages before being able to compile
216 notmuch:
217
218 EOF
219     if [ $have_xapian -eq 0 ]; then
220         echo "  Xapian library (including development files such as headers)"
221         echo "  http://xapian.org/"
222     fi
223     if [ $have_gmime -eq 0 ]; then
224         echo "  GMime 2.4 library (including development files such as headers)"
225         echo "  http://spruce.sourceforge.net/gmime/"
226     fi
227     if [ $have_talloc -eq 0 ]; then
228         echo "  The talloc library (including development files such as headers)"
229         echo "  http://talloc.samba.org/"
230     fi
231     cat <<EOF
232
233 With any luck, you're using a modern, package-based operating system
234 that has all of these packages available in the distribution. In that
235 case a simple command will install everything you need. For example:
236
237 On Debian and similar systems:
238
239         sudo apt-get install libxapian-dev libgmime-2.4-dev libtalloc-dev
240
241 Or on Fedora and similar systems:
242
243         sudo yum install xapian-core-devel gmime-devel libtalloc-devel
244
245 On other systems, similar commands can be used, but the details of the
246 package names may be different.
247
248 EOF
249     if [ $have_pkg_config -eq 0 ]; then
250 cat <<EOF
251 Note: the pkg-config program is not available. This configure script
252 uses pkg-config to find the compilation flags required to link against
253 the various libraries needed by notmuch. It's possible you simply need
254 to install pkg-config with a command such as:
255
256         sudo apt-get install pkg-config
257 Or:
258         sudo yum install pkgconfig
259
260 But if pkg-config is not available for your system, then you will need
261 to modify the configure script to manually set the cflags and ldflags
262 variables to the correct values to link against each library in each
263 case that pkg-config could not be used to determine those values.
264
265 EOF
266     fi
267 cat <<EOF
268 When you have installed the necessary dependencies, you can run
269 configure again to ensure the packages can be found, or simply run
270 "make" to compile notmuch.
271
272 EOF
273     exit 1
274 fi
275
276 printf "Checking for getline... "
277 if ${CC} -o compat/have_getline compat/have_getline.c > /dev/null 2>&1
278 then
279     printf "Yes.\n"
280     have_getline=1
281 else
282     printf "No (will use our own instead).\n"
283     have_getline=0
284 fi
285 rm -f compat/have_getline
286
287 cat <<EOF
288
289 All required packages were found. You may now run the following
290 commands to compile and install notmuch:
291
292         make
293         sudo make install
294
295 EOF
296
297 # construct the Makefile.config
298 cat > Makefile.config <<EOF
299 # This Makefile.config was automatically generated by the ./configure
300 # script of notmuch. If the configure script identified anything
301 # incorrectly, then you can edit this file to try to correct things,
302 # but be warned that if configure is run again it will destroy your
303 # changes, (and this could happen by simply calling "make" if the
304 # configure script is updated).
305
306 # The C compiler to use
307 CC = ${CC}
308
309 # The C++ compiler to use
310 CXX = ${CXX}
311
312 # Command to execute emacs from Makefiles
313 EMACS = emacs --quick
314
315 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
316 CFLAGS = ${CFLAGS}
317
318 # Default FLAGS for C++ compiler (can be overridden by user such as "make CXXFLAGS=-g")
319 CXXFLAGS = ${CXXFLAGS}
320
321 # Flags to enable warnings when using the C++ compiler
322 WARN_CXXFLAGS=-Wall -Wextra -Wwrite-strings -Wswitch-enum
323
324 # Flags to enable warnings when using the C compiler
325 WARN_CFLAGS=\$(WARN_CXXFLAGS) -Wmissing-declarations
326
327 # The prefix to which notmuch should be installed
328 prefix = ${PREFIX}
329
330 # The directory to which libraries should be installed
331 libdir = ${LIBDIR:=\$(prefix)/lib}
332
333 # The directory to which header files should be installed
334 includedir = ${INCLUDEDIR:=\$(prefix)/lib}
335
336 # The directory to which emacs lisp files should be installed
337 emacs_lispdir=${emacs_lispdir}
338
339 # Whether there's an emacs binary available for byte-compiling
340 HAVE_EMACS = ${have_emacs}
341
342 # The directory to which desktop files should be installed
343 desktop_dir = \$(prefix)/share/applications
344
345 # The directory to which bash completions files should be installed
346 bash_completion_dir = /etc/bash_completion.d
347
348 # The directory to which zsh completions files should be installed
349 zsh_completion_dir = \$(prefix)/share/zsh/functions/Completion/Unix
350
351 # Whether the getline function is available (if not, then notmuch will
352 # build its own version)
353 HAVE_GETLINE = ${have_getline}
354
355 # Flags needed to compile and link against Xapian
356 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
357 XAPIAN_LDFLAGS = ${xapian_ldflags}
358
359 # Flags needed to compile and link against GMime-2.4
360 GMIME_CFLAGS = ${gmime_cflags}
361 GMIME_LDFLAGS = ${gmime_ldflags}
362
363 # Flags needed to compile and link against talloc
364 TALLOC_CFLAGS = ${talloc_cflags}
365 TALLOC_LDFLAGS = ${talloc_ldflags}
366
367 # Whether valgrind header files are available
368 HAVE_VALGRIND = ${have_valgrind}
369
370 # And if so, flags needed at compile time for valgrind macros
371 VALGRIND_CFLAGS = ${valgrind_cflags}
372
373 # Combined flags for compiling and linking against all of the above
374 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
375                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
376                    \$(VALGRIND_CFLAGS)
377 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
378                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
379                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)
380 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
381 EOF