]> git.notmuchmail.org Git - notmuch/blob - configure
f69cd9259c531c53efac5893ae878bfcea4cbee2
[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         --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
73         --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
74         --emacslispdir=DIR      Emacs code [PREFIX/share/emacs/site-lisp]
75
76 Additional options are accepted for compatibility with other
77 configure-script calling conventions, but don't do anything yet:
78
79         --build=<cpu>-<vendor>-<os>     Currently ignored
80         --infodir=DIR                   Currently ignored
81         --localstatedir=DIR             Currently ignored
82         --libexecdir=DIR                Currently ignored
83         --disable-maintainer-mode       Currently ignored
84         --disable-dependency-tracking   Currently ignored
85
86 EOF
87 }
88
89 # Parse command-line options
90 for option; do
91     if [ "${option}" = '--help' ] ; then
92         usage
93         exit 0
94     elif [ "${option%%=*}" = '--prefix' ] ; then
95         PREFIX="${option#*=}"
96     elif [ "${option%%=*}" = '--libdir' ] ; then
97         LIBDIR="${option#*=}"
98     elif [ "${option%%=*}" = '--includedir' ] ; then
99         INCLUDEDIR="${option#*=}"
100     elif [ "${option%%=*}" = '--mandir' ] ; then
101         MANDIR="${option#*=}"
102     elif [ "${option%%=*}" = '--sysconfdir' ] ; then
103         SYSCONFDIR="${option#*=}"
104     elif [ "${option%%=*}" = '--emacslispdir' ] ; then
105         EMACSLISPDIR="${option#*=}"
106     elif [ "${option%%=*}" = '--build' ] ; then
107         build_option="${option#*=}"
108         case ${build_option} in
109             *-*-*) ;;
110             *)
111                 echo "Unrecognized value for --build option: ${build_option}"
112                 echo "Should be: <cpu>-<vendor>-<os>"
113                 echo "See:"
114                 echo "  $0 --help"
115                 echo ""
116                 exit 1
117         esac
118         build_cpu=${build_option%%-*}
119         build_option=${build_option#*-}
120         build_vendor=${build_option%%-*}
121         build_os=${build_option#*-}
122     elif [ "${option%%=*}" = '--infodir' ] ; then
123         true
124     elif [ "${option%%=*}" = '--localstatedir' ] ; then
125         true
126     elif [ "${option%%=*}" = '--libexecdir' ] ; then
127         true
128     elif [ "${option}" = '--disable-maintainer-mode' ] ; then
129         true
130     elif [ "${option}" = '--disable-dependency-tracking' ] ; then
131         true
132     else
133         echo "Unrecognized option: ${option}"
134         echo "See:"
135         echo "  $0 --help"
136         echo ""
137         exit 1
138     fi
139 done
140
141 cat <<EOF
142 Welcome to Notmuch, a system for indexing, searching and tagging your email.
143
144 We hope that the process of building and installing notmuch is quick
145 and smooth so that you can soon be reading and processing your email
146 more efficiently than ever.
147
148 If anything goes wrong in the configure process, you can override any
149 decisions it makes by manually editing the Makefile.config file that
150 it creates. Also please do as much as you can to figure out what could
151 be different on your machine compared to those of the notmuch
152 developers. Then, please email those details to the Notmuch list
153 (notmuch@notmuchmail.org) so that we can hopefully make future
154 versions of notmuch easier for you to use.
155
156 We'll now investigate your system to verify that all required
157 dependencies are available:
158
159 EOF
160
161 errors=0
162
163 if pkg-config --version > /dev/null 2>&1; then
164     have_pkg_config=1
165 else
166     have_pkg_config=0
167 fi
168
169 printf "Checking for Xapian development files... "
170 have_xapian=0
171 for xapian_config in ${XAPIAN_CONFIG}; do
172     if ${xapian_config} --version > /dev/null 2>&1; then
173         printf "Yes.\n"
174         have_xapian=1
175         xapian_cxxflags=$(${xapian_config} --cxxflags)
176         xapian_ldflags=$(${xapian_config} --libs)
177         break
178     fi
179 done
180 if [ ${have_xapian} = "0" ]; then
181     printf "No.\n"
182     errors=$((errors + 1))
183 fi
184
185 printf "Checking for GMime 2.4 development files... "
186 if pkg-config --modversion gmime-2.4 > /dev/null 2>&1; then
187     printf "Yes.\n"
188     have_gmime=1
189     gmime_cflags=$(pkg-config --cflags gmime-2.4)
190     gmime_ldflags=$(pkg-config --libs gmime-2.4)
191 elif pkg-config --modversion gmime-2.6 > /dev/null 2>&1; then
192     printf "Yes.\n"
193     have_gmime=1
194     gmime_cflags=$(pkg-config --cflags gmime-2.6)
195     gmime_ldflags=$(pkg-config --libs gmime-2.6)
196 else
197     printf "No.\n"
198     have_gmime=0
199     errors=$((errors + 1))
200 fi
201
202 printf "Checking for talloc development files... "
203 if pkg-config --modversion talloc > /dev/null 2>&1; then
204     printf "Yes.\n"
205     have_talloc=1
206     talloc_cflags=$(pkg-config --cflags talloc)
207     talloc_ldflags=$(pkg-config --libs talloc)
208 else
209     printf "No.\n"
210     have_talloc=0
211     talloc_cflags=
212     errors=$((errors + 1))
213 fi
214
215 printf "Checking for valgrind development files... "
216 if pkg-config --modversion valgrind > /dev/null 2>&1; then
217     printf "Yes.\n"
218     have_valgrind=1
219     valgrind_cflags=$(pkg-config --cflags valgrind)
220 else
221     printf "No (but that's fine).\n"
222     have_valgrind=0
223 fi
224
225 if [ -z "${EMACSLISPDIR}" ]; then
226     if pkg-config --modversion emacs > /dev/null 2>&1; then
227         EMACSLISPDIR=$(pkg-config emacs --variable sitepkglispdir)
228     else
229         EMACSLISPDIR='$(prefix)/share/emacs/site-lisp'
230     fi
231 fi
232
233 printf "Checking if emacs is available... "
234 if emacs --quick --batch > /dev/null 2>&1; then
235     printf "Yes.\n"
236     have_emacs=1
237 else
238     printf "No (so will not byte-compile emacs code)\n"
239     have_emacs=0
240 fi
241
242 printf "Checking for Mac OS X (for shared library)... "
243 if [ `uname` = "Darwin" ] ; then
244     printf "Yes.\n"
245     mac_os_x=1
246     linker_resolves_library_dependencies=0
247 else
248     printf "No.\n"
249     mac_os_x=0
250     linker_resolves_library_dependencies=1
251 fi
252
253 if [ $errors -gt 0 ]; then
254     cat <<EOF
255
256 *** Error: The dependencies of notmuch could not be satisfied. You will
257 need to install the following packages before being able to compile
258 notmuch:
259
260 EOF
261     if [ $have_xapian -eq 0 ]; then
262         echo "  Xapian library (including development files such as headers)"
263         echo "  http://xapian.org/"
264     fi
265     if [ $have_gmime -eq 0 ]; then
266         echo "  GMime 2.4 library (including development files such as headers)"
267         echo "  http://spruce.sourceforge.net/gmime/"
268     fi
269     if [ $have_talloc -eq 0 ]; then
270         echo "  The talloc library (including development files such as headers)"
271         echo "  http://talloc.samba.org/"
272     fi
273     cat <<EOF
274
275 With any luck, you're using a modern, package-based operating system
276 that has all of these packages available in the distribution. In that
277 case a simple command will install everything you need. For example:
278
279 On Debian and similar systems:
280
281         sudo apt-get install libxapian-dev libgmime-2.4-dev libtalloc-dev
282
283 Or on Fedora and similar systems:
284
285         sudo yum install xapian-core-devel gmime-devel libtalloc-devel
286
287 On other systems, similar commands can be used, but the details of the
288 package names may be different.
289
290 EOF
291     if [ $have_pkg_config -eq 0 ]; then
292 cat <<EOF
293 Note: the pkg-config program is not available. This configure script
294 uses pkg-config to find the compilation flags required to link against
295 the various libraries needed by notmuch. It's possible you simply need
296 to install pkg-config with a command such as:
297
298         sudo apt-get install pkg-config
299 Or:
300         sudo yum install pkgconfig
301
302 But if pkg-config is not available for your system, then you will need
303 to modify the configure script to manually set the cflags and ldflags
304 variables to the correct values to link against each library in each
305 case that pkg-config could not be used to determine those values.
306
307 EOF
308     fi
309 cat <<EOF
310 When you have installed the necessary dependencies, you can run
311 configure again to ensure the packages can be found, or simply run
312 "make" to compile notmuch.
313
314 EOF
315     exit 1
316 fi
317
318 printf "Checking for getline... "
319 if ${CC} -o compat/have_getline compat/have_getline.c > /dev/null 2>&1
320 then
321     printf "Yes.\n"
322     have_getline=1
323 else
324     printf "No (will use our own instead).\n"
325     have_getline=0
326 fi
327 rm -f compat/have_getline
328
329 printf "Checking for strcasestr... "
330 if ${CC} -o compat/have_strcasestr compat/have_strcasestr.c > /dev/null 2>&1
331 then
332     printf "Yes.\n"
333     have_strcasestr=1
334 else
335     printf "No (will use our own instead).\n"
336     have_strcasestr=0
337 fi
338 rm -f compat/have_strcasestr
339
340 cat <<EOF
341
342 All required packages were found. You may now run the following
343 commands to compile and install notmuch:
344
345         make
346         sudo make install
347
348 EOF
349
350 # construct the Makefile.config
351 cat > Makefile.config <<EOF
352 # This Makefile.config was automatically generated by the ./configure
353 # script of notmuch. If the configure script identified anything
354 # incorrectly, then you can edit this file to try to correct things,
355 # but be warned that if configure is run again it will destroy your
356 # changes, (and this could happen by simply calling "make" if the
357 # configure script is updated).
358
359 # The C compiler to use
360 CC = ${CC}
361
362 # The C++ compiler to use
363 CXX = ${CXX}
364
365 # Command to execute emacs from Makefiles
366 EMACS = emacs --quick
367
368 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
369 CFLAGS = ${CFLAGS}
370
371 # Default FLAGS for C++ compiler (can be overridden by user such as "make CXXFLAGS=-g")
372 CXXFLAGS = ${CXXFLAGS}
373
374 # Flags to enable warnings when using the C++ compiler
375 WARN_CXXFLAGS=-Wall -Wextra -Wwrite-strings -Wswitch-enum
376
377 # Flags to enable warnings when using the C compiler
378 WARN_CFLAGS=\$(WARN_CXXFLAGS) -Wmissing-declarations
379
380 # The prefix to which notmuch should be installed
381 prefix = ${PREFIX}
382
383 # The directory to which libraries should be installed
384 libdir = ${LIBDIR:=\$(prefix)/lib}
385
386 # The directory to which header files should be installed
387 includedir = ${INCLUDEDIR:=\$(prefix)/include}
388
389 # The directory to which man pages should be installed
390 mandir = ${MANDIR:=\$(prefix)/share/man}
391
392 # The directory to which read-only (configuration) filesshould be installed
393 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
394
395 # The directory to which emacs lisp files should be installed
396 emacslispdir=${EMACSLISPDIR}
397
398 # Whether there's an emacs binary available for byte-compiling
399 HAVE_EMACS = ${have_emacs}
400
401 # The directory to which desktop files should be installed
402 desktop_dir = \$(prefix)/share/applications
403
404 # The directory to which bash completions files should be installed
405 bash_completion_dir = \$(sysconfdir)/bash_completion.d
406
407 # The directory to which zsh completions files should be installed
408 zsh_completion_dir = \$(prefix)/share/zsh/functions/Completion/Unix
409
410 # Whether the getline function is available (if not, then notmuch will
411 # build its own version)
412 HAVE_GETLINE = ${have_getline}
413
414 # Whether the strcasestr function is available (if not, then notmuch will
415 # build its own version)
416 HAVE_STRCASESTR = ${have_strcasestr}
417
418 # Whether we are building on OS X.  This will affect how we build the
419 # shared library.
420 MAC_OS_X = ${mac_os_x}
421
422 # Whether the linker will automatically resolve the dependency of one
423 # library on another (if not, then linking a binary requires linking
424 # directly against both)
425 LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}
426
427 # Flags needed to compile and link against Xapian
428 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
429 XAPIAN_LDFLAGS = ${xapian_ldflags}
430
431 # Flags needed to compile and link against GMime-2.4
432 GMIME_CFLAGS = ${gmime_cflags}
433 GMIME_LDFLAGS = ${gmime_ldflags}
434
435 # Flags needed to compile and link against talloc
436 TALLOC_CFLAGS = ${talloc_cflags}
437 TALLOC_LDFLAGS = ${talloc_ldflags}
438
439 # Whether valgrind header files are available
440 HAVE_VALGRIND = ${have_valgrind}
441
442 # And if so, flags needed at compile time for valgrind macros
443 VALGRIND_CFLAGS = ${valgrind_cflags}
444
445 # Combined flags for compiling and linking against all of the above
446 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
447                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
448                    \$(VALGRIND_CFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
449 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
450                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
451                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\
452                      -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
453 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
454 EOF