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