]> git.notmuchmail.org Git - notmuch/blob - configure
crypto: rename notmuch_crypto_t to _notmuch_crypto_t
[notmuch] / configure
1 #! /bin/sh
2
3 set -u
4
5 # Test whether this shell is capable of parameter substring processing.
6 ( option='a/b'; : ${option#*/} ) 2>/dev/null || {
7     echo "
8 The shell interpreting '$0' is lacking some required features.
9
10 To work around this problem you may try to execute:
11
12     ksh $0 $*
13  or
14     bash $0 $*
15 "
16     exit 1
17 }
18
19 # Store original IFS value so it can be changed (and restored) in many places.
20 readonly DEFAULT_IFS="$IFS"
21
22 # The top-level directory for the source. This ./configure and all Makefiles
23 # are good with ${srcdir} usually being relative. Some components (e.g. tests)
24 # are executed in subdirectories and for those it is simpler to use
25 # ${NOTMUCH_SRCDIR} which holds absolute path to the source.
26 srcdir=$(dirname "$0")
27 NOTMUCH_SRCDIR=$(cd "$srcdir" && pwd)
28
29 subdirs="util compat lib parse-time-string completion doc emacs"
30 subdirs="${subdirs} performance-test test test/test-databases"
31 subdirs="${subdirs} bindings"
32
33 # For a non-srcdir configure invocation (such as ../configure), create
34 # the directory structure and copy Makefiles.
35 if [ "$srcdir" != "." ]; then
36
37     for dir in . ${subdirs}; do
38         mkdir -p "$dir"
39         cp "$srcdir"/"$dir"/Makefile.local "$dir"
40         cp "$srcdir"/"$dir"/Makefile "$dir"
41     done
42
43     # Easiest way to get the test suite to work is to just copy the
44     # whole thing into the build directory.
45     cp -a "$srcdir"/test/* test
46
47     # Emacs only likes to generate compiled files next to the .el files
48     # by default so copy these as well (which is not ideal).
49     cp -a "$srcdir"/emacs/*.el emacs
50
51     # We were not able to create fully working Makefile using ruby mkmf.rb
52     # so ruby bindings source files are copied as well (ditto -- not ideal).
53     mkdir bindings/ruby
54     cp -a "$srcdir"/bindings/ruby/*.[ch] bindings/ruby
55     cp -a "$srcdir"/bindings/ruby/extconf.rb bindings/ruby
56 fi
57
58 # Set several defaults (optionally specified by the user in
59 # environment variables)
60 CC=${CC:-cc}
61 CXX=${CXX:-c++}
62 CFLAGS=${CFLAGS:--g -O2}
63 CPPFLAGS=${CPPFLAGS:-}
64 CXXFLAGS_for_sh=${CXXFLAGS:-${CFLAGS}}
65 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
66 LDFLAGS=${LDFLAGS:-}
67 XAPIAN_CONFIG=${XAPIAN_CONFIG:-}
68 PYTHON=${PYTHON:-}
69
70 # We don't allow the EMACS or GZIP Makefile variables inherit values
71 # from the environment as we do with CC and CXX above. The reason is
72 # that these names as environment variables have existing uses other
73 # than the program name that we want. (EMACS is set to 't' when a
74 # shell is running within emacs and GZIP specifies arguments to pass
75 # on the gzip command line).
76
77 # Set the defaults for values the user can specify with command-line
78 # options.
79 PREFIX=/usr/local
80 LIBDIR=
81 WITH_DOCS=1
82 WITH_API_DOCS=1
83 WITH_EMACS=1
84 WITH_DESKTOP=1
85 WITH_BASH=1
86 WITH_RUBY=1
87 WITH_ZSH=1
88 WITH_RETRY_LOCK=1
89
90 usage ()
91 {
92     cat <<EOF
93 Usage: ./configure [options]...
94
95 This script configures notmuch to build on your system.
96
97 It verifies that dependencies are available, determines flags needed
98 to compile and link against various required libraries, and identifies
99 whether various system functions can be used or if locally-provided
100 replacements will be built instead.
101
102 Finally, it allows you to control various aspects of the build and
103 installation process.
104
105 First, some common variables can specified via environment variables:
106
107         CC              The C compiler to use
108         CFLAGS          Flags to pass to the C compiler
109         CPPFLAGS        Flags to pass to the C preprocessor
110         CXX             The C++ compiler to use
111         CXXFLAGS        Flags to pass to the C compiler
112         LDFLAGS         Flags to pass when linking
113
114 Each of these values can further be controlled by specifying them
115 later on the "make" command line.
116
117 Other environment variables can be used to control configure itself,
118 (and for which there is no equivalent build-time control):
119
120         XAPIAN_CONFIG   The program to use to determine flags for
121                         compiling and linking against the Xapian
122                         library. [$XAPIAN_CONFIG]
123         PYTHON          Name of python command to use in
124                         configure and the test suite.
125
126 Additionally, various options can be specified on the configure
127 command line.
128
129         --prefix=PREFIX Install files in PREFIX [$PREFIX]
130
131 By default, "make install" will install the resulting program to
132 $PREFIX/bin, documentation to $PREFIX/man, etc. You can
133 specify an installation prefix other than $PREFIX using
134 --prefix, for instance:
135
136         ./configure --prefix=\$HOME
137
138 Fine tuning of some installation directories is available:
139
140         --libdir=DIR            Install libraries to DIR [PREFIX/lib]
141         --includedir=DIR        Install header files to DIR [PREFIX/include]
142         --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
143         --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
144         --emacslispdir=DIR      Emacs code [PREFIX/share/emacs/site-lisp]
145         --emacsetcdir=DIR       Emacs miscellaneous files [PREFIX/share/emacs/site-lisp]
146         --bashcompletiondir=DIR Bash completions files [PREFIX/share/bash-completion/completions]
147         --zshcompletiondir=DIR  Zsh completions files [PREFIX/share/zsh/functions/Completion/Unix]
148
149 Some features can be disabled (--with-feature=no is equivalent to
150 --without-feature) :
151
152         --without-bash-completion       Do not install bash completions files
153         --without-docs                  Do not install documentation
154         --without-api-docs              Do not install API man page
155         --without-emacs                 Do not install lisp file
156         --without-desktop               Do not install desktop file
157         --without-ruby                  Do not install ruby bindings
158         --without-zsh-completion        Do not install zsh completions files
159         --without-retry-lock            Do not use blocking xapian opens, even if available
160
161 Additional options are accepted for compatibility with other
162 configure-script calling conventions, but don't do anything yet:
163
164         --build=<cpu>-<vendor>-<os>     Currently ignored
165         --host=<cpu>-<vendor>-<os>      Currently ignored
166         --infodir=DIR                   Currently ignored
167         --datadir=DIR                   Currently ignored
168         --localstatedir=DIR             Currently ignored
169         --libexecdir=DIR                Currently ignored
170         --disable-maintainer-mode       Currently ignored
171         --disable-dependency-tracking   Currently ignored
172
173 EOF
174 }
175
176 # Parse command-line options
177 for option; do
178     if [ "${option}" = '--help' ] ; then
179         usage
180         exit 0
181     elif [ "${option%%=*}" = '--prefix' ] ; then
182         PREFIX="${option#*=}"
183     elif [ "${option%%=*}" = '--libdir' ] ; then
184         LIBDIR="${option#*=}"
185     elif [ "${option%%=*}" = '--includedir' ] ; then
186         INCLUDEDIR="${option#*=}"
187     elif [ "${option%%=*}" = '--mandir' ] ; then
188         MANDIR="${option#*=}"
189     elif [ "${option%%=*}" = '--sysconfdir' ] ; then
190         SYSCONFDIR="${option#*=}"
191     elif [ "${option%%=*}" = '--emacslispdir' ] ; then
192         EMACSLISPDIR="${option#*=}"
193     elif [ "${option%%=*}" = '--emacsetcdir' ] ; then
194         EMACSETCDIR="${option#*=}"
195     elif [ "${option%%=*}" = '--bashcompletiondir' ] ; then
196         BASHCOMPLETIONDIR="${option#*=}"
197     elif [ "${option%%=*}" = '--zshcompletiondir' ] ; then
198         ZSHCOMLETIONDIR="${option#*=}"
199     elif [ "${option%%=*}" = '--with-docs' ]; then
200         if [ "${option#*=}" = 'no' ]; then
201             WITH_DOCS=0
202             WITH_API_DOCS=0
203         else
204             WITH_DOCS=1
205         fi
206     elif [ "${option}" = '--without-docs' ] ; then
207         WITH_DOCS=0
208         WITH_API_DOCS=0
209     elif [ "${option%%=*}" = '--with-api-docs' ]; then
210         if [ "${option#*=}" = 'no' ]; then
211             WITH_API_DOCS=0
212         else
213             WITH_API_DOCS=1
214         fi
215     elif [ "${option}" = '--without-api-docs' ] ; then
216         WITH_API_DOCS=0
217     elif [ "${option%%=*}" = '--with-emacs' ]; then
218         if [ "${option#*=}" = 'no' ]; then
219             WITH_EMACS=0
220         else
221             WITH_EMACS=1
222         fi
223     elif [ "${option}" = '--without-emacs' ] ; then
224         WITH_EMACS=0
225     elif [ "${option%%=*}" = '--with-desktop' ]; then
226         if [ "${option#*=}" = 'no' ]; then
227             WITH_DESKTOP=0
228         else
229             WITH_DESKTOP=1
230         fi
231     elif [ "${option}" = '--without-desktop' ] ; then
232         WITH_DESKTOP=0
233     elif [ "${option%%=*}" = '--with-bash-completion' ]; then
234         if [ "${option#*=}" = 'no' ]; then
235             WITH_BASH=0
236         else
237             WITH_BASH=1
238         fi
239     elif [ "${option}" = '--without-bash-completion' ] ; then
240         WITH_BASH=0
241     elif [ "${option%%=*}" = '--with-ruby' ]; then
242         if [ "${option#*=}" = 'no' ]; then
243             WITH_RUBY=0
244         else
245             WITH_RUBY=1
246         fi
247     elif [ "${option}" = '--without-ruby' ] ; then
248         WITH_RUBY=0
249     elif [ "${option%%=*}" = '--with-retry-lock' ]; then
250         if [ "${option#*=}" = 'no' ]; then
251             WITH_RETRY_LOCK=0
252         else
253             WITH_RETRY_LOCK=1
254         fi
255     elif [ "${option}" = '--without-retry-lock' ] ; then
256         WITH_RETRY_LOCK=0
257     elif [ "${option%%=*}" = '--with-zsh-completion' ]; then
258         if [ "${option#*=}" = 'no' ]; then
259             WITH_ZSH=0
260         else
261             WITH_ZSH=1
262         fi
263     elif [ "${option}" = '--without-zsh-completion' ] ; then
264         WITH_ZSH=0
265     elif [ "${option%%=*}" = '--build' ] ; then
266         true
267     elif [ "${option%%=*}" = '--host' ] ; then
268         true
269     elif [ "${option%%=*}" = '--infodir' ] ; then
270         true
271     elif [ "${option%%=*}" = '--datadir' ] ; then
272         true
273     elif [ "${option%%=*}" = '--localstatedir' ] ; then
274         true
275     elif [ "${option%%=*}" = '--libexecdir' ] ; then
276         true
277     elif [ "${option}" = '--disable-maintainer-mode' ] ; then
278         true
279     elif [ "${option}" = '--disable-dependency-tracking' ] ; then
280         true
281     else
282         echo "Unrecognized option: ${option}"
283         echo "See:"
284         echo "  $0 --help"
285         echo ""
286         exit 1
287     fi
288 done
289
290 # We set this value early, (rather than just while printing the
291 # Makefile.config file later like most values), because we need to
292 # actually investigate this value compared to the ldconfig_paths value
293 # below.
294 if [ -z "$LIBDIR" ] ; then
295     libdir_expanded="${PREFIX}/lib"
296 else
297     # very non-general variable expansion
298     libdir_expanded=$(printf %s "$LIBDIR" | sed "s|\${prefix}|${PREFIX}|; s|\$prefix\>|${PREFIX}|; s|//*|/|g")
299 fi
300
301 cat <<EOF
302 Welcome to Notmuch, a system for indexing, searching and tagging your email.
303
304 We hope that the process of building and installing notmuch is quick
305 and smooth so that you can soon be reading and processing your email
306 more efficiently than ever.
307
308 If anything goes wrong in the configure process, you can override any
309 decisions it makes by manually editing the Makefile.config file that
310 it creates. Also please do as much as you can to figure out what could
311 be different on your machine compared to those of the notmuch
312 developers. Then, please email those details to the Notmuch list
313 (notmuch@notmuchmail.org) so that we can hopefully make future
314 versions of notmuch easier for you to use.
315
316 We'll now investigate your system to verify that all required
317 dependencies are available:
318
319 EOF
320
321 errors=0
322 printf "int main(void){return 0;}\n" > minimal.c
323
324 printf "Sanity checking C compilation environment... "
325 test_cmdline="${CC} ${CFLAGS} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal"
326 if  ${test_cmdline} > /dev/null 2>&1
327 then
328     printf "OK.\n"
329 else
330     printf "Fail.\n"
331     errors=$((errors + 1))
332     printf Executed:; printf ' %s' ${test_cmdline}; echo
333     ${test_cmdline}
334 fi
335
336 printf "Sanity checking C++ compilation environment... "
337 test_cmdline="${CXX} ${CXXFLAGS_for_sh} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal"
338 if ${test_cmdline} > /dev/null 2>&1
339 then
340     printf "OK.\n"
341 else
342     printf "Fail.\n"
343     errors=$((errors + 1))
344     printf Executed:; printf ' %s' ${test_cmdline}; echo
345     ${test_cmdline}
346 fi
347 unset test_cmdline
348
349 if [ $errors -gt 0 ]; then
350     cat <<EOF
351 *** Error: Initial sanity checking of environment failed.  Please try
352 running configure in a clean environment, and if the problem persists,
353 report a bug.
354 EOF
355     rm -f minimal minimal.c
356     exit 1
357 fi
358
359 printf "Reading libnotmuch version from source... "
360 cat > _libversion.c <<EOF
361 #include <stdio.h>
362 #include "lib/notmuch.h"
363 int main(void) {
364     printf("libnotmuch_version_major=%d\n",
365                 LIBNOTMUCH_MAJOR_VERSION);
366     printf("libnotmuch_version_minor=%d\n",
367                 LIBNOTMUCH_MINOR_VERSION);
368     printf("libnotmuch_version_release=%d\n",
369                 LIBNOTMUCH_MICRO_VERSION);
370     return 0;
371 }
372 EOF
373 if ${CC} ${CFLAGS} -I"$srcdir" _libversion.c -o _libversion > /dev/null 2>&1 \
374        && ./_libversion > _libversion.sh && . ./_libversion.sh
375 then
376     printf "OK.\n"
377 else
378     cat <<EOF
379
380 *** Error: Reading lib/notmuch.h failed.
381 Please try running configure again in a clean environment, and if the
382 problem persists, report a bug.
383 EOF
384     rm -f _libversion _libversion.c _libversion.sh
385     exit 1
386 fi
387
388 if pkg-config --version > /dev/null 2>&1; then
389     have_pkg_config=1
390 else
391     have_pkg_config=0
392 fi
393
394 printf "Checking for Xapian development files... "
395 have_xapian=0
396 for xapian_config in ${XAPIAN_CONFIG} xapian-config xapian-config-1.3; do
397     if ${xapian_config} --version > /dev/null 2>&1; then
398         xapian_version=$(${xapian_config} --version | sed -e 's/.* //')
399         printf "Yes (%s).\n" ${xapian_version}
400         have_xapian=1
401         xapian_cxxflags=$(${xapian_config} --cxxflags)
402         xapian_ldflags=$(${xapian_config} --libs)
403         break
404     fi
405 done
406 if [ ${have_xapian} = "0" ]; then
407     printf "No.\n"
408     errors=$((errors + 1))
409 fi
410
411 have_xapian_compact=0
412 have_xapian_field_processor=0
413 if [ ${have_xapian} = "1" ]; then
414     printf "Checking for Xapian compaction support... "
415     cat>_compact.cc<<EOF
416 #include <xapian.h>
417 class TestCompactor : public Xapian::Compactor { };
418 EOF
419     if ${CXX} ${CXXFLAGS_for_sh} ${xapian_cxxflags} -c _compact.cc -o _compact.o > /dev/null 2>&1
420     then
421         have_xapian_compact=1
422         printf "Yes.\n"
423     else
424         printf "No.\n"
425         errors=$((errors + 1))
426     fi
427
428     rm -f _compact.o _compact.cc
429
430     printf "Checking for Xapian FieldProcessor API... "
431     cat>_field_processor.cc<<EOF
432 #include <xapian.h>
433 class TitleFieldProcessor : public Xapian::FieldProcessor { };
434 EOF
435     if ${CXX} ${CXXFLAGS_for_sh} ${xapian_cxxflags} -c _field_processor.cc -o _field_processor.o > /dev/null 2>&1
436     then
437         have_xapian_field_processor=1
438         printf "Yes.\n"
439     else
440         printf "No. (optional)\n"
441     fi
442
443     rm -f _field_processor.o _field_processor.cc
444
445     default_xapian_backend=""
446     # DB_RETRY_LOCK is only supported on Xapian > 1.3.2
447     have_xapian_db_retry_lock=0
448     if [ $WITH_RETRY_LOCK = "1" ]; then
449         printf "Checking for Xapian lock retry support... "
450         cat>_retry.cc<<EOF
451 #include <xapian.h>
452 int flag = Xapian::DB_RETRY_LOCK;
453 EOF
454         if ${CXX} ${CXXFLAGS_for_sh} ${xapian_cxxflags} -c _retry.cc -o _retry.o > /dev/null 2>&1
455         then
456             have_xapian_db_retry_lock=1
457             printf "Yes.\n"
458         else
459             printf "No. (optional)\n"
460         fi
461         rm -f _retry.o _retry.cc
462     fi
463
464     printf "Testing default Xapian backend... "
465     cat >_default_backend.cc <<EOF
466 #include <xapian.h>
467 int main(int argc, char** argv) {
468    Xapian::WritableDatabase db("test.db",Xapian::DB_CREATE_OR_OPEN);
469 }
470 EOF
471     ${CXX} ${CXXFLAGS_for_sh} ${xapian_cxxflags} _default_backend.cc -o _default_backend ${xapian_ldflags}
472     ./_default_backend
473     if [ -f test.db/iamglass ]; then
474         default_xapian_backend=glass
475     else
476         default_xapian_backend=chert
477     fi
478     printf "%s\n" "${default_xapian_backend}";
479     rm -rf test.db _default_backend _default_backend.cc
480 fi
481
482 # we need to have a version >= 2.6.5 to avoid a crypto bug. We need
483 # 2.6.7 for permissive "From " header handling.
484 GMIME_MINVER=2.6.7
485
486 printf "Checking for GMime development files... "
487 if pkg-config --exists "gmime-3.0"; then
488     printf "Yes (3.0).\n"
489     have_gmime=1
490     gmime_cflags=$(pkg-config --cflags gmime-3.0)
491     gmime_ldflags=$(pkg-config --libs gmime-3.0)
492     gmime_major=3
493 elif pkg-config --exists "gmime-2.6 >= $GMIME_MINVER"; then
494     printf "Yes (2.6).\n"
495     have_gmime=1
496     gmime_cflags=$(pkg-config --cflags gmime-2.6)
497     gmime_ldflags=$(pkg-config --libs gmime-2.6)
498     gmime_major=2
499 else
500     have_gmime=0
501     printf "No.\n"
502     errors=$((errors + 1))
503 fi
504
505 # GMime already depends on Glib >= 2.12, but we use at least one Glib
506 # function that only exists as of 2.22, (g_array_unref)
507 printf "Checking for Glib development files (>= 2.22)... "
508 have_glib=0
509 if pkg-config --exists 'glib-2.0 >= 2.22'; then
510     printf "Yes.\n"
511     have_glib=1
512     # these are included in gmime cflags and ldflags
513     # glib_cflags=$(pkg-config --cflags glib-2.0)
514     # glib_ldflags=$(pkg-config --libs glib-2.0)
515 else
516     printf "No.\n"
517     errors=$((errors + 1))
518 fi
519
520 if ! pkg-config --exists zlib; then
521   ${CC} -o compat/gen_zlib_pc "$srcdir"/compat/gen_zlib_pc.c >/dev/null 2>&1 &&
522   compat/gen_zlib_pc > compat/zlib.pc &&
523   PKG_CONFIG_PATH="$PKG_CONFIG_PATH":compat &&
524   export PKG_CONFIG_PATH
525   rm -f compat/gen_zlib_pc
526 fi
527
528 printf "Checking for zlib (>= 1.2.5.2)... "
529 have_zlib=0
530 if pkg-config --atleast-version=1.2.5.2 zlib; then
531     printf "Yes.\n"
532     have_zlib=1
533     zlib_cflags=$(pkg-config --cflags zlib)
534     zlib_ldflags=$(pkg-config --libs zlib)
535 else
536     printf "No.\n"
537     errors=$((errors + 1))
538 fi
539
540 printf "Checking for talloc development files... "
541 if pkg-config --exists talloc; then
542     printf "Yes.\n"
543     have_talloc=1
544     talloc_cflags=$(pkg-config --cflags talloc)
545     talloc_ldflags=$(pkg-config --libs talloc)
546 else
547     printf "No.\n"
548     have_talloc=0
549     talloc_cflags=
550     errors=$((errors + 1))
551 fi
552
553 printf "Checking for python... "
554 have_python=0
555
556 for name in ${PYTHON} python python2 python3; do
557     if command -v $name > /dev/null; then
558         have_python=1
559         python=$name
560         printf "Yes (%s).\n" "$name"
561         break
562     fi
563 done
564
565 if [ $have_python -eq 0 ]; then
566     printf "No.\n"
567     errors=$((errors + 1))
568 fi
569
570 printf "Checking for valgrind development files... "
571 if pkg-config --exists valgrind; then
572     printf "Yes.\n"
573     have_valgrind=1
574     valgrind_cflags=$(pkg-config --cflags valgrind)
575 else
576     printf "No (but that's fine).\n"
577     have_valgrind=0
578     valgrind_cflags=
579 fi
580
581 printf "Checking for bash-completion (>= 1.90)... "
582 if pkg-config --atleast-version=1.90 bash-completion; then
583     printf "Yes.\n"
584 else
585     printf "No (will not install bash completion).\n"
586     WITH_BASH=0
587 fi
588
589 if [ -z "${EMACSLISPDIR-}" ]; then
590     EMACSLISPDIR="\$(prefix)/share/emacs/site-lisp"
591 fi
592
593 if [ -z "${EMACSETCDIR-}" ]; then
594     EMACSETCDIR="\$(prefix)/share/emacs/site-lisp"
595 fi
596
597 printf "Checking if emacs is available... "
598 if emacs --quick --batch > /dev/null 2>&1; then
599     printf "Yes.\n"
600     have_emacs=1
601 else
602     printf "No (so will not byte-compile emacs code)\n"
603     have_emacs=0
604 fi
605
606 have_doxygen=0
607 if [ $WITH_API_DOCS = "1" ] ; then
608     printf "Checking if doxygen is available... "
609     if command -v doxygen > /dev/null; then
610         printf "Yes.\n"
611         have_doxygen=1
612     else
613         printf "No (so will not install api docs)\n"
614     fi
615 fi
616
617 have_ruby_dev=0
618 if [ $WITH_RUBY = "1" ] ; then
619     printf "Checking for ruby development files... "
620     if ruby -e "require 'mkmf'"> /dev/null 2>&1; then
621         printf "Yes.\n"
622         have_ruby_dev=1
623     else
624         printf "No (skipping ruby bindings)\n"
625     fi
626 fi
627
628 have_sphinx=0
629 if [ $WITH_DOCS = "1" ] ; then
630     printf "Checking if sphinx is available and supports nroff output... "
631     if command -v sphinx-build > /dev/null && ${python} -m sphinx.writers.manpage > /dev/null 2>&1 ; then
632         printf "Yes.\n"
633         have_sphinx=1
634     else
635         printf "No (so will not install man pages).\n"
636     fi
637 fi
638
639 if [ $WITH_DESKTOP = "1" ]; then
640     printf "Checking if desktop-file-install is available... "
641     if command -v desktop-file-install > /dev/null; then
642         printf "Yes.\n"
643     else
644         printf "No (so will not install .desktop file).\n"
645         WITH_DESKTOP=0
646     fi
647 fi
648
649 printf "Checking for cppcheck... "
650 if command -v cppcheck > /dev/null; then
651     have_cppcheck=1
652     printf "Yes.\n"
653 else
654     have_cppcheck=0
655     printf "No.\n"
656 fi
657
658 libdir_in_ldconfig=0
659
660 printf "Checking which platform we are on... "
661 uname=$(uname)
662 if [ $uname = "Darwin" ] ; then
663     printf "Mac OS X.\n"
664     platform=MACOSX
665     linker_resolves_library_dependencies=0
666 elif [ $uname = "SunOS" ] ; then
667     printf "Solaris.\n"
668     platform=SOLARIS
669     linker_resolves_library_dependencies=0
670 elif [ $uname = "FreeBSD" ] ; then
671     printf "FreeBSD.\n"
672     platform=FREEBSD
673     linker_resolves_library_dependencies=0
674 elif [ $uname = "OpenBSD" ] ; then
675     printf "OpenBSD.\n"
676     platform=OPENBSD
677     linker_resolves_library_dependencies=0
678 elif [ $uname = "Linux" ] || [ $uname = "GNU" ] ; then
679     printf "%s\n" "$uname"
680     platform="$uname"
681     linker_resolves_library_dependencies=1
682
683     printf "Checking for %s in ldconfig... " "$libdir_expanded"
684     ldconfig_paths=$(/sbin/ldconfig -N -X -v 2>/dev/null | sed -n -e 's,^\(/.*\):\( (.*)\)\?$,\1,p')
685     # Separate ldconfig_paths only on newline (not on any potential
686     # embedded space characters in any filenames). Note, we use a
687     # literal newline in the source here rather than something like:
688     #
689     #   IFS=$(printf '\n')
690     #
691     # because the shell's command substitution deletes any trailing newlines.
692     IFS="
693 "
694     for path in $ldconfig_paths; do
695         if [ "$path" = "$libdir_expanded" ]; then
696             libdir_in_ldconfig=1
697         fi
698     done
699     IFS=$DEFAULT_IFS
700     if [ "$libdir_in_ldconfig" = '0' ]; then
701         printf "No (will set RPATH)\n"
702     else
703         printf "Yes\n"
704     fi
705 else
706     printf "Unknown.\n"
707     platform="$uname"
708     linker_resolves_library_dependencies=0
709     cat <<EOF
710
711 *** Warning: Unknown platform. Notmuch might or might not build correctly.
712
713 EOF
714 fi
715
716 if [ $errors -gt 0 ]; then
717     cat <<EOF
718
719 *** Error: The dependencies of notmuch could not be satisfied. You will
720 need to install the following packages before being able to compile
721 notmuch:
722
723 EOF
724     if [ $have_python -eq 0 ]; then
725         echo "  python interpreter"
726     fi
727     if [ $have_xapian -eq 0 -o $have_xapian_compact -eq 0 ]; then
728         echo "  Xapian library (>= version 1.2.6, including development files such as headers)"
729         echo "  https://xapian.org/"
730     fi
731     if [ $have_zlib -eq 0 ]; then
732         echo "  zlib library (>= version 1.2.5.2, including development files such as headers)"
733         echo "  http://zlib.net/"
734         echo
735     fi
736     if [ $have_gmime -eq 0 ]; then
737         echo "  GMime 2.6 library >= $GMIME_MINVER"
738         echo "  (including development files such as headers)"
739         echo "  http://spruce.sourceforge.net/gmime/"
740         echo
741     fi
742     if [ $have_glib -eq 0 ]; then
743         echo "  Glib library >= 2.22 (including development files such as headers)"
744         echo "  http://ftp.gnome.org/pub/gnome/sources/glib/"
745         echo
746     fi
747     if [ $have_talloc -eq 0 ]; then
748         echo "  The talloc library (including development files such as headers)"
749         echo "  https://talloc.samba.org/"
750         echo
751     fi
752     cat <<EOF
753 With any luck, you're using a modern, package-based operating system
754 that has all of these packages available in the distribution. In that
755 case a simple command will install everything you need. For example:
756
757 On Debian and similar systems:
758
759         sudo apt-get install libxapian-dev libgmime-2.6-dev libtalloc-dev zlib1g-dev
760
761 Or on Fedora and similar systems:
762
763         sudo yum install xapian-core-devel gmime-devel libtalloc-devel zlib-devel
764
765 On other systems, similar commands can be used, but the details of the
766 package names may be different.
767
768 EOF
769     if [ $have_pkg_config -eq 0 ]; then
770 cat <<EOF
771 Note: the pkg-config program is not available. This configure script
772 uses pkg-config to find the compilation flags required to link against
773 the various libraries needed by notmuch. It's possible you simply need
774 to install pkg-config with a command such as:
775
776         sudo apt-get install pkg-config
777 Or:
778         sudo yum install pkgconfig
779
780 But if pkg-config is not available for your system, then you will need
781 to modify the configure script to manually set the cflags and ldflags
782 variables to the correct values to link against each library in each
783 case that pkg-config could not be used to determine those values.
784
785 EOF
786     fi
787 cat <<EOF
788 When you have installed the necessary dependencies, you can run
789 configure again to ensure the packages can be found, or simply run
790 "make" to compile notmuch.
791
792 EOF
793     exit 1
794 fi
795
796 printf "Checking for canonicalize_file_name... "
797 if ${CC} -o compat/have_canonicalize_file_name "$srcdir"/compat/have_canonicalize_file_name.c > /dev/null 2>&1
798 then
799     printf "Yes.\n"
800     have_canonicalize_file_name=1
801 else
802     printf "No (will use our own instead).\n"
803     have_canonicalize_file_name=0
804 fi
805 rm -f compat/have_canonicalize_file_name
806
807
808 printf "Checking for getline... "
809 if ${CC} -o compat/have_getline "$srcdir"/compat/have_getline.c > /dev/null 2>&1
810 then
811     printf "Yes.\n"
812     have_getline=1
813 else
814     printf "No (will use our own instead).\n"
815     have_getline=0
816 fi
817 rm -f compat/have_getline
818
819 printf "Checking for strcasestr... "
820 if ${CC} -o compat/have_strcasestr "$srcdir"/compat/have_strcasestr.c > /dev/null 2>&1
821 then
822     printf "Yes.\n"
823     have_strcasestr=1
824 else
825     printf "No (will use our own instead).\n"
826     have_strcasestr=0
827 fi
828 rm -f compat/have_strcasestr
829
830 printf "Checking for strsep... "
831 if ${CC} -o compat/have_strsep "$srcdir"/compat/have_strsep.c > /dev/null 2>&1
832 then
833     printf "Yes.\n"
834     have_strsep="1"
835 else
836     printf "No (will use our own instead).\n"
837     have_strsep="0"
838 fi
839 rm -f compat/have_strsep
840
841 printf "Checking for timegm... "
842 if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
843 then
844     printf "Yes.\n"
845     have_timegm="1"
846 else
847     printf "No (will use our own instead).\n"
848     have_timegm="0"
849 fi
850 rm -f compat/have_timegm
851
852 printf "Checking for dirent.d_type... "
853 if ${CC} -o compat/have_d_type "$srcdir"/compat/have_d_type.c > /dev/null 2>&1
854 then
855     printf "Yes.\n"
856     have_d_type="1"
857 else
858     printf "No (will use stat instead).\n"
859     have_d_type="0"
860 fi
861 rm -f compat/have_d_type
862
863 printf "Checking for standard version of getpwuid_r... "
864 if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
865 then
866     printf "Yes.\n"
867     std_getpwuid=1
868 else
869     printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
870     std_getpwuid=0
871 fi
872 rm -f compat/check_getpwuid
873
874 printf "Checking for standard version of asctime_r... "
875 if ${CC} -o compat/check_asctime "$srcdir"/compat/check_asctime.c > /dev/null 2>&1
876 then
877     printf "Yes.\n"
878     std_asctime=1
879 else
880     printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
881     std_asctime=0
882 fi
883 rm -f compat/check_asctime
884
885 printf "Checking for rpath support... "
886 if ${CC} -Wl,--enable-new-dtags -Wl,-rpath,/tmp/ -o minimal minimal.c >/dev/null 2>&1
887 then
888     printf "Yes.\n"
889     rpath_ldflags="-Wl,--enable-new-dtags -Wl,-rpath,\$(libdir)"
890 else
891     printf "No (nothing to worry about).\n"
892     rpath_ldflags=""
893 fi
894
895 printf "Checking for -Wl,--as-needed... "
896 if ${CC} -Wl,--as-needed -o minimal minimal.c >/dev/null 2>&1
897 then
898     printf "Yes.\n"
899     as_needed_ldflags="-Wl,--as-needed"
900 else
901     printf "No (nothing to worry about).\n"
902     as_needed_ldflags=""
903 fi
904
905 printf "Checking for -Wl,--no-undefined... "
906 if ${CC} -Wl,--no-undefined -o minimal minimal.c >/dev/null 2>&1
907 then
908     printf "Yes.\n"
909     no_undefined_ldflags="-Wl,--no-undefined"
910 else
911     printf "No (nothing to worry about).\n"
912     no_undefined_ldflags=""
913 fi
914
915 WARN_CXXFLAGS=""
916 printf "Checking for available C++ compiler warning flags... "
917 for flag in -Wall -Wextra -Wwrite-strings; do
918     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
919     then
920         WARN_CXXFLAGS="${WARN_CXXFLAGS}${WARN_CXXFLAGS:+ }${flag}"
921     fi
922 done
923 printf "\n\t%s\n" "${WARN_CXXFLAGS}"
924
925 WARN_CFLAGS="${WARN_CXXFLAGS}"
926 printf "Checking for available C compiler warning flags... "
927 for flag in -Wmissing-declarations; do
928     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
929     then
930         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
931     fi
932 done
933 printf "\n\t%s\n" "${WARN_CFLAGS}"
934
935 rm -f minimal minimal.c _libversion.c _libversion _libversion.sh
936
937 # construct the Makefile.config
938 cat > Makefile.config <<EOF
939 # This Makefile.config was automatically generated by the ./configure
940 # script of notmuch. If the configure script identified anything
941 # incorrectly, then you can edit this file to try to correct things,
942 # but be warned that if configure is run again it will destroy your
943 # changes, (and this could happen by simply calling "make" if the
944 # configure script is updated).
945
946 # The top-level directory for the source, (the directory containing
947 # the configure script). This may be different than the build
948 # directory (the current directory at the time configure was run).
949 srcdir = ${srcdir}
950 NOTMUCH_SRCDIR = ${NOTMUCH_SRCDIR}
951
952 # subdirectories to build
953 subdirs = ${subdirs}
954
955 configure_options = $@
956
957 # We use vpath directives (rather than the VPATH variable) since the
958 # VPATH variable matches targets as well as prerequisites, (which is
959 # not useful since then a target left-over from a srcdir build would
960 # cause a target to not be built in the non-srcdir build).
961 #
962 # Also, we don't use a single "vpath % \$(srcdir)" here because we
963 # don't want the vpath to trigger for our emacs lisp compilation,
964 # (unless we first find a way to convince emacs to build the .elc
965 # target in a directory other than the directory of the .el
966 # prerequisite). In the meantime, we're actually copying in the .el
967 # files, (which is quite ugly).
968 vpath %.c \$(srcdir)
969 vpath %.cc \$(srcdir)
970 vpath Makefile.% \$(srcdir)
971 vpath %.py \$(srcdir)
972 vpath %.rst \$(srcdir)
973
974 # Library versions (used to make SONAME)
975 # The major version of the library interface. This will control the soname.
976 # As such, this number must be incremented for any incompatible change to
977 # the library interface, (such as the deletion of an API or a major
978 # semantic change that breaks formerly functioning code).
979 #
980 LIBNOTMUCH_VERSION_MAJOR = ${libnotmuch_version_major}
981
982 # The minor version of the library interface. This should be incremented at
983 # the time of release for any additions to the library interface,
984 # (and when it is incremented, the release version of the library should
985 #  be reset to 0).
986 LIBNOTMUCH_VERSION_MINOR = ${libnotmuch_version_minor}
987
988 # The release version the library interface. This should be incremented at
989 # the time of release if there have been no changes to the interface, (but
990 # simply compatible changes to the implementation).
991 LIBNOTMUCH_VERSION_RELEASE = ${libnotmuch_version_release}
992
993 # These are derived from the VERSION macros in lib/notmuch.h so
994 # if you have to change them, something is wrong.
995
996 # The C compiler to use
997 CC = ${CC}
998
999 # The C++ compiler to use
1000 CXX = ${CXX}
1001
1002 # Command to execute emacs from Makefiles
1003 EMACS = emacs --quick
1004
1005 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
1006 CFLAGS = ${CFLAGS}
1007
1008 # Default FLAGS for C preprocessor (can be overridden by user such as "make CPPFLAGS=-I/usr/local/include")
1009 CPPFLAGS = ${CPPFLAGS}
1010
1011 # Default FLAGS for C++ compiler (can be overridden by user such as "make CXXFLAGS=-g")
1012 CXXFLAGS = ${CXXFLAGS}
1013
1014 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
1015 LDFLAGS = ${LDFLAGS}
1016
1017 # Flags to enable warnings when using the C++ compiler
1018 WARN_CXXFLAGS=${WARN_CXXFLAGS}
1019
1020 # Flags to enable warnings when using the C compiler
1021 WARN_CFLAGS=${WARN_CFLAGS}
1022
1023 # Name of python interpreter
1024 PYTHON = ${python}
1025
1026 # The prefix to which notmuch should be installed
1027 # Note: If you change this value here, be sure to ensure that the
1028 # LIBDIR_IN_LDCONFIG value below is still set correctly.
1029 prefix = ${PREFIX}
1030
1031 # The directory to which libraries should be installed
1032 # Note: If you change this value here, be sure to ensure that the
1033 # LIBDIR_IN_LDCONFIG value below is still set correctly.
1034 libdir = ${LIBDIR:=\$(prefix)/lib}
1035
1036 # Whether libdir is in a path configured into ldconfig
1037 LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
1038
1039 # The directory to which header files should be installed
1040 includedir = ${INCLUDEDIR:=\$(prefix)/include}
1041
1042 # The directory to which man pages should be installed
1043 mandir = ${MANDIR:=\$(prefix)/share/man}
1044
1045 # The directory to which read-only (configuration) files should be installed
1046 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
1047
1048 # The directory to which emacs lisp files should be installed
1049 emacslispdir=${EMACSLISPDIR}
1050
1051 # The directory to which emacs miscellaneous (machine-independent) files should
1052 # be installed
1053 emacsetcdir=${EMACSETCDIR}
1054
1055 # Whether there's an emacs binary available for byte-compiling
1056 HAVE_EMACS = ${have_emacs}
1057
1058 # Whether there's a sphinx-build binary available for building documentation
1059 HAVE_SPHINX=${have_sphinx}
1060
1061 # Whether there's a doxygen binary available for building api documentation
1062 HAVE_DOXYGEN=${have_doxygen}
1063
1064 # The directory to which desktop files should be installed
1065 desktop_dir = \$(prefix)/share/applications
1066
1067 # The directory to which bash completions files should be installed
1068 bash_completion_dir = ${BASHCOMPLETIONDIR:=\$(prefix)/share/bash-completion/completions}
1069
1070 # The directory to which zsh completions files should be installed
1071 zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completion/Unix}
1072
1073 # Whether the canonicalize_file_name function is available (if not, then notmuch will
1074 # build its own version)
1075 HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}
1076
1077 # Whether the cppcheck static checker is available
1078 HAVE_CPPCHECK = ${have_cppcheck}
1079
1080 # Whether the getline function is available (if not, then notmuch will
1081 # build its own version)
1082 HAVE_GETLINE = ${have_getline}
1083
1084 # Are the ruby development files (and ruby) available? If not skip
1085 # building/testing ruby bindings.
1086 HAVE_RUBY_DEV = ${have_ruby_dev}
1087
1088 # Whether the strcasestr function is available (if not, then notmuch will
1089 # build its own version)
1090 HAVE_STRCASESTR = ${have_strcasestr}
1091
1092 # Whether the strsep function is available (if not, then notmuch will
1093 # build its own version)
1094 HAVE_STRSEP = ${have_strsep}
1095
1096 # Whether the timegm function is available (if not, then notmuch will
1097 # build its own version)
1098 HAVE_TIMEGM = ${have_timegm}
1099
1100 # Whether struct dirent has d_type (if not, then notmuch will use stat)
1101 HAVE_D_TYPE = ${have_d_type}
1102
1103 # Whether the Xapian version in use supports compaction
1104 HAVE_XAPIAN_COMPACT = ${have_xapian_compact}
1105
1106 # Whether the Xapian version in use supports field processors
1107 HAVE_XAPIAN_FIELD_PROCESSOR = ${have_xapian_field_processor}
1108
1109 # Whether the Xapian version in use supports DB_RETRY_LOCK
1110 HAVE_XAPIAN_DB_RETRY_LOCK = ${have_xapian_db_retry_lock}
1111
1112 # Whether the getpwuid_r function is standards-compliant
1113 # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
1114 # to enable the standards-compliant version -- needed for Solaris)
1115 STD_GETPWUID = ${std_getpwuid}
1116
1117 # Whether the asctime_r function is standards-compliant
1118 # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
1119 # to enable the standards-compliant version -- needed for Solaris)
1120 STD_ASCTIME = ${std_asctime}
1121
1122 # Supported platforms (so far) are: LINUX, MACOSX, SOLARIS, FREEBSD, OPENBSD
1123 PLATFORM = ${platform}
1124
1125 # Whether the linker will automatically resolve the dependency of one
1126 # library on another (if not, then linking a binary requires linking
1127 # directly against both)
1128 LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}
1129
1130 # Flags needed to compile and link against Xapian
1131 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
1132 XAPIAN_LDFLAGS = ${xapian_ldflags}
1133
1134 # Which backend will Xapian use by default?
1135 DEFAULT_XAPIAN_BACKEND = ${default_xapian_backend}
1136
1137 # Flags needed to compile and link against GMime
1138 GMIME_CFLAGS = ${gmime_cflags}
1139 GMIME_LDFLAGS = ${gmime_ldflags}
1140
1141 # Flags needed to compile and link against zlib
1142 ZLIB_CFLAGS = ${zlib_cflags}
1143 ZLIB_LDFLAGS = ${zlib_ldflags}
1144
1145 # Flags needed to compile and link against talloc
1146 TALLOC_CFLAGS = ${talloc_cflags}
1147 TALLOC_LDFLAGS = ${talloc_ldflags}
1148
1149 # Flags needed to have linker set rpath attribute
1150 RPATH_LDFLAGS = ${rpath_ldflags}
1151
1152 # Flags needed to have linker link only to necessary libraries
1153 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
1154
1155 # Flags to have the linker flag undefined symbols in object files
1156 NO_UNDEFINED_LDFLAGS = ${no_undefined_ldflags}
1157
1158 # Whether valgrind header files are available
1159 HAVE_VALGRIND = ${have_valgrind}
1160
1161 # And if so, flags needed at compile time for valgrind macros
1162 VALGRIND_CFLAGS = ${valgrind_cflags}
1163
1164 # Support for emacs
1165 WITH_EMACS = ${WITH_EMACS}
1166
1167 # Support for desktop file
1168 WITH_DESKTOP = ${WITH_DESKTOP}
1169
1170 # Support for bash completion
1171 WITH_BASH = ${WITH_BASH}
1172
1173 # Support for zsh completion
1174 WITH_ZSH = ${WITH_ZSH}
1175
1176 # Combined flags for compiling and linking against all of the above
1177 COMMON_CONFIGURE_CFLAGS = \\
1178         \$(GMIME_CFLAGS) \$(TALLOC_CFLAGS) \$(ZLIB_CFLAGS)      \\
1179         -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \$(VALGRIND_CFLAGS)   \\
1180         -DHAVE_GETLINE=\$(HAVE_GETLINE)                         \\
1181         -DHAVE_CANONICALIZE_FILE_NAME=\$(HAVE_CANONICALIZE_FILE_NAME) \\
1182         -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)                   \\
1183         -DHAVE_STRSEP=\$(HAVE_STRSEP)                           \\
1184         -DHAVE_TIMEGM=\$(HAVE_TIMEGM)                           \\
1185         -DHAVE_D_TYPE=\$(HAVE_D_TYPE)                           \\
1186         -DSTD_GETPWUID=\$(STD_GETPWUID)                         \\
1187         -DSTD_ASCTIME=\$(STD_ASCTIME)                           \\
1188         -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)           \\
1189         -DSILENCE_XAPIAN_DEPRECATION_WARNINGS                   \\
1190         -DHAVE_XAPIAN_FIELD_PROCESSOR=\$(HAVE_XAPIAN_FIELD_PROCESSOR) \\
1191         -DHAVE_XAPIAN_DB_RETRY_LOCK=\$(HAVE_XAPIAN_DB_RETRY_LOCK)
1192
1193 CONFIGURE_CFLAGS = \$(COMMON_CONFIGURE_CFLAGS)
1194
1195 CONFIGURE_CXXFLAGS = \$(COMMON_CONFIGURE_CFLAGS) \$(XAPIAN_CXXFLAGS)
1196
1197 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(XAPIAN_LDFLAGS)
1198 EOF
1199
1200 # construct the sh.config
1201 cat > sh.config <<EOF
1202 # This sh.config was automatically generated by the ./configure
1203 # script of notmuch.
1204
1205 NOTMUCH_SRCDIR='${NOTMUCH_SRCDIR}'
1206
1207 # Whether the Xapian version in use supports compaction
1208 NOTMUCH_HAVE_XAPIAN_COMPACT=${have_xapian_compact}
1209
1210 # Whether the Xapian version in use supports field processors
1211 NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR=${have_xapian_field_processor}
1212
1213 # Whether the Xapian version in use supports lock retry
1214 NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK=${have_xapian_db_retry_lock}
1215
1216 # Which backend will Xapian use by default?
1217 NOTMUCH_DEFAULT_XAPIAN_BACKEND=${default_xapian_backend}
1218
1219 # do we have man pages?
1220 NOTMUCH_HAVE_MAN=$((have_sphinx))
1221
1222 # Name of python interpreter
1223 NOTMUCH_PYTHON=${python}
1224
1225 # Are the ruby development files (and ruby) available? If not skip
1226 # building/testing ruby bindings.
1227 NOTMUCH_HAVE_RUBY_DEV=${have_ruby_dev}
1228
1229 # Major version of gmime
1230 NOTMUCH_GMIME_MAJOR=${gmime_major}
1231
1232 # Platform we are run on
1233 PLATFORM=${platform}
1234 EOF
1235
1236 # Finally, after everything configured, inform the user how to continue.
1237 cat <<EOF
1238
1239 All required packages were found. You may now run the following
1240 commands to compile and install notmuch:
1241
1242         make
1243         sudo make install
1244
1245 EOF