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