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