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