]> git.notmuchmail.org Git - notmuch/blob - configure
c7ec4145afb37518d2d2155911f86ef61effece2
[notmuch] / configure
1 #! /bin/sh
2
3 # Removing space from IFS makes it much easier to support filenames
4 # with spaces. See http://www.dwheeler.com/essays/filenames-in-shell.html
5 # for gory details.
6 IFS="$(printf '\n\t')"
7
8 # Since we don't have space in IFS we use tab to separate things in lists
9 tab="$(printf '\t')"
10
11 # Set several defaults (optionally specified by the user in
12 # environemnt variables)
13 CC=${CC:-gcc}
14 CXX=${CXX:-g++}
15 CFLAGS=${CFLAGS:--O2}
16 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
17 LDFLAGS=${LDFLAGS:-}
18 XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}
19
20 # We don't allow the EMACS or GZIP Makefile variables inherit values
21 # from the environment as we do with CC and CXX above. The reason is
22 # that these names as environment variables have existing uses other
23 # than the program name that we want. (EMACS is set to 't' when a
24 # shell is running within emacs and GZIP specifies arguments to pass
25 # on the gzip command line).
26
27 # Set the defaults for values the user can specify with command-line
28 # options.
29 PREFIX=/usr/local
30 LIBDIR=
31 WITH_EMACS=1
32 WITH_BASH=1
33 WITH_ZSH=1
34
35 usage ()
36 {
37     cat <<EOF
38 Usage: ./configure [options]...
39
40 This script configures notmuch to build on your system.
41
42 It verifies that dependencies are available, determines flags needed
43 to compile and link against various required libraries, and identifies
44 whether various system functions can be used or if locally-provided
45 replacements will be built instead.
46
47 Finally, it allows you to control various aspects of the build and
48 installation process.
49
50 First, some common variables can specified via environment variables:
51
52         CC              The C compiler to use
53         CFLAGS          Flags to pass to the C compiler
54         CXX             The C++ compiler to use
55         CXXFLAGS        Flags to pass to the C compiler
56         LDFLAGS         Flags to pass when linking
57
58 Each of these values can further be controlled by specifying them
59 later on the "make" command line.
60
61 Other environment variables can be used to control configure itself,
62 (and for which there is no equivalent build-time control):
63
64         XAPIAN_CONFIG   The program to use to determine flags for
65                         compiling and linking against the Xapian
66                         library. [$XAPIAN_CONFIG]
67
68 Additionally, various options can be specified on the configure
69 command line.
70
71         --prefix=PREFIX Install files in PREFIX [$PREFIX]
72
73 By default, "make install" will install the resulting program to
74 $PREFIX/bin, documentation to $PREFIX/man, etc. You can
75 specify an installation prefix other than $PREFIX using
76 --prefix, for instance:
77
78         ./configure --prefix=\$HOME
79
80 Fine tuning of some installation directories is available:
81
82         --libdir=DIR            Install libraries to DIR [PREFIX/lib]
83         --includedir=DIR        Install header files to DIR [PREFIX/include]
84         --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
85         --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
86         --emacslispdir=DIR      Emacs code [PREFIX/share/emacs/site-lisp]
87         --bashcompletiondir=DIR Bash completions files [SYSCONFDIR/bash_completion.d]
88         --zshcompletiondir=DIR  Zsh completions files [PREFIX/share/zsh/functions/Completion/Unix]
89
90 Some features can be disabled (--with-feature=no is equivalent to
91 --without-feature) :
92
93         --without-emacs                 Do not install lisp file
94         --without-bash-completion       Do not install bash completions files
95         --without-zsh-completion        Do not install zsh completions files
96
97 Additional options are accepted for compatibility with other
98 configure-script calling conventions, but don't do anything yet:
99
100         --build=<cpu>-<vendor>-<os>     Currently ignored
101         --host=<cpu>-<vendor>-<os>      Currently ignored
102         --infodir=DIR                   Currently ignored
103         --datadir=DIR                   Currently ignored
104         --localstatedir=DIR             Currently ignored
105         --libexecdir=DIR                Currently ignored
106         --disable-maintainer-mode       Currently ignored
107         --disable-dependency-tracking   Currently ignored
108
109 EOF
110 }
111
112 # Parse command-line options
113 for option; do
114     if [ "${option}" = '--help' ] ; then
115         usage
116         exit 0
117     elif [ "${option%%=*}" = '--prefix' ] ; then
118         PREFIX="${option#*=}"
119     elif [ "${option%%=*}" = '--libdir' ] ; then
120         LIBDIR="${option#*=}"
121     elif [ "${option%%=*}" = '--includedir' ] ; then
122         INCLUDEDIR="${option#*=}"
123     elif [ "${option%%=*}" = '--mandir' ] ; then
124         MANDIR="${option#*=}"
125     elif [ "${option%%=*}" = '--sysconfdir' ] ; then
126         SYSCONFDIR="${option#*=}"
127     elif [ "${option%%=*}" = '--emacslispdir' ] ; then
128         EMACSLISPDIR="${option#*=}"
129     elif [ "${option%%=*}" = '--bashcompletiondir' ] ; then
130         BASHCOMPLETIONDIR="${option#*=}"
131     elif [ "${option%%=*}" = '--zshcompletiondir' ] ; then
132         ZSHCOMLETIONDIR="${option#*=}"
133     elif [ "${option%%=*}" = '--with-emacs' ]; then
134         if [ "${option#*=}" = 'no' ]; then
135             WITH_EMACS=0
136         else
137             WITH_EMACS=1
138         fi
139     elif [ "${option}" = '--without-emacs' ] ; then
140         WITH_EMACS=0
141     elif [ "${option%%=*}" = '--with-bash-completion' ]; then
142         if [ "${option#*=}" = 'no' ]; then
143             WITH_BASH=0
144         else
145             WITH_BASH=1
146         fi
147     elif [ "${option}" = '--without-bash-completion' ] ; then
148         WITH_BASH=0
149     elif [ "${option%%=*}" = '--with-zsh-completion' ]; then
150         if [ "${option#*=}" = 'no' ]; then
151             WITH_ZSH=0
152         else
153             WITH_ZSH=1
154         fi
155     elif [ "${option}" = '--without-zsh-completion' ] ; then
156         WITH_ZSH=0
157     elif [ "${option%%=*}" = '--build' ] ; then
158         build_option="${option#*=}"
159         case ${build_option} in
160             *-*-*) ;;
161             *)
162                 echo "Unrecognized value for --build option: ${build_option}"
163                 echo "Should be: <cpu>-<vendor>-<os>"
164                 echo "See:"
165                 echo "  $0 --help"
166                 echo ""
167                 exit 1
168         esac
169         build_cpu=${build_option%%-*}
170         build_option=${build_option#*-}
171         build_vendor=${build_option%%-*}
172         build_os=${build_option#*-}
173     elif [ "${option%%=*}" = '--host' ] ; then
174         host_option="${option#*=}"
175         case ${host_option} in
176             *-*-*) ;;
177             *)
178                 echo "Unrecognized value for --host option: ${host_option}"
179                 echo "Should be: <cpu>-<vendor>-<os>"
180                 echo "See:"
181                 echo "  $0 --help"
182                 echo ""
183                 exit 1
184         esac
185         host_cpu=${host_option%%-*}
186         host_option=${host_option#*-}
187         host_vendor=${host_option%%-*}
188         host_os=${host_option#*-}
189     elif [ "${option%%=*}" = '--infodir' ] ; then
190         true
191     elif [ "${option%%=*}" = '--datadir' ] ; then
192         true
193     elif [ "${option%%=*}" = '--localstatedir' ] ; then
194         true
195     elif [ "${option%%=*}" = '--libexecdir' ] ; then
196         true
197     elif [ "${option}" = '--disable-maintainer-mode' ] ; then
198         true
199     elif [ "${option}" = '--disable-dependency-tracking' ] ; then
200         true
201     else
202         echo "Unrecognized option: ${option}"
203         echo "See:"
204         echo "  $0 --help"
205         echo ""
206         exit 1
207     fi
208 done
209
210 # We set this value early, (rather than just while printing the
211 # Makefile.config file later like most values), because we need to
212 # actually investigate this value compared to the ldconfig_paths value
213 # below.
214 libdir_expanded=${LIBDIR:-${PREFIX}/lib}
215
216 cat <<EOF
217 Welcome to Notmuch, a system for indexing, searching and tagging your email.
218
219 We hope that the process of building and installing notmuch is quick
220 and smooth so that you can soon be reading and processing your email
221 more efficiently than ever.
222
223 If anything goes wrong in the configure process, you can override any
224 decisions it makes by manually editing the Makefile.config file that
225 it creates. Also please do as much as you can to figure out what could
226 be different on your machine compared to those of the notmuch
227 developers. Then, please email those details to the Notmuch list
228 (notmuch@notmuchmail.org) so that we can hopefully make future
229 versions of notmuch easier for you to use.
230
231 We'll now investigate your system to verify that all required
232 dependencies are available:
233
234 EOF
235
236 errors=0
237
238 if pkg-config --version > /dev/null 2>&1; then
239     have_pkg_config=1
240 else
241     have_pkg_config=0
242 fi
243
244 printf "Checking for Xapian development files... "
245 have_xapian=0
246 for xapian_config in ${XAPIAN_CONFIG}; do
247     if ${xapian_config} --version > /dev/null 2>&1; then
248         printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //')
249         have_xapian=1
250         xapian_cxxflags=$(${xapian_config} --cxxflags)
251         xapian_ldflags=$(${xapian_config} --libs)
252         break
253     fi
254 done
255 if [ ${have_xapian} = "0" ]; then
256     printf "No.\n"
257     errors=$((errors + 1))
258 fi
259
260 printf "Checking for GMime development files... "
261 have_gmime=0
262 for gmimepc in gmime-2.6 gmime-2.4; do
263     if pkg-config --exists $gmimepc; then
264         printf "Yes ($gmimepc).\n"
265         have_gmime=1
266         gmime_cflags=$(pkg-config --cflags $gmimepc)
267         gmime_ldflags=$(pkg-config --libs $gmimepc)
268     fi
269 done
270 if [ "$have_gmime" = "0" ]; then
271     printf "No.\n"
272     errors=$((errors + 1))
273 fi
274
275 # GMime already depends on Glib >= 2.12, but we use at least one Glib
276 # function that only exists as of 2.14, (g_hash_table_get_keys)
277 printf "Checking for Glib development files (>= 2.14)... "
278 have_glib=0
279 if pkg-config --exists 'glib-2.0 >= 2.14'; then
280     printf "Yes.\n"
281     have_glib=1
282     glib_cflags=$(pkg-config --cflags glib-2.0)
283     glib_ldflags=$(pkg-config --libs glib-2.0)
284 else
285     printf "No.\n"
286     errors=$((errors + 1))
287 fi
288
289 printf "Checking for talloc development files... "
290 if pkg-config --exists talloc; then
291     printf "Yes.\n"
292     have_talloc=1
293     talloc_cflags=$(pkg-config --cflags talloc)
294     talloc_ldflags=$(pkg-config --libs talloc)
295 else
296     printf "No.\n"
297     have_talloc=0
298     talloc_cflags=
299     errors=$((errors + 1))
300 fi
301
302 printf "Checking for valgrind development files... "
303 if pkg-config --exists valgrind; then
304     printf "Yes.\n"
305     have_valgrind=1
306     valgrind_cflags=$(pkg-config --cflags valgrind)
307 else
308     printf "No (but that's fine).\n"
309     have_valgrind=0
310 fi
311
312 if [ -z "${EMACSLISPDIR}" ]; then
313     if pkg-config --exists emacs; then
314         EMACSLISPDIR=$(pkg-config emacs --variable sitepkglispdir)
315     else
316         EMACSLISPDIR='$(prefix)/share/emacs/site-lisp'
317     fi
318 fi
319
320 printf "Checking if emacs is available... "
321 if emacs --quick --batch > /dev/null 2>&1; then
322     printf "Yes.\n"
323     have_emacs=1
324 else
325     printf "No (so will not byte-compile emacs code)\n"
326     have_emacs=0
327 fi
328
329 libdir_in_ldconfig=0
330
331 printf "Checking which platform we are on... "
332 uname=`uname`
333 if [ $uname = "Darwin" ] ; then
334     printf "Mac OS X.\n"
335     platform=MACOSX
336     linker_resolves_library_dependencies=0
337 elif [ $uname = "SunOS" ] ; then
338     printf "Solaris.\n"
339     platform=SOLARIS
340     linker_resolves_library_dependencies=0
341 elif [ $uname = "Linux" ] ; then
342     printf "Linux\n"
343     platform=LINUX
344     linker_resolves_library_dependencies=1
345     ldconfig_paths=$(/sbin/ldconfig -N -X -v 2>/dev/null | sed -n -e 's,^\(/.*\):\( (.*)\)\?$,\1,p')
346     for path in $ldconfig_paths; do
347         if [ "$path" = "$libdir_expanded" ]; then
348             libdir_in_ldconfig=1
349         fi
350     done
351 else
352     printf "Unknown.\n"
353     cat <<EOF
354
355 *** Warning: Unknown platform. Notmuch might or might not build correctly.
356
357 EOF
358 fi
359
360 if [ $errors -gt 0 ]; then
361     cat <<EOF
362
363 *** Error: The dependencies of notmuch could not be satisfied. You will
364 need to install the following packages before being able to compile
365 notmuch:
366
367 EOF
368     if [ $have_xapian -eq 0 ]; then
369         echo "  Xapian library (including development files such as headers)"
370         echo "  http://xapian.org/"
371     fi
372     if [ $have_gmime -eq 0 ]; then
373         echo "  GMime 2.4 library (including development files such as headers)"
374         echo "  http://spruce.sourceforge.net/gmime/"
375     fi
376     if [ $have_glib -eq 0 ]; then
377         echo "  Glib library >= 2.14 (including development files such as headers)"
378         echo "  http://ftp.gnome.org/pub/gnome/sources/glib/"
379     fi
380     if [ $have_talloc -eq 0 ]; then
381         echo "  The talloc library (including development files such as headers)"
382         echo "  http://talloc.samba.org/"
383     fi
384     cat <<EOF
385
386 With any luck, you're using a modern, package-based operating system
387 that has all of these packages available in the distribution. In that
388 case a simple command will install everything you need. For example:
389
390 On Debian and similar systems:
391
392         sudo apt-get install libxapian-dev libgmime-2.4-dev libtalloc-dev
393
394 Or on Fedora and similar systems:
395
396         sudo yum install xapian-core-devel gmime-devel libtalloc-devel
397
398 On other systems, similar commands can be used, but the details of the
399 package names may be different.
400
401 EOF
402     if [ $have_pkg_config -eq 0 ]; then
403 cat <<EOF
404 Note: the pkg-config program is not available. This configure script
405 uses pkg-config to find the compilation flags required to link against
406 the various libraries needed by notmuch. It's possible you simply need
407 to install pkg-config with a command such as:
408
409         sudo apt-get install pkg-config
410 Or:
411         sudo yum install pkgconfig
412
413 But if pkg-config is not available for your system, then you will need
414 to modify the configure script to manually set the cflags and ldflags
415 variables to the correct values to link against each library in each
416 case that pkg-config could not be used to determine those values.
417
418 EOF
419     fi
420 cat <<EOF
421 When you have installed the necessary dependencies, you can run
422 configure again to ensure the packages can be found, or simply run
423 "make" to compile notmuch.
424
425 EOF
426     exit 1
427 fi
428
429 printf "Checking for getline... "
430 if ${CC} -o compat/have_getline compat/have_getline.c > /dev/null 2>&1
431 then
432     printf "Yes.\n"
433     have_getline=1
434 else
435     printf "No (will use our own instead).\n"
436     have_getline=0
437 fi
438 rm -f compat/have_getline
439
440 printf "Checking for strcasestr... "
441 if ${CC} -o compat/have_strcasestr compat/have_strcasestr.c > /dev/null 2>&1
442 then
443     printf "Yes.\n"
444     have_strcasestr=1
445 else
446     printf "No (will use our own instead).\n"
447     have_strcasestr=0
448 fi
449 rm -f compat/have_strcasestr
450
451 printf "int main(void){return 0;}\n" > minimal.c
452
453 printf "Checking for rpath support... "
454 if ${CC} -Wl,--enable-new-dtags -Wl,-rpath,/tmp/ -o minimal minimal.c >/dev/null 2>&1
455 then
456     printf "Yes.\n"
457     rpath_ldflags="-Wl,--enable-new-dtags -Wl,-rpath,\$(libdir)"
458 else
459     printf "No (nothing to worry about).\n"
460     rpath_ldflags=""
461 fi
462
463 printf "Checking for -Wl,--as-needed... "
464 if ${CC} -Wl,--as-needed -o minimal minimal.c >/dev/null 2>&1
465 then
466     printf "Yes.\n"
467     as_needed_ldflags="-Wl,--as-needed"
468 else
469     printf "No (nothing to worry about).\n"
470     as_needed_ldflags=""
471 fi
472
473 WARN_CXXFLAGS=""
474 printf "Checking for available C++ compiler warning flags... "
475 for flag in -Wall -Wextra -Wwrite-strings -Wswitch-enum; do
476     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
477     then
478         WARN_CXXFLAGS="${WARN_CXXFLAGS}${WARN_CXXFLAGS:+ }${flag}"
479     fi
480 done
481 printf "\n\t${WARN_CXXFLAGS}\n"
482
483 WARN_CFLAGS="${WARN_CXXFLAGS}"
484 printf "Checking for available C compiler warning flags... "
485 for flag in -Wmissing-declarations; do
486     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
487     then
488         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
489     fi
490 done
491 printf "\n\t${WARN_CFLAGS}\n"
492
493 rm -f minimal minimal.c
494         
495 cat <<EOF
496
497 All required packages were found. You may now run the following
498 commands to compile and install notmuch:
499
500         make
501         sudo make install
502
503 EOF
504
505 # construct the Makefile.config
506 cat > Makefile.config <<EOF
507 # This Makefile.config was automatically generated by the ./configure
508 # script of notmuch. If the configure script identified anything
509 # incorrectly, then you can edit this file to try to correct things,
510 # but be warned that if configure is run again it will destroy your
511 # changes, (and this could happen by simply calling "make" if the
512 # configure script is updated).
513
514 # The C compiler to use
515 CC = ${CC}
516
517 # The C++ compiler to use
518 CXX = ${CXX}
519
520 # Command to execute emacs from Makefiles
521 EMACS = emacs --quick
522
523 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
524 CFLAGS = ${CFLAGS}
525
526 # Default FLAGS for C++ compiler (can be overridden by user such as "make CXXFLAGS=-g")
527 CXXFLAGS = ${CXXFLAGS}
528
529 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
530 LDFLAGS = ${LDFLAGS}
531
532 # Flags to enable warnings when using the C++ compiler
533 WARN_CXXFLAGS=${WARN_CXXFLAGS}
534
535 # Flags to enable warnings when using the C compiler
536 WARN_CFLAGS=${WARN_CFLAGS}
537
538 # The prefix to which notmuch should be installed
539 # Note: If you change this value here, be sure to ensure that the
540 # LIBDIR_IN_LDCONFIG value below is still set correctly.
541 prefix = ${PREFIX}
542
543 # The directory to which libraries should be installed
544 # Note: If you change this value here, be sure to ensure that the
545 # LIBDIR_IN_LDCONFIG value below is still set correctly.
546 libdir = ${LIBDIR:=\$(prefix)/lib}
547
548 # Whether libdir is in a path configured into ldconfig
549 LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
550
551 # The directory to which header files should be installed
552 includedir = ${INCLUDEDIR:=\$(prefix)/include}
553
554 # The directory to which man pages should be installed
555 mandir = ${MANDIR:=\$(prefix)/share/man}
556
557 # The directory to which read-only (configuration) filesshould be installed
558 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
559
560 # The directory to which emacs lisp files should be installed
561 emacslispdir=${EMACSLISPDIR}
562
563 # Whether there's an emacs binary available for byte-compiling
564 HAVE_EMACS = ${have_emacs}
565
566 # The directory to which desktop files should be installed
567 desktop_dir = \$(prefix)/share/applications
568
569 # The directory to which bash completions files should be installed
570 bash_completion_dir = ${BASHCOMPLETIONDIR:=\$(sysconfdir)/bash_completion.d}
571
572 # The directory to which zsh completions files should be installed
573 zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completion/Unix}
574
575 # Whether the getline function is available (if not, then notmuch will
576 # build its own version)
577 HAVE_GETLINE = ${have_getline}
578
579 # Whether the strcasestr function is available (if not, then notmuch will
580 # build its own version)
581 HAVE_STRCASESTR = ${have_strcasestr}
582
583 # Supported platforms (so far) are: LINUX, MACOSX, SOLARIS
584 PLATFORM = ${platform}
585
586 # Whether the linker will automatically resolve the dependency of one
587 # library on another (if not, then linking a binary requires linking
588 # directly against both)
589 LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}
590
591 # Flags needed to compile and link against Xapian
592 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
593 XAPIAN_LDFLAGS = ${xapian_ldflags}
594
595 # Flags needed to compile and link against GMime-2.4
596 GMIME_CFLAGS = ${gmime_cflags}
597 GMIME_LDFLAGS = ${gmime_ldflags}
598
599 # Flags needed to compile and link against talloc
600 TALLOC_CFLAGS = ${talloc_cflags}
601 TALLOC_LDFLAGS = ${talloc_ldflags}
602
603 # Flags needed to have linker set rpath attribute
604 RPATH_LDFLAGS = ${rpath_ldflags}
605
606 # Flags needed to have linker link only to necessary libraries
607 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
608
609 # Whether valgrind header files are available
610 HAVE_VALGRIND = ${have_valgrind}
611
612 # And if so, flags needed at compile time for valgrind macros
613 VALGRIND_CFLAGS = ${valgrind_cflags}
614
615 # Support for emacs
616 WITH_EMACS = ${WITH_EMACS}
617
618 # Support for bash completion
619 WITH_BASH = ${WITH_BASH}
620
621 # Support for zsh completion
622 WITH_ZSH = ${WITH_ZSH}
623
624 # Combined flags for compiling and linking against all of the above
625 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
626                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
627                    \$(VALGRIND_CFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
628 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
629                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
630                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\
631                      -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
632 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
633 EOF