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