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