]> git.notmuchmail.org Git - notmuch/blob - configure
emacs: Add new option notmuch-search-hide-excluded
[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 case $NOTMUCH_SRCDIR in ( *\'* | *['\"`$']* )
30         echo "Definitely unsafe characters in source path '$NOTMUCH_SRCDIR'".
31         exit 1
32 esac
33
34 case $PWD in ( *\'* | *['\"`$']* )
35         echo "Definitely unsafe characters in current directory '$PWD'".
36         exit 1
37 esac
38
39 # In case of whitespace, builds may work, tests definitely will not.
40 case $NOTMUCH_SRCDIR in ( *["$IFS"]* )
41         echo "Whitespace in source path '$NOTMUCH_SRCDIR' not supported".
42         exit 1
43 esac
44
45 case $PWD in ( *["$IFS"]* )
46         echo "Whitespace in current directory '$PWD' not supported".
47         exit 1
48 esac
49
50 subdirs="util compat lib parse-time-string completion doc emacs"
51 subdirs="${subdirs} performance-test test"
52 subdirs="${subdirs} bindings"
53
54 # For a non-srcdir configure invocation (such as ../configure), create
55 # the directory structure and copy Makefiles.
56 if [ "$srcdir" != "." ]; then
57
58     NOTMUCH_BUILDDIR=$PWD
59
60     for dir in . ${subdirs}; do
61         mkdir -p "$dir"
62         cp "$srcdir"/"$dir"/Makefile.local "$dir"
63         cp "$srcdir"/"$dir"/Makefile "$dir"
64     done
65
66     # Emacs only likes to generate compiled files next to the .el files
67     # by default so copy these as well (which is not ideal).
68     cp -a "$srcdir"/emacs/*.el emacs
69
70     # We were not able to create fully working Makefile using ruby mkmf.rb
71     # so ruby bindings source files are copied as well (ditto -- not ideal).
72     mkdir bindings/ruby
73     cp -a "$srcdir"/bindings/ruby/*.[ch] bindings/ruby
74     cp -a "$srcdir"/bindings/ruby/extconf.rb bindings/ruby
75
76     # Use the same hack to replicate python-cffi source for
77     # out-of-tree builds (again, not ideal).
78     mkdir bindings/python-cffi
79     cp -a "$srcdir"/bindings/python-cffi/tests \
80        "$srcdir"/bindings/python-cffi/notmuch2 \
81        "$srcdir"/bindings/python-cffi/setup.py \
82        bindings/python-cffi/
83 else
84     NOTMUCH_BUILDDIR=$NOTMUCH_SRCDIR
85 fi
86
87 # Set several defaults (optionally specified by the user in
88 # environment variables)
89 BASHCMD=${BASHCMD:-bash}
90 PERL=${PERL:-perl}
91 CC=${CC:-cc}
92 CXX=${CXX:-c++}
93 CFLAGS=${CFLAGS:--g -O2}
94 CPPFLAGS=${CPPFLAGS:-}
95 CXXFLAGS_for_sh=${CXXFLAGS:-${CFLAGS}}
96 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
97 LDFLAGS=${LDFLAGS:-}
98 XAPIAN_CONFIG=${XAPIAN_CONFIG:-}
99 PYTHON=${PYTHON:-}
100 RUBY=${RUBY:-ruby}
101
102 # We don't allow the EMACS or GZIP Makefile variables inherit values
103 # from the environment as we do with CC and CXX above. The reason is
104 # that these names as environment variables have existing uses other
105 # than the program name that we want. (EMACS is set to 't' when a
106 # shell is running within emacs and GZIP specifies arguments to pass
107 # on the gzip command line).
108
109 # Set the defaults for values the user can specify with command-line
110 # options.
111 PREFIX=/usr/local
112 LIBDIR=
113 WITH_DOCS=1
114 WITH_API_DOCS=1
115 WITH_PYTHON_DOCS=1
116 WITH_EMACS=1
117 WITH_DESKTOP=1
118 WITH_BASH=1
119 WITH_RPATH=1
120 WITH_RUBY=1
121 WITH_ZSH=1
122 WITH_RETRY_LOCK=1
123
124 usage ()
125 {
126     cat <<EOF
127 Usage: ./configure [options]...
128
129 This script configures notmuch to build on your system.
130
131 It verifies that dependencies are available, determines flags needed
132 to compile and link against various required libraries, and identifies
133 whether various system functions can be used or if locally-provided
134 replacements will be built instead.
135
136 Finally, it allows you to control various aspects of the build and
137 installation process.
138
139 First, some common variables can specified via environment variables:
140
141         CC              The C compiler to use
142         CFLAGS          Flags to pass to the C compiler
143         CPPFLAGS        Flags to pass to the C preprocessor
144         CXX             The C++ compiler to use
145         CXXFLAGS        Flags to pass to the C compiler
146         LDFLAGS         Flags to pass when linking
147
148 Each of these values can further be controlled by specifying them
149 later on the "make" command line.
150
151 Other environment variables can be used to control configure itself,
152 (and for which there is no equivalent build-time control):
153
154         XAPIAN_CONFIG   The program to use to determine flags for
155                         compiling and linking against the Xapian
156                         library. [$XAPIAN_CONFIG]
157         PYTHON          Name of python command to use in
158                         configure and the test suite.
159         RUBY            Name of ruby command to use in
160                         configure and the test suite.
161
162 Additionally, various options can be specified on the configure
163 command line.
164
165         --prefix=PREFIX Install files in PREFIX [$PREFIX]
166
167 By default, "make install" will install the resulting program to
168 $PREFIX/bin, documentation to $PREFIX/man, etc. You can
169 specify an installation prefix other than $PREFIX using
170 --prefix, for instance:
171
172         ./configure --prefix=\$HOME
173
174 Fine tuning of some installation directories is available:
175
176         --libdir=DIR            Install libraries to DIR [PREFIX/lib]
177         --includedir=DIR        Install header files to DIR [PREFIX/include]
178         --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
179         --infodir=DIR           Install man pages to DIR [PREFIX/share/man]
180         --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
181         --emacslispdir=DIR      Emacs code [PREFIX/share/emacs/site-lisp]
182         --emacsetcdir=DIR       Emacs miscellaneous files [PREFIX/share/emacs/site-lisp]
183         --bashcompletiondir=DIR Bash completions files [PREFIX/share/bash-completion/completions]
184         --zshcompletiondir=DIR  Zsh completions files [PREFIX/share/zsh/site-functions]
185
186 Some features can be disabled (--with-feature=no is equivalent to
187 --without-feature) :
188
189         --without-bash-completion       Do not install bash completions files
190         --without-docs                  Do not install documentation
191         --without-api-docs              Do not install API man page
192         --without-emacs                 Do not install lisp file
193         --without-desktop               Do not install desktop file
194         --without-ruby                  Do not install ruby bindings
195         --without-zsh-completion        Do not install zsh completions files
196         --without-retry-lock            Do not use blocking xapian opens, even if available
197
198 Additional options are accepted for compatibility with other
199 configure-script calling conventions, but don't do anything yet:
200
201         --build=<cpu>-<vendor>-<os>     Currently ignored
202         --host=<cpu>-<vendor>-<os>      Currently ignored
203         --datadir=DIR                   Currently ignored
204         --localstatedir=DIR             Currently ignored
205         --libexecdir=DIR                Currently ignored
206         --disable-maintainer-mode       Currently ignored
207         --disable-dependency-tracking   Currently ignored
208
209 EOF
210 }
211
212 # Parse command-line options
213 for option; do
214     if [ "${option}" = '--help' ] ; then
215         usage
216         exit 0
217     elif [ "${option%%=*}" = '--prefix' ] ; then
218         PREFIX="${option#*=}"
219     elif [ "${option%%=*}" = '--libdir' ] ; then
220         LIBDIR="${option#*=}"
221     elif [ "${option%%=*}" = '--includedir' ] ; then
222         INCLUDEDIR="${option#*=}"
223     elif [ "${option%%=*}" = '--mandir' ] ; then
224         MANDIR="${option#*=}"
225     elif [ "${option%%=*}" = '--infodir' ] ; then
226         INFODIR="${option#*=}"
227     elif [ "${option%%=*}" = '--sysconfdir' ] ; then
228         SYSCONFDIR="${option#*=}"
229     elif [ "${option%%=*}" = '--emacslispdir' ] ; then
230         EMACSLISPDIR="${option#*=}"
231     elif [ "${option%%=*}" = '--emacsetcdir' ] ; then
232         EMACSETCDIR="${option#*=}"
233     elif [ "${option%%=*}" = '--bashcompletiondir' ] ; then
234         BASHCOMPLETIONDIR="${option#*=}"
235     elif [ "${option%%=*}" = '--zshcompletiondir' ] ; then
236         ZSHCOMLETIONDIR="${option#*=}"
237     elif [ "${option%%=*}" = '--with-docs' ]; then
238         if [ "${option#*=}" = 'no' ]; then
239             WITH_DOCS=0
240             WITH_API_DOCS=0
241         else
242             WITH_DOCS=1
243         fi
244     elif [ "${option}" = '--without-docs' ] ; then
245         WITH_DOCS=0
246         WITH_API_DOCS=0
247     elif [ "${option%%=*}" = '--with-api-docs' ]; then
248         if [ "${option#*=}" = 'no' ]; then
249             WITH_API_DOCS=0
250         else
251             WITH_API_DOCS=1
252         fi
253     elif [ "${option}" = '--without-api-docs' ] ; then
254         WITH_API_DOCS=0
255     elif [ "${option%%=*}" = '--with-emacs' ]; then
256         if [ "${option#*=}" = 'no' ]; then
257             WITH_EMACS=0
258         else
259             WITH_EMACS=1
260         fi
261     elif [ "${option}" = '--without-emacs' ] ; then
262         WITH_EMACS=0
263     elif [ "${option%%=*}" = '--with-desktop' ]; then
264         if [ "${option#*=}" = 'no' ]; then
265             WITH_DESKTOP=0
266         else
267             WITH_DESKTOP=1
268         fi
269     elif [ "${option}" = '--without-desktop' ] ; then
270         WITH_DESKTOP=0
271     elif [ "${option%%=*}" = '--with-bash-completion' ]; then
272         if [ "${option#*=}" = 'no' ]; then
273             WITH_BASH=0
274         else
275             WITH_BASH=1
276         fi
277     elif [ "${option}" = '--without-bash-completion' ] ; then
278         WITH_BASH=0
279     elif [ "${option%%=*}" = '--with-rpath' ]; then
280         if [ "${option#*=}" = 'no' ]; then
281             WITH_RPATH=0
282         else
283             WITH_RPATH=1
284         fi
285     elif [ "${option}" = '--without-rpath' ] ; then
286         WITH_RPATH=0
287     elif [ "${option%%=*}" = '--with-ruby' ]; then
288         if [ "${option#*=}" = 'no' ]; then
289             WITH_RUBY=0
290         else
291             WITH_RUBY=1
292         fi
293     elif [ "${option}" = '--without-ruby' ] ; then
294         WITH_RUBY=0
295     elif [ "${option%%=*}" = '--with-retry-lock' ]; then
296         if [ "${option#*=}" = 'no' ]; then
297             WITH_RETRY_LOCK=0
298         else
299             WITH_RETRY_LOCK=1
300         fi
301     elif [ "${option}" = '--without-retry-lock' ] ; then
302         WITH_RETRY_LOCK=0
303     elif [ "${option%%=*}" = '--with-zsh-completion' ]; then
304         if [ "${option#*=}" = 'no' ]; then
305             WITH_ZSH=0
306         else
307             WITH_ZSH=1
308         fi
309     elif [ "${option}" = '--without-zsh-completion' ] ; then
310         WITH_ZSH=0
311     elif [ "${option%%=*}" = '--build' ] ; then
312         true
313     elif [ "${option%%=*}" = '--host' ] ; then
314         true
315     elif [ "${option%%=*}" = '--bindir' ] ; then
316         true
317     elif [ "${option%%=*}" = '--sbindir' ] ; then
318         true
319     elif [ "${option%%=*}" = '--datadir' ] ; then
320         true
321     elif [ "${option%%=*}" = '--localstatedir' ] ; then
322         true
323     elif [ "${option%%=*}" = '--sharedstatedir' ] ; then
324         true
325     elif [ "${option%%=*}" = '--libexecdir' ] ; then
326         true
327     elif [ "${option%%=*}" = '--exec-prefix' ] ; then
328         true
329     elif [ "${option%%=*}" = '--program-prefix' ] ; then
330         true
331     elif [ "${option}" = '--disable-maintainer-mode' ] ; then
332         true
333     elif [ "${option}" = '--disable-dependency-tracking' ] ; then
334         true
335     else
336         echo "Unrecognized option: ${option}"
337         echo "See:"
338         echo "  $0 --help"
339         echo ""
340         exit 1
341     fi
342 done
343
344 # We set this value early, (rather than just while printing the
345 # Makefile.config file later like most values), because we need to
346 # actually investigate this value compared to the ldconfig_paths value
347 # below.
348 if [ -z "$LIBDIR" ] ; then
349     libdir_expanded="${PREFIX}/lib"
350 else
351     # very non-general variable expansion
352     libdir_expanded=$(printf %s "$LIBDIR" | sed "s|\${prefix}|${PREFIX}|; s|\$prefix\>|${PREFIX}|; s|//*|/|g")
353 fi
354
355 cat <<EOF
356 Welcome to Notmuch, a system for indexing, searching and tagging your email.
357
358 We hope that the process of building and installing notmuch is quick
359 and smooth so that you can soon be reading and processing your email
360 more efficiently than ever.
361
362 If anything goes wrong in the configure process, you can override any
363 decisions it makes by manually editing the Makefile.config file that
364 it creates. Also please do as much as you can to figure out what could
365 be different on your machine compared to those of the notmuch
366 developers. Then, please email those details to the Notmuch list
367 (notmuch@notmuchmail.org) so that we can hopefully make future
368 versions of notmuch easier for you to use.
369
370 We'll now investigate your system to verify that all required
371 dependencies are available:
372
373 EOF
374
375 errors=0
376 printf "int main(void){return 0;}\n" > minimal.c
377
378 printf "Sanity checking C compilation environment... "
379 test_cmdline="${CC} ${CFLAGS} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal"
380 if  ${test_cmdline} > /dev/null 2>&1
381 then
382     printf "OK.\n"
383 else
384     printf "Fail.\n"
385     errors=$((errors + 1))
386     printf Executed:; printf ' %s' ${test_cmdline}; echo
387     ${test_cmdline}
388 fi
389
390 printf "Sanity checking C++ compilation environment... "
391 test_cmdline="${CXX} ${CXXFLAGS_for_sh} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal"
392 if ${test_cmdline} > /dev/null 2>&1
393 then
394     printf "OK.\n"
395 else
396     printf "Fail.\n"
397     errors=$((errors + 1))
398     printf Executed:; printf ' %s' ${test_cmdline}; echo
399     ${test_cmdline}
400 fi
401 unset test_cmdline
402
403 if [ $errors -gt 0 ]; then
404     cat <<EOF
405 *** Error: Initial sanity checking of environment failed.  Please try
406 running configure in a clean environment, and if the problem persists,
407 report a bug.
408 EOF
409     rm -f minimal minimal.c
410     exit 1
411 fi
412
413 printf "C compiler supports address sanitizer... "
414 test_cmdline="${CC} ${CFLAGS} ${CPPFLAGS} -fsanitize=address minimal.c ${LDFLAGS} -o minimal"
415 if ${test_cmdline} >/dev/null 2>&1 && ./minimal
416 then
417     printf "Yes.\n"
418     have_asan=1
419 else
420     printf "Nope, skipping those tests.\n"
421     have_asan=0
422 fi
423 unset test_cmdline
424
425 printf "C compiler supports thread sanitizer... "
426 test_cmdline="${CC} ${CFLAGS} ${CPPFLAGS} -fsanitize=thread minimal.c ${LDFLAGS} -o minimal"
427 if ${test_cmdline} >/dev/null 2>&1 && ./minimal
428 then
429     printf "Yes.\n"
430     have_tsan=1
431 else
432     printf "Nope, skipping those tests.\n"
433     have_tsan=0
434 fi
435 unset test_cmdline
436
437 printf "Reading libnotmuch version from source... "
438 cat > _libversion.c <<EOF
439 #include <stdio.h>
440 #include "lib/notmuch.h"
441 int main(void) {
442     printf("libnotmuch_version_major=%d\n",
443                 LIBNOTMUCH_MAJOR_VERSION);
444     printf("libnotmuch_version_minor=%d\n",
445                 LIBNOTMUCH_MINOR_VERSION);
446     printf("libnotmuch_version_release=%d\n",
447                 LIBNOTMUCH_MICRO_VERSION);
448     return 0;
449 }
450 EOF
451 if ${CC} ${CFLAGS} -I"$srcdir" _libversion.c -o _libversion > /dev/null 2>&1 \
452        && ./_libversion > _libversion.sh && . ./_libversion.sh
453 then
454     printf "OK.\n"
455 else
456     cat <<EOF
457
458 *** Error: Reading lib/notmuch.h failed.
459 Please try running configure again in a clean environment, and if the
460 problem persists, report a bug.
461 EOF
462     rm -f _libversion _libversion.c _libversion.sh
463     exit 1
464 fi
465
466 if pkg-config --version > /dev/null 2>&1; then
467     have_pkg_config=1
468 else
469     have_pkg_config=0
470 fi
471
472
473
474 printf "Checking for Xapian development files (>= 1.4.0)... "
475 have_xapian=0
476 for xapian_config in ${XAPIAN_CONFIG} xapian-config; do
477     if ${xapian_config} --version > /dev/null 2>&1; then
478         xapian_version=$(${xapian_config} --version | sed -e 's/.* //')
479         case $xapian_version in
480                 1.[4-9]* | 1.[1-9][0-9]* | [2-9]* | [1-9][0-9]*)
481                         printf "Yes (%s).\n" ${xapian_version}
482                         have_xapian=1
483                         xapian_cxxflags=$(${xapian_config} --cxxflags)
484                         xapian_ldflags=$(${xapian_config} --libs)
485                         ;;
486                 *) printf "Xapian $xapian_version not supported... "
487         esac
488         break
489     fi
490 done
491 if [ ${have_xapian} = "0" ]; then
492     printf "No.\n"
493     errors=$((errors + 1))
494 fi
495
496 GMIME_MINVER=3.0.3
497
498 printf "Checking for GMime development files (>= $GMIME_MINVER)... "
499 if pkg-config --exists "gmime-3.0 >= $GMIME_MINVER"; then
500     printf "Yes.\n"
501     have_gmime=1
502     gmime_cflags=$(pkg-config --cflags gmime-3.0)
503     gmime_ldflags=$(pkg-config --libs gmime-3.0)
504
505     printf "Checking for GMime session key extraction support... "
506
507     cat > _check_session_keys.c <<EOF
508 #include <gmime/gmime.h>
509 #include <stdio.h>
510
511 int main () {
512     GError *error = NULL;
513     GMimeParser *parser = NULL;
514     GMimeMultipartEncrypted *body = NULL;
515     GMimeDecryptResult *decrypt_result = NULL;
516     GMimeObject *output = NULL;
517
518     g_mime_init ();
519     parser = g_mime_parser_new ();
520     g_mime_parser_init_with_stream (parser, g_mime_stream_file_open("$srcdir/test/corpora/crypto/basic-encrypted.eml", "r", &error));
521     if (error) return !! fprintf (stderr, "failed to instantiate parser with test/corpora/crypto/basic-encrypted.eml\n");
522
523     body = GMIME_MULTIPART_ENCRYPTED(g_mime_message_get_mime_part (g_mime_parser_construct_message (parser, NULL)));
524     if (body == NULL) return !! fprintf (stderr, "did not find a multipart encrypted message\n");
525
526     output = g_mime_multipart_encrypted_decrypt (body, GMIME_DECRYPT_EXPORT_SESSION_KEY, NULL, &decrypt_result, &error);
527     if (error || output == NULL) return !! fprintf (stderr, "decryption failed\n");
528
529     if (decrypt_result == NULL) return !! fprintf (stderr, "no GMimeDecryptResult found\n");
530     if (decrypt_result->session_key == NULL) return !! fprintf (stderr, "GMimeDecryptResult has no session key\n");
531
532     printf ("%s\n", decrypt_result->session_key);
533     return 0;
534 }
535 EOF
536     if ! TEMP_GPG=$(mktemp -d "${TMPDIR:-/tmp}/notmuch.XXXXXX"); then
537         printf 'No.\nCould not make tempdir for testing session-key support.\n'
538         errors=$((errors + 1))
539     elif ${CC} ${CFLAGS} ${gmime_cflags} _check_session_keys.c ${gmime_ldflags} -o _check_session_keys \
540            && GNUPGHOME=${TEMP_GPG} gpg --batch --quiet --import < "$srcdir"/test/openpgp4-secret-key.asc \
541            && SESSION_KEY=$(GNUPGHOME=${TEMP_GPG} ./_check_session_keys) \
542            && [ $SESSION_KEY = 9:496A0B6D15A5E7BA762FB8E5FE6DEE421D4D9BBFCEAD1CDD0CCF636D07ADE621 ]
543     then
544         printf "OK.\n"
545     else
546         cat <<EOF
547 No.
548 *** Error: Could not extract session keys from encrypted message.
549
550 This is likely due to your GMime having been built against a old
551 version of GPGME.
552
553 Please try to rebuild your version of GMime against a more recent
554 version of GPGME (at least GPGME 1.8.0).
555 EOF
556         if GPGME_VERS="$(pkg-config --modversion gpgme || gpgme-config --version)"; then
557             printf 'Your current GPGME development version is: %s\n' "$GPGME_VERS"
558         else
559             printf 'You do not have the GPGME development libraries installed.\n'
560         fi
561         errors=$((errors + 1))
562     fi
563     if [ -n "$TEMP_GPG" -a -d "$TEMP_GPG" ]; then
564         rm -rf "$TEMP_GPG"
565     fi
566
567     cat > _check_gmime_cert.c <<EOF
568 #include <stdio.h>
569 #include <gmime/gmime.h>
570
571 int main () {
572     GError *error = NULL;
573     GMimeParser *parser = NULL;
574     GMimeApplicationPkcs7Mime *body = NULL;
575     GMimeSignatureList *sig_list = NULL;
576     GMimeSignature *sig = NULL;
577     GMimeCertificate *cert = NULL;
578     GMimeObject *output = NULL;
579     int len;
580
581     g_mime_init ();
582     parser = g_mime_parser_new ();
583     g_mime_parser_init_with_stream (parser, g_mime_stream_file_open("$srcdir/test/corpora/pkcs7/smime-onepart-signed.eml", "r", &error));
584     if (error) return !! fprintf (stderr, "failed to instantiate parser with test/corpora/pkcs7/smime-onepart-signed.eml\n");
585
586     body = GMIME_APPLICATION_PKCS7_MIME(g_mime_message_get_mime_part (g_mime_parser_construct_message (parser, NULL)));
587     if (body == NULL) return !! fprintf (stderr, "did not find a application/pkcs7 message\n");
588
589     sig_list = g_mime_application_pkcs7_mime_verify (body, GMIME_VERIFY_NONE, &output, &error);
590     if (error || output == NULL) return !! fprintf (stderr, "verify failed\n");
591
592     if (sig_list == NULL) return !! fprintf (stderr, "no GMimeSignatureList found\n");
593     len = g_mime_signature_list_length (sig_list);
594     if (len != 1) return !! fprintf (stderr, "expected 1 signature, got %d\n", len);
595     sig = g_mime_signature_list_get_signature (sig_list, 0);
596     if (sig == NULL) return !! fprintf (stderr, "no GMimeSignature found at position 0\n");
597     cert = g_mime_signature_get_certificate (sig);
598     if (cert == NULL) return !! fprintf (stderr, "no GMimeCertificate found\n");
599 #ifdef CHECK_VALIDITY
600     GMimeValidity validity = g_mime_certificate_get_id_validity (cert);
601     if (validity != GMIME_VALIDITY_FULL) return !! fprintf (stderr, "Got validity %d, expected %d\n", validity, GMIME_VALIDITY_FULL);
602 #endif
603 #ifdef CHECK_EMAIL
604     const char *email = g_mime_certificate_get_email (cert);
605     if (! email) return !! fprintf (stderr, "no email returned");
606     if (email[0] == '<') return 2;
607 #endif
608     return 0;
609 }
610 EOF
611
612     # see https://github.com/jstedfast/gmime/pull/90
613     # should be fixed in GMime in 3.2.7, but some distros might patch
614     printf "Checking for GMime X.509 certificate validity... "
615
616     if ! TEMP_GPG=$(mktemp -d "${TMPDIR:-/tmp}/notmuch.XXXXXX"); then
617         printf 'No.\nCould not make tempdir for testing X.509 certificate validity support.\n'
618         errors=$((errors + 1))
619     elif ${CC} -DCHECK_VALIDITY ${CFLAGS} ${gmime_cflags} _check_gmime_cert.c ${gmime_ldflags} -o _check_x509_validity \
620             && echo disable-crl-checks > "$TEMP_GPG/gpgsm.conf" \
621             && echo "4D:E0:FF:63:C0:E9:EC:01:29:11:C8:7A:EE:DA:3A:9A:7F:6E:C1:0D S" >> "$TEMP_GPG/trustlist.txt" \
622             && GNUPGHOME=${TEMP_GPG} gpgsm --batch --quiet --import < "$srcdir"/test/smime/ca.crt
623     then
624         if GNUPGHOME=${TEMP_GPG} ./_check_x509_validity; then
625             gmime_x509_cert_validity=1
626             printf "Yes.\n"
627         else
628             gmime_x509_cert_validity=0
629             printf "No.\n"
630             if pkg-config --exists "gmime-3.0 >= 3.2.7"; then
631                 cat <<EOF
632 *** Error: GMime fails to calculate X.509 certificate validity, and
633 is later than 3.2.7, which should have fixed this issue.
634
635 Please follow up on https://github.com/jstedfast/gmime/pull/90 with
636 more details.
637 EOF
638                 errors=$((errors + 1))
639             fi
640         fi
641         printf "Checking whether GMime emits email addresses with angle brackets... "
642         if ${CC} -DCHECK_EMAIL ${CFLAGS} ${gmime_cflags} _check_gmime_cert.c ${gmime_ldflags} -o _check_email &&
643                 GNUPGHOME=${TEMP_GPG} ./_check_email; then
644             gmime_emits_angle_brackets=0
645             printf "No.\n"
646         else
647             gmime_emits_angle_brackets=1
648             printf "Yes.\n"
649         fi
650     else
651         printf 'No.\nFailed to set up gpgsm for testing X.509 certificate validity support.\n'
652         errors=$((errors + 1))
653     fi
654     if [ -n "$TEMP_GPG" -a -d "$TEMP_GPG" ]; then
655         rm -rf "$TEMP_GPG"
656     fi
657
658     # see https://dev.gnupg.org/T3464
659     # there are problems verifying signatures when decrypting with session keys with GPGME 1.13.0 and 1.13.1
660     printf "Checking signature verification when decrypting using session keys... "
661
662     cat > _verify_sig_with_session_key.c <<EOF
663 #include <stdio.h>
664 #include <gmime/gmime.h>
665
666 int main () {
667     GError *error = NULL;
668     GMimeParser *parser = NULL;
669     GMimeMultipartEncrypted *body = NULL;
670     GMimeDecryptResult *result = NULL;
671     GMimeSignatureList *sig_list = NULL;
672     GMimeSignature *sig = NULL;
673     GMimeObject *output = NULL;
674     GMimeSignatureStatus status;
675     int len;
676
677     g_mime_init ();
678     parser = g_mime_parser_new ();
679     g_mime_parser_init_with_stream (parser, g_mime_stream_file_open("$srcdir/test/corpora/crypto/encrypted-signed.eml", "r", &error));
680     if (error) return !! fprintf (stderr, "failed to instantiate parser with test/corpora/pkcs7/smime-onepart-signed.eml\n");
681
682     body = GMIME_MULTIPART_ENCRYPTED(g_mime_message_get_mime_part (g_mime_parser_construct_message (parser, NULL)));
683     if (body == NULL) return !! fprintf (stderr, "did not find a multipart/encrypted message\n");
684
685     output = g_mime_multipart_encrypted_decrypt (body, GMIME_DECRYPT_NONE, "9:9E1CDF53BBF794EA34F894B5B68E1E56FB015EA69F81D2A5EAB7F96C7B65783E", &result, &error);
686     if (error || output == NULL) return !! fprintf (stderr, "decrypt failed\n");
687
688     sig_list = g_mime_decrypt_result_get_signatures (result);
689     if (sig_list == NULL) return !! fprintf (stderr, "sig_list is NULL\n");
690
691     if (sig_list == NULL) return !! fprintf (stderr, "no GMimeSignatureList found\n");
692     len = g_mime_signature_list_length (sig_list);
693     if (len != 1) return !! fprintf (stderr, "expected 1 signature, got %d\n", len);
694     sig = g_mime_signature_list_get_signature (sig_list, 0);
695     if (sig == NULL) return !! fprintf (stderr, "no GMimeSignature found at position 0\n");
696     status = g_mime_signature_get_status (sig);
697     if (status & GMIME_SIGNATURE_STATUS_KEY_MISSING) return !! fprintf (stderr, "signature status contains KEY_MISSING (see https://dev.gnupg.org/T3464)\n");
698
699     return 0;
700 }
701 EOF
702     if ! TEMP_GPG=$(mktemp -d "${TMPDIR:-/tmp}/notmuch.XXXXXX"); then
703         printf 'No.\nCould not make tempdir for testing signature verification when decrypting with session keys.\n'
704         errors=$((errors + 1))
705     elif ${CC} ${CFLAGS} ${gmime_cflags} _verify_sig_with_session_key.c ${gmime_ldflags} -o _verify_sig_with_session_key \
706             && GNUPGHOME=${TEMP_GPG} gpg --batch --quiet --import < "$srcdir"/test/openpgp4-secret-key.asc \
707             && rm -f ${TEMP_GPG}/private-keys-v1.d/*.key
708     then
709         if GNUPGHOME=${TEMP_GPG} ./_verify_sig_with_session_key; then
710             gmime_verify_with_session_key=1
711             printf "Yes.\n"
712         else
713             gmime_verify_with_session_key=0
714             printf "No.\n"
715             cat <<EOF
716 *** Error: GMime fails to verify signatures when decrypting with a session key.
717
718 This is most likely due to a buggy version of GPGME, which should be fixed in 1.13.2 or later.
719 See https://dev.gnupg.org/T3464 for more details.
720 EOF
721         fi
722     else
723         printf 'No.\nFailed to set up gpg for testing signature verification while decrypting with a session key.\n'
724         errors=$((errors + 1))
725     fi
726     if [ -n "$TEMP_GPG" -a -d "$TEMP_GPG" ]; then
727         rm -rf "$TEMP_GPG"
728     fi
729 else
730     have_gmime=0
731     printf "No.\n"
732     errors=$((errors + 1))
733 fi
734
735 # GMime already depends on Glib >= 2.12, but we use at least one Glib
736 # function that only exists as of 2.22, (g_array_unref)
737 printf "Checking for Glib development files (>= 2.22)... "
738 have_glib=0
739 if pkg-config --exists 'glib-2.0 >= 2.22'; then
740     printf "Yes.\n"
741     have_glib=1
742     # these are included in gmime cflags and ldflags
743     # glib_cflags=$(pkg-config --cflags glib-2.0)
744     # glib_ldflags=$(pkg-config --libs glib-2.0)
745 else
746     printf "No.\n"
747     errors=$((errors + 1))
748 fi
749
750 if ! pkg-config --exists zlib; then
751   ${CC} -o compat/gen_zlib_pc "$srcdir"/compat/gen_zlib_pc.c >/dev/null 2>&1 &&
752   compat/gen_zlib_pc > compat/zlib.pc &&
753   PKG_CONFIG_PATH=${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}compat &&
754   export PKG_CONFIG_PATH
755   rm -f compat/gen_zlib_pc
756 fi
757
758 printf "Checking for zlib (>= 1.2.5.2)... "
759 have_zlib=0
760 if pkg-config --atleast-version=1.2.5.2 zlib; then
761     printf "Yes.\n"
762     have_zlib=1
763     zlib_cflags=$(pkg-config --cflags zlib)
764     zlib_ldflags=$(pkg-config --libs zlib)
765 else
766     printf "No.\n"
767     errors=$((errors + 1))
768 fi
769
770 printf "Checking for talloc development files... "
771 if pkg-config --exists talloc; then
772     printf "Yes.\n"
773     have_talloc=1
774     talloc_cflags=$(pkg-config --cflags talloc)
775     talloc_ldflags=$(pkg-config --libs talloc)
776 else
777     printf "No.\n"
778     have_talloc=0
779     talloc_cflags=
780     errors=$((errors + 1))
781 fi
782
783 printf "Checking for bash... "
784 if command -v ${BASHCMD} > /dev/null; then
785     have_bash=1
786     bash_absolute=$(command -v ${BASHCMD})
787     printf "Yes (%s).\n" "$bash_absolute"
788 else
789     have_bash=0
790     bash_absolute=
791     printf "No. (%s not found)\n" "${BASHCMD}"
792 fi
793
794 printf "Checking for perl... "
795 if command -v ${PERL} > /dev/null; then
796     have_perl=1
797     perl_absolute=$(command -v ${PERL})
798     printf "Yes (%s).\n" "$perl_absolute"
799 else
800     have_perl=0
801     perl_absolute=
802     printf "No. (%s not found)\n" "${PERL}"
803 fi
804
805 printf "Checking for python... "
806 have_python=0
807
808 for name in ${PYTHON} python3 python python2; do
809     if command -v $name > /dev/null; then
810         have_python=1
811         python=$name
812         printf "Yes (%s).\n" "$name"
813         break
814     fi
815 done
816
817 if [ $have_python -eq 0 ]; then
818     printf "No.\n"
819     errors=$((errors + 1))
820 fi
821
822 have_python3=0
823 if [ $have_python -eq 1 ]; then
824     printf "Checking for python3 (>= 3.5)..."
825     if "$python" -c 'import sys, sysconfig; assert sys.version_info >= (3,5)'; >/dev/null 2>&1; then
826         printf "Yes.\n"
827         have_python3=1
828     else
829         printf "No (will not install CFFI-based python bindings).\n"
830     fi
831 fi
832
833 have_python3_dev=0
834 if [ $have_python3 -eq 1 ]; then
835     printf "Checking for python3 version ..."
836     python3_version=$("$python" -c 'import sysconfig; print(sysconfig.get_python_version());')
837     printf "(%s)\n" $python3_version
838
839     printf "Checking for python $python3_version development files..."
840     if pkg-config --exists "python-$python3_version"; then
841         have_python3_dev=1
842         printf "Yes.\n"
843     else
844         have_python3_dev=0
845         printf "No (will not install CFFI-based python bindings).\n"
846     fi
847 fi
848
849 have_python3_cffi=0
850 have_python3_pytest=0
851 if [ $have_python3_dev -eq 1 ]; then
852     printf "Checking for python3 cffi and setuptools... "
853     if "$python" -c 'import cffi,setuptools; cffi.FFI().verify()' >/dev/null 2>&1; then
854         printf "Yes.\n"
855         have_python3_cffi=1
856         WITH_PYTHON_DOCS=1
857     else
858         WITH_PYTHON_DOCS=0
859         printf "No (will not install CFFI-based python bindings).\n"
860     fi
861     rm -rf __pycache__  # cffi.FFI().verify() uses this space
862
863     printf "Checking for python3 pytest (>= 3.0)... "
864     conf=$(mktemp)
865     printf "[pytest]\nminversion=3.0\n" > $conf
866     if "$python" -m pytest -c $conf --version >/dev/null 2>&1; then
867         printf "Yes.\n"
868         have_python3_pytest=1
869     else
870         printf "No (will not test CFFI-based python bindings).\n"
871     fi
872     rm -f $conf
873 fi
874
875 printf "Checking for valgrind development files... "
876 if pkg-config --exists valgrind; then
877     printf "Yes.\n"
878     have_valgrind=1
879     valgrind_cflags=$(pkg-config --cflags valgrind)
880 else
881     printf "No (but that's fine).\n"
882     have_valgrind=0
883     valgrind_cflags=
884 fi
885
886 printf "Checking for bash-completion (>= 1.90)... "
887 if pkg-config --atleast-version=1.90 bash-completion; then
888     printf "Yes.\n"
889 else
890     printf "No (will not install bash completion).\n"
891     WITH_BASH=0
892 fi
893
894 printf "Checking for sfsexp... "
895 if pkg-config --exists sfsexp; then
896     printf "Yes.\n"
897     have_sfsexp=1
898     sfsexp_cflags=$(pkg-config --cflags sfsexp)
899     sfsexp_ldflags=$(pkg-config --libs sfsexp)
900 else
901     printf "No (will not enable s-expression queries).\n"
902     have_sfsexp=0
903     sfsexp_cflags=
904     sfsexp_ldflags=
905 fi
906
907 if [ -z "${EMACSLISPDIR-}" ]; then
908     EMACSLISPDIR="\$(prefix)/share/emacs/site-lisp"
909 fi
910
911 if [ -z "${EMACSETCDIR-}" ]; then
912     EMACSETCDIR="\$(prefix)/share/emacs/site-lisp"
913 fi
914
915 if [ $WITH_EMACS = "1" ]; then
916     printf "Checking if emacs (>= 25) is available... "
917     if emacs --quick --batch --eval '(if (< emacs-major-version 25) (kill-emacs 1))' > /dev/null 2>&1; then
918         printf "Yes.\n"
919     else
920         printf "No (disabling emacs related parts of build)\n"
921         WITH_EMACS=0
922     fi
923 fi
924
925 have_doxygen=0
926 if [ $WITH_API_DOCS = "1" ] ; then
927     printf "Checking if doxygen is available... "
928     if command -v doxygen > /dev/null; then
929         printf "Yes.\n"
930         have_doxygen=1
931     else
932         printf "No (so will not install api docs)\n"
933     fi
934 fi
935
936 have_ruby_dev=0
937 if [ $WITH_RUBY = "1" ] ; then
938     printf "Checking for ruby development files... "
939     if ${RUBY} -e "require 'mkmf'"> /dev/null 2>&1; then
940         printf "Yes.\n"
941         have_ruby_dev=1
942     else
943         printf "No (skipping ruby bindings)\n"
944     fi
945 fi
946
947 have_sphinx=0
948 have_makeinfo=0
949 have_install_info=0
950 if [ $WITH_DOCS = "1" ] ; then
951     printf "Checking if sphinx is available and supports nroff output... "
952     if command -v sphinx-build > /dev/null && ${python} -m sphinx.writers.manpage > /dev/null 2>&1 ; then
953         printf "Yes.\n"
954         have_sphinx=1
955     else
956         printf "No (so will not install man pages).\n"
957     fi
958     printf "Checking if makeinfo is available... "
959     if command -v makeinfo > /dev/null; then
960         printf "Yes.\n"
961         have_makeinfo=1
962     else
963         printf "No (so will not build info pages).\n"
964     fi
965     printf "Checking if install-info is available... "
966     if command -v install-info > /dev/null; then
967         printf "Yes.\n"
968         have_install_info=1
969     else
970         printf "No (so will not install info pages).\n"
971     fi
972 fi
973
974 if [ $WITH_DESKTOP = "1" ]; then
975     printf "Checking if desktop-file-install is available... "
976     if command -v desktop-file-install > /dev/null; then
977         printf "Yes.\n"
978     else
979         printf "No (so will not install .desktop file).\n"
980         WITH_DESKTOP=0
981     fi
982 fi
983
984 printf "Checking for cppcheck... "
985 if command -v cppcheck > /dev/null; then
986     have_cppcheck=1
987     printf "Yes.\n"
988 else
989     have_cppcheck=0
990     printf "No.\n"
991 fi
992
993 libdir_in_ldconfig=0
994
995 printf "Checking which platform we are on... "
996 uname=$(uname)
997 if [ $uname = "Darwin" ] ; then
998     printf "Mac OS X.\n"
999     platform=MACOSX
1000     linker_resolves_library_dependencies=0
1001 elif [ $uname = "SunOS" ] ; then
1002     printf "Solaris.\n"
1003     platform=SOLARIS
1004     linker_resolves_library_dependencies=0
1005 elif [ $uname = "FreeBSD" ] ; then
1006     printf "FreeBSD.\n"
1007     platform=FREEBSD
1008     linker_resolves_library_dependencies=0
1009 elif [ $uname = "OpenBSD" ] ; then
1010     printf "OpenBSD.\n"
1011     platform=OPENBSD
1012     linker_resolves_library_dependencies=0
1013 elif [ $uname = "Linux" ] || [ $uname = "GNU" ] ; then
1014     printf "%s\n" "$uname"
1015     platform="$uname"
1016     linker_resolves_library_dependencies=1
1017
1018     printf "Checking for %s in ldconfig... " "$libdir_expanded"
1019     ldconfig_paths=$(/sbin/ldconfig -N -X -v 2>/dev/null | sed -n -e 's,^\(/.*\):\( (.*)\)\?$,\1,p')
1020     # Separate ldconfig_paths only on newline (not on any potential
1021     # embedded space characters in any filenames). Note, we use a
1022     # literal newline in the source here rather than something like:
1023     #
1024     #   IFS=$(printf '\n')
1025     #
1026     # because the shell's command substitution deletes any trailing newlines.
1027     IFS="
1028 "
1029     for path in $ldconfig_paths; do
1030         if [ "$path" -ef "$libdir_expanded" ]; then
1031             libdir_in_ldconfig=1
1032         fi
1033     done
1034     IFS=$DEFAULT_IFS
1035     if [ "$libdir_in_ldconfig" = '0' ]; then
1036         printf "No (will set RPATH)\n"
1037     else
1038         printf "Yes\n"
1039     fi
1040 else
1041     printf "Unknown.\n"
1042     platform="$uname"
1043     linker_resolves_library_dependencies=0
1044     cat <<EOF
1045
1046 *** Warning: Unknown platform. Notmuch might or might not build correctly.
1047
1048 EOF
1049 fi
1050
1051 if [ $errors -gt 0 ]; then
1052     cat <<EOF
1053
1054 *** Error: The dependencies of notmuch could not be satisfied. You will
1055 need to install the following packages before being able to compile
1056 notmuch:
1057
1058 EOF
1059     if [ $have_python -eq 0 ]; then
1060         echo "  python interpreter"
1061     fi
1062     if [ $have_xapian -eq 0 ]; then
1063         echo "  Xapian library (>= version 1.4.0, including development files such as headers)"
1064         echo "  https://xapian.org/"
1065     fi
1066     if [ $have_zlib -eq 0 ]; then
1067         echo "  zlib library (>= version 1.2.5.2, including development files such as headers)"
1068         echo "  https://zlib.net/"
1069         echo
1070     fi
1071     if [ $have_gmime -eq 0 ]; then
1072         echo "  GMime library >= $GMIME_MINVER"
1073         echo "  (including development files such as headers)"
1074         echo "  https://github.com/jstedfast/gmime/"
1075         echo
1076     fi
1077     if [ $have_glib -eq 0 ]; then
1078         echo "  Glib library >= 2.22 (including development files such as headers)"
1079         echo "  https://ftp.gnome.org/pub/gnome/sources/glib/"
1080         echo
1081     fi
1082     if [ $have_talloc -eq 0 ]; then
1083         echo "  The talloc library (including development files such as headers)"
1084         echo "  https://talloc.samba.org/"
1085         echo
1086     fi
1087     cat <<EOF
1088 With any luck, you're using a modern, package-based operating system
1089 that has all of these packages available in the distribution. In that
1090 case a simple command will install everything you need. For example:
1091
1092 On Debian and similar systems:
1093
1094         sudo apt-get install libxapian-dev libgmime-3.0-dev libtalloc-dev zlib1g-dev
1095
1096 Or on Fedora and similar systems:
1097
1098         sudo dnf install xapian-core-devel gmime30-devel libtalloc-devel zlib-devel
1099
1100 On other systems, similar commands can be used, but the details of the
1101 package names may be different.
1102
1103 EOF
1104     if [ $have_pkg_config -eq 0 ]; then
1105 cat <<EOF
1106 Note: the pkg-config program is not available. This configure script
1107 uses pkg-config to find the compilation flags required to link against
1108 the various libraries needed by notmuch. It's possible you simply need
1109 to install pkg-config with a command such as:
1110
1111         sudo apt-get install pkg-config
1112 Or:
1113         sudo dnf install pkgconfig
1114
1115 But if pkg-config is not available for your system, then you will need
1116 to modify the configure script to manually set the cflags and ldflags
1117 variables to the correct values to link against each library in each
1118 case that pkg-config could not be used to determine those values.
1119
1120 EOF
1121     fi
1122 cat <<EOF
1123 When you have installed the necessary dependencies, you can run
1124 configure again to ensure the packages can be found, or simply run
1125 "make" to compile notmuch.
1126
1127 EOF
1128     exit 1
1129 fi
1130
1131 printf "Checking for canonicalize_file_name... "
1132 if ${CC} -o compat/have_canonicalize_file_name "$srcdir"/compat/have_canonicalize_file_name.c > /dev/null 2>&1
1133 then
1134     printf "Yes.\n"
1135     have_canonicalize_file_name=1
1136 else
1137     printf "No (will use our own instead).\n"
1138     have_canonicalize_file_name=0
1139 fi
1140 rm -f compat/have_canonicalize_file_name
1141
1142
1143 printf "Checking for getline... "
1144 if ${CC} -o compat/have_getline "$srcdir"/compat/have_getline.c > /dev/null 2>&1
1145 then
1146     printf "Yes.\n"
1147     have_getline=1
1148 else
1149     printf "No (will use our own instead).\n"
1150     have_getline=0
1151 fi
1152 rm -f compat/have_getline
1153
1154 printf "Checking for strcasestr... "
1155 if ${CC} -o compat/have_strcasestr "$srcdir"/compat/have_strcasestr.c > /dev/null 2>&1
1156 then
1157     printf "Yes.\n"
1158     have_strcasestr=1
1159 else
1160     printf "No (will use our own instead).\n"
1161     have_strcasestr=0
1162 fi
1163 rm -f compat/have_strcasestr
1164
1165 printf "Checking for strsep... "
1166 if ${CC} -o compat/have_strsep "$srcdir"/compat/have_strsep.c > /dev/null 2>&1
1167 then
1168     printf "Yes.\n"
1169     have_strsep="1"
1170 else
1171     printf "No (will use our own instead).\n"
1172     have_strsep="0"
1173 fi
1174 rm -f compat/have_strsep
1175
1176 printf "Checking for timegm... "
1177 if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
1178 then
1179     printf "Yes.\n"
1180     have_timegm="1"
1181 else
1182     printf "No (will use our own instead).\n"
1183     have_timegm="0"
1184 fi
1185 rm -f compat/have_timegm
1186
1187 cat <<EOF > _time_t.c
1188 #include <time.h>
1189 #include <assert.h>
1190 static_assert(sizeof(time_t) >= 8, "sizeof(time_t) < 8");
1191 EOF
1192
1193 printf "Checking for 64 bit time_t... "
1194 if ${CC} -c _time_t.c -o /dev/null
1195 then
1196     printf "Yes.\n"
1197     have_64bit_time_t=1
1198 else
1199     printf "No.\n"
1200     have_64bit_time_t=0
1201 fi
1202
1203 printf "Checking for dirent.d_type... "
1204 if ${CC} -o compat/have_d_type "$srcdir"/compat/have_d_type.c > /dev/null 2>&1
1205 then
1206     printf "Yes.\n"
1207     have_d_type="1"
1208 else
1209     printf "No (will use stat instead).\n"
1210     have_d_type="0"
1211 fi
1212 rm -f compat/have_d_type
1213
1214 printf "Checking for standard version of getpwuid_r... "
1215 if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
1216 then
1217     printf "Yes.\n"
1218     std_getpwuid=1
1219 else
1220     printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
1221     std_getpwuid=0
1222 fi
1223 rm -f compat/check_getpwuid
1224
1225 printf "Checking for standard version of asctime_r... "
1226 if ${CC} -o compat/check_asctime "$srcdir"/compat/check_asctime.c > /dev/null 2>&1
1227 then
1228     printf "Yes.\n"
1229     std_asctime=1
1230 else
1231     printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
1232     std_asctime=0
1233 fi
1234 rm -f compat/check_asctime
1235
1236 printf "Checking for rpath support... "
1237 if [ $WITH_RPATH = "1" ] && ${CC} -Wl,--enable-new-dtags -Wl,-rpath,/tmp/ -o minimal minimal.c >/dev/null 2>&1
1238 then
1239     printf "Yes.\n"
1240     rpath_ldflags="-Wl,--enable-new-dtags -Wl,-rpath,\$(libdir)"
1241 else
1242     printf "No (nothing to worry about).\n"
1243     rpath_ldflags=""
1244 fi
1245
1246 printf "Checking for -Wl,--as-needed... "
1247 if ${CC} -Wl,--as-needed -o minimal minimal.c >/dev/null 2>&1
1248 then
1249     printf "Yes.\n"
1250     as_needed_ldflags="-Wl,--as-needed"
1251 else
1252     printf "No (nothing to worry about).\n"
1253     as_needed_ldflags=""
1254 fi
1255
1256 printf "Checking for -Wl,--no-undefined... "
1257 if ${CC} -Wl,--no-undefined -o minimal minimal.c >/dev/null 2>&1
1258 then
1259     printf "Yes.\n"
1260     no_undefined_ldflags="-Wl,--no-undefined"
1261 else
1262     printf "No (nothing to worry about).\n"
1263     no_undefined_ldflags=""
1264 fi
1265
1266 WARN_CXXFLAGS=""
1267 printf "Checking for available C++ compiler warning flags... "
1268 for flag in -Wall -Wextra -Wwrite-strings; do
1269     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
1270     then
1271         WARN_CXXFLAGS="${WARN_CXXFLAGS}${WARN_CXXFLAGS:+ }${flag}"
1272     fi
1273 done
1274 printf "\n\t%s\n" "${WARN_CXXFLAGS}"
1275
1276 WARN_CFLAGS="${WARN_CXXFLAGS}"
1277 printf "Checking for available C compiler warning flags... "
1278 for flag in -Wmissing-declarations; do
1279     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
1280     then
1281         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
1282     fi
1283 done
1284 printf "\n\t%s\n" "${WARN_CFLAGS}"
1285
1286 rm -f minimal minimal.c _time_t.c _libversion.c _libversion _libversion.sh _check_session_keys.c _check_session_keys _check_gmime_cert.c _check_x509_validity _check_email \
1287    _verify_sig_with_session_key.c _verify_sig_with_session_key
1288
1289 # construct the Makefile.config
1290 cat > Makefile.config <<EOF
1291 # This Makefile.config was automatically generated by the ./configure
1292 # script of notmuch. If the configure script identified anything
1293 # incorrectly, then you can edit this file to try to correct things,
1294 # but be warned that if configure is run again it will destroy your
1295 # changes, (and this could happen by simply calling "make" if the
1296 # configure script is updated).
1297
1298 # The top-level directory for the source, (the directory containing
1299 # the configure script). This may be different than the build
1300 # directory (the current directory at the time configure was run).
1301 srcdir = ${srcdir}
1302 NOTMUCH_SRCDIR = ${NOTMUCH_SRCDIR}
1303 NOTMUCH_BUILDDIR = ${NOTMUCH_BUILDDIR}
1304
1305 # subdirectories to build
1306 subdirs = ${subdirs}
1307
1308 configure_options = $@
1309
1310 # We use vpath directives (rather than the VPATH variable) since the
1311 # VPATH variable matches targets as well as prerequisites, (which is
1312 # not useful since then a target left-over from a srcdir build would
1313 # cause a target to not be built in the non-srcdir build).
1314 #
1315 # Also, we don't use a single "vpath % \$(srcdir)" here because we
1316 # don't want the vpath to trigger for our emacs lisp compilation,
1317 # (unless we first find a way to convince emacs to build the .elc
1318 # target in a directory other than the directory of the .el
1319 # prerequisite). In the meantime, we're actually copying in the .el
1320 # files, (which is quite ugly).
1321 vpath %.c \$(srcdir)
1322 vpath %.cc \$(srcdir)
1323 vpath Makefile.% \$(srcdir)
1324 vpath %.py \$(srcdir)
1325 vpath %.rst \$(srcdir)
1326
1327 # Library versions (used to make SONAME)
1328 # The major version of the library interface. This will control the soname.
1329 # As such, this number must be incremented for any incompatible change to
1330 # the library interface, (such as the deletion of an API or a major
1331 # semantic change that breaks formerly functioning code).
1332 #
1333 LIBNOTMUCH_VERSION_MAJOR = ${libnotmuch_version_major}
1334
1335 # The minor version of the library interface. This should be incremented at
1336 # the time of release for any additions to the library interface,
1337 # (and when it is incremented, the release version of the library should
1338 #  be reset to 0).
1339 LIBNOTMUCH_VERSION_MINOR = ${libnotmuch_version_minor}
1340
1341 # The release version the library interface. This should be incremented at
1342 # the time of release if there have been no changes to the interface, (but
1343 # simply compatible changes to the implementation).
1344 LIBNOTMUCH_VERSION_RELEASE = ${libnotmuch_version_release}
1345
1346 # These are derived from the VERSION macros in lib/notmuch.h so
1347 # if you have to change them, something is wrong.
1348
1349 # The C compiler to use
1350 CC = ${CC}
1351
1352 # The C++ compiler to use
1353 CXX = ${CXX}
1354
1355 # Command to execute emacs from Makefiles
1356 EMACS = emacs --quick
1357
1358 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
1359 CFLAGS = ${CFLAGS}
1360
1361 # Default FLAGS for C preprocessor (can be overridden by user such as "make CPPFLAGS=-I/usr/local/include")
1362 CPPFLAGS = ${CPPFLAGS}
1363
1364 # Default FLAGS for C++ compiler (can be overridden by user such as "make CXXFLAGS=-g")
1365 CXXFLAGS = ${CXXFLAGS}
1366
1367 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
1368 LDFLAGS = ${LDFLAGS}
1369
1370 # Flags to enable warnings when using the C++ compiler
1371 WARN_CXXFLAGS=${WARN_CXXFLAGS}
1372
1373 # Flags to enable warnings when using the C compiler
1374 WARN_CFLAGS=${WARN_CFLAGS}
1375
1376 # Name of python interpreter
1377 PYTHON = ${python}
1378
1379 # Name of ruby interpreter
1380 RUBY = ${RUBY}
1381
1382 # The prefix to which notmuch should be installed
1383 # Note: If you change this value here, be sure to ensure that the
1384 # LIBDIR_IN_LDCONFIG value below is still set correctly.
1385 prefix = ${PREFIX}
1386
1387 # The directory to which libraries should be installed
1388 # Note: If you change this value here, be sure to ensure that the
1389 # LIBDIR_IN_LDCONFIG value below is still set correctly.
1390 libdir = ${LIBDIR:=\$(prefix)/lib}
1391
1392 # Whether libdir is in a path configured into ldconfig
1393 LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
1394
1395 # The directory to which header files should be installed
1396 includedir = ${INCLUDEDIR:=\$(prefix)/include}
1397
1398 # The directory to which man pages should be installed
1399 mandir = ${MANDIR:=\$(prefix)/share/man}
1400
1401 # The directory to which man pages should be installed
1402 infodir = ${INFODIR:=\$(prefix)/share/info}
1403
1404 # The directory to which read-only (configuration) files should be installed
1405 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
1406
1407 # The directory to which emacs lisp files should be installed
1408 emacslispdir=${EMACSLISPDIR}
1409
1410 # The directory to which emacs miscellaneous (machine-independent) files should
1411 # be installed
1412 emacsetcdir=${EMACSETCDIR}
1413
1414 # Whether bash exists, and if so where
1415 HAVE_BASH = ${have_bash}
1416 BASH_ABSOLUTE = ${bash_absolute}
1417
1418 # Whether perl exists, and if so where
1419 HAVE_PERL = ${have_perl}
1420 PERL_ABSOLUTE = ${perl_absolute}
1421
1422 # Whether there's a sphinx-build binary available for building documentation
1423 HAVE_SPHINX=${have_sphinx}
1424
1425 # Whether there's a makeinfo binary available for building info format documentation
1426 HAVE_MAKEINFO=${have_makeinfo}
1427
1428 # Whether there's an install-info binary available for installing info format documentation
1429 HAVE_INSTALL_INFO=${have_install_info}
1430
1431 # Whether there's a doxygen binary available for building api documentation
1432 HAVE_DOXYGEN=${have_doxygen}
1433
1434 # The directory to which desktop files should be installed
1435 desktop_dir = \$(prefix)/share/applications
1436
1437 # The directory to which bash completions files should be installed
1438 bash_completion_dir = ${BASHCOMPLETIONDIR:=\$(prefix)/share/bash-completion/completions}
1439
1440 # The directory to which zsh completions files should be installed
1441 zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/site-functions}
1442
1443 # Whether the canonicalize_file_name function is available (if not, then notmuch will
1444 # build its own version)
1445 HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}
1446
1447 # Whether the cppcheck static checker is available
1448 HAVE_CPPCHECK = ${have_cppcheck}
1449
1450 # Whether the getline function is available (if not, then notmuch will
1451 # build its own version)
1452 HAVE_GETLINE = ${have_getline}
1453
1454 # Are the ruby development files (and ruby) available? If not skip
1455 # building/testing ruby bindings.
1456 HAVE_RUBY_DEV = ${have_ruby_dev}
1457
1458 # Is the python cffi package available?
1459 HAVE_PYTHON3_CFFI = ${have_python3_cffi}
1460
1461 # Is the python pytest package available?
1462 HAVE_PYTHON3_PYTEST = ${have_python3_pytest}
1463
1464 # Whether the strcasestr function is available (if not, then notmuch will
1465 # build its own version)
1466 HAVE_STRCASESTR = ${have_strcasestr}
1467
1468 # Whether the strsep function is available (if not, then notmuch will
1469 # build its own version)
1470 HAVE_STRSEP = ${have_strsep}
1471
1472 # Whether the timegm function is available (if not, then notmuch will
1473 # build its own version)
1474 HAVE_TIMEGM = ${have_timegm}
1475
1476 # Whether struct dirent has d_type (if not, then notmuch will use stat)
1477 HAVE_D_TYPE = ${have_d_type}
1478
1479 # Whether to have Xapian retry lock
1480 HAVE_XAPIAN_DB_RETRY_LOCK = ${WITH_RETRY_LOCK}
1481
1482 # Whether the getpwuid_r function is standards-compliant
1483 # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
1484 # to enable the standards-compliant version -- needed for Solaris)
1485 STD_GETPWUID = ${std_getpwuid}
1486
1487 # Whether the asctime_r function is standards-compliant
1488 # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
1489 # to enable the standards-compliant version -- needed for Solaris)
1490 STD_ASCTIME = ${std_asctime}
1491
1492 # Supported platforms (so far) are: LINUX, MACOSX, SOLARIS, FREEBSD, OPENBSD
1493 PLATFORM = ${platform}
1494
1495 # Whether the linker will automatically resolve the dependency of one
1496 # library on another (if not, then linking a binary requires linking
1497 # directly against both)
1498 LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}
1499
1500 # Flags needed to compile and link against Xapian
1501 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
1502 XAPIAN_LDFLAGS = ${xapian_ldflags}
1503
1504 # Flags needed to compile and link against GMime
1505 GMIME_CFLAGS = ${gmime_cflags}
1506 GMIME_LDFLAGS = ${gmime_ldflags}
1507
1508 # Flags needed to compile and link against zlib
1509 ZLIB_CFLAGS = ${zlib_cflags}
1510 ZLIB_LDFLAGS = ${zlib_ldflags}
1511
1512 # Flags needed to compile and link against talloc
1513 TALLOC_CFLAGS = ${talloc_cflags}
1514 TALLOC_LDFLAGS = ${talloc_ldflags}
1515
1516 # Flags needed to have linker set rpath attribute
1517 RPATH_LDFLAGS = ${rpath_ldflags}
1518
1519 # Flags needed to have linker link only to necessary libraries
1520 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
1521
1522 # Flags to have the linker flag undefined symbols in object files
1523 NO_UNDEFINED_LDFLAGS = ${no_undefined_ldflags}
1524
1525 # Whether valgrind header files are available
1526 HAVE_VALGRIND = ${have_valgrind}
1527
1528 # And if so, flags needed at compile time for valgrind macros
1529 VALGRIND_CFLAGS = ${valgrind_cflags}
1530
1531 # Whether the sfsexp library is available
1532 HAVE_SFSEXP = ${have_sfsexp}
1533
1534 # And if so, flags needed at compile/link time for sfsexp
1535 SFSEXP_CFLAGS = ${sfsexp_cflags}
1536 SFSEXP_LDFLAGS = ${sfsexp_ldflags}
1537
1538 # Support for emacs
1539 WITH_EMACS = ${WITH_EMACS}
1540
1541 # Support for desktop file
1542 WITH_DESKTOP = ${WITH_DESKTOP}
1543
1544 # Support for bash completion
1545 WITH_BASH = ${WITH_BASH}
1546
1547 # Support for zsh completion
1548 WITH_ZSH = ${WITH_ZSH}
1549
1550 # Combined flags for compiling and linking against all of the above
1551 COMMON_CONFIGURE_CFLAGS = \\
1552         \$(GMIME_CFLAGS) \$(TALLOC_CFLAGS) \$(ZLIB_CFLAGS)      \\
1553         -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \$(VALGRIND_CFLAGS)   \\
1554         -DHAVE_SFSEXP=\$(HAVE_SFSEXP) \$(SFSEXP_CFLAGS)         \\
1555         -DHAVE_GETLINE=\$(HAVE_GETLINE)                         \\
1556         -DWITH_EMACS=\$(WITH_EMACS)                             \\
1557         -DHAVE_CANONICALIZE_FILE_NAME=\$(HAVE_CANONICALIZE_FILE_NAME) \\
1558         -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)                   \\
1559         -DHAVE_STRSEP=\$(HAVE_STRSEP)                           \\
1560         -DHAVE_TIMEGM=\$(HAVE_TIMEGM)                           \\
1561         -DHAVE_D_TYPE=\$(HAVE_D_TYPE)                           \\
1562         -DSTD_GETPWUID=\$(STD_GETPWUID)                         \\
1563         -DSTD_ASCTIME=\$(STD_ASCTIME)                           \\
1564         -DSILENCE_XAPIAN_DEPRECATION_WARNINGS                   \\
1565         -DHAVE_XAPIAN_DB_RETRY_LOCK=\$(HAVE_XAPIAN_DB_RETRY_LOCK)
1566
1567 CONFIGURE_CFLAGS = \$(COMMON_CONFIGURE_CFLAGS)
1568
1569 CONFIGURE_CXXFLAGS = \$(COMMON_CONFIGURE_CFLAGS) \$(XAPIAN_CXXFLAGS)
1570
1571 CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(XAPIAN_LDFLAGS) \$(SFSEXP_LDFLAGS)
1572 EOF
1573
1574 # construct the sh.config
1575 cat > sh.config <<EOF
1576 # This sh.config was automatically generated by the ./configure
1577 # script of notmuch.
1578
1579 NOTMUCH_SRCDIR='${NOTMUCH_SRCDIR}'
1580
1581 # Flags needed to compile and link against Xapian
1582 NOTMUCH_XAPIAN_CXXFLAGS="${xapian_cxxflags}"
1583 NOTMUCH_XAPIAN_LDFLAGS="${xapian_ldflags}"
1584
1585 # Whether to have Xapian retry lock
1586 NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK=${WITH_RETRY_LOCK}
1587
1588 # Flags needed to compile and link against GMime
1589 NOTMUCH_GMIME_CFLAGS="${gmime_cflags}"
1590 NOTMUCH_GMIME_LDFLAGS="${gmime_ldflags}"
1591
1592 # Whether GMime can verify X.509 certificate validity
1593 NOTMUCH_GMIME_X509_CERT_VALIDITY=${gmime_x509_cert_validity}
1594
1595 # Whether GMime emits addresses with angle brackets (with <>)
1596 NOTMUCH_GMIME_EMITS_ANGLE_BRACKETS=${gmime_emits_angle_brackets}
1597
1598 # Whether GMime can verify signatures when decrypting with a session key:
1599 NOTMUCH_GMIME_VERIFY_WITH_SESSION_KEY=${gmime_verify_with_session_key}
1600
1601 # Flags needed to compile and link against zlib
1602 NOTMUCH_ZLIB_CFLAGS="${zlib_cflags}"
1603 NOTMUCH_ZLIB_LDFLAGS="${zlib_ldflags}"
1604
1605 # Does the C compiler support the sanitizers
1606 NOTMUCH_HAVE_ASAN=${have_asan}
1607 NOTMUCH_HAVE_TSAN=${have_tsan}
1608
1609 # do we have man pages?
1610 NOTMUCH_HAVE_MAN=$((have_sphinx))
1611
1612 # Whether bash exists, and if so where
1613 NOTMUCH_HAVE_BASH=${have_bash}
1614 NOTMUCH_BASH_ABSOLUTE=${bash_absolute}
1615
1616 # Whether time_t is 64 bits (or more)
1617 NOTMUCH_HAVE_64BIT_TIME_T=${have_64bit_time_t}
1618
1619 # Whether perl exists, and if so where
1620 NOTMUCH_HAVE_PERL=${have_perl}
1621 NOTMUCH_PERL_ABSOLUTE=${perl_absolute}
1622
1623 # Name of python interpreter
1624 NOTMUCH_PYTHON=${python}
1625
1626 # Name of ruby interpreter
1627 NOTMUCH_RUBY=${RUBY}
1628
1629 # Are the ruby development files (and ruby) available? If not skip
1630 # building/testing ruby bindings.
1631 NOTMUCH_HAVE_RUBY_DEV=${have_ruby_dev}
1632
1633 # Is the python cffi package available?
1634 NOTMUCH_HAVE_PYTHON3_CFFI=${have_python3_cffi}
1635
1636 # Is the python pytest package available?
1637 NOTMUCH_HAVE_PYTHON3_PYTEST=${have_python3_pytest}
1638
1639 # Is the sfsexp library available?
1640 NOTMUCH_HAVE_SFSEXP=${have_sfsexp}
1641
1642 # And if so, flags needed at compile/link time for sfsexp
1643 NOTMUCH_SFSEXP_CFLAGS="${sfsexp_cflags}"
1644 NOTMUCH_SFSEXP_LDFLAGS="${sfsexp_ldflags}"
1645
1646 # Platform we are run on
1647 PLATFORM=${platform}
1648 EOF
1649
1650 {
1651     echo "# Generated by configure, run from doc/conf.py"
1652     if [ $WITH_EMACS = "1" ]; then
1653         echo "tags.add('WITH_EMACS')"
1654     fi
1655     if [ $WITH_PYTHON_DOCS = "1" ]; then
1656         echo "tags.add('WITH_PYTHON')"
1657     fi
1658     printf "rsti_dir = '%s'\n" "$(cd emacs && pwd -P)"
1659 } > sphinx.config
1660
1661 cat > bindings/python-cffi/_notmuch_config.py <<EOF
1662 # _notmuch_config.py was automatically generated by the configure
1663 # script in the root of the notmuch source tree.
1664 NOTMUCH_VERSION_FILE='${NOTMUCH_SRCDIR}/version.txt'
1665 NOTMUCH_INCLUDE_DIR='${NOTMUCH_SRCDIR}/lib'
1666 NOTMUCH_LIB_DIR='${NOTMUCH_SRCDIR}/lib'
1667 EOF
1668
1669 # Finally, after everything configured, inform the user how to continue.
1670 cat <<EOF
1671
1672 All required packages were found. You may now run the following
1673 commands to compile and install notmuch:
1674
1675         make
1676         sudo make install
1677
1678 EOF