]> git.notmuchmail.org Git - notmuch/blob - configure
b1e5f7850135227989833e8731ed62950323bd1d
[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
74 Additional options are accepted for compatibility with other
75 configure-script calling conventions, but don't do anything yet:
76
77         --build=<cpu>-<vendor>-<os>     Currently ignored
78
79 EOF
80 }
81
82 # Parse command-line options
83 for option; do
84     if [ "${option}" = '--help' ] ; then
85         usage
86         exit 0
87     elif [ "${option%%=*}" = '--prefix' ] ; then
88         PREFIX="${option#*=}"
89     elif [ "${option%%=*}" = '--libdir' ] ; then
90         LIBDIR="${option#*=}"
91     elif [ "${option%%=*}" = '--includedir' ] ; then
92         INCLUDEDIR="${option#*=}"
93     elif [ "${option%%=*}" = '--mandir' ] ; then
94         MANDIR="${option#*=}"
95     elif [ "${option%%=*}" = '--build' ] ; then
96         build_option="${option#*=}"
97         case ${build_option} in
98             *-*-*) ;;
99             *)
100                 echo "Unrecognized value for --build option: ${build_option}"
101                 echo "Should be: <cpu>-<vendor>-<os>"
102                 echo "See:"
103                 echo "  $0 --help"
104                 echo ""
105                 exit 1
106         esac
107         build_cpu=${build_option%%-*}
108         build_option=${build_option#*-}
109         build_vendor=${build_option%%-*}
110         build_os=${build_option#*-}
111     else
112         echo "Unrecognized option: ${option}"
113         echo "See:"
114         echo "  $0 --help"
115         echo ""
116         exit 1
117     fi
118 done
119
120 cat <<EOF
121 Welcome to Notmuch, a system for indexing, searching and tagging your email.
122
123 We hope that the process of building and installing notmuch is quick
124 and smooth so that you can soon be reading and processing your email
125 more efficiently than ever.
126
127 If anything goes wrong in the configure process, you can override any
128 decisions it makes by manually editing the Makefile.config file that
129 it creates. Also please do as much as you can to figure out what could
130 be different on your machine compared to those of the notmuch
131 developers. Then, please email those details to the Notmuch list
132 (notmuch@notmuchmail.org) so that we can hopefully make future
133 versions of notmuch easier for you to use.
134
135 We'll now investigate your system to verify that all required
136 dependencies are available:
137
138 EOF
139
140 errors=0
141
142 if pkg-config --version > /dev/null 2>&1; then
143     have_pkg_config=1
144 else
145     have_pkg_config=0
146 fi
147
148 printf "Checking for Xapian development files... "
149 have_xapian=0
150 for xapian_config in ${XAPIAN_CONFIG}; do
151     if ${xapian_config} --version > /dev/null 2>&1; then
152         printf "Yes.\n"
153         have_xapian=1
154         xapian_cxxflags=$(${xapian_config} --cxxflags)
155         xapian_ldflags=$(${xapian_config} --libs)
156         break
157     fi
158 done
159 if [ ${have_xapian} = "0" ]; then
160     printf "No.\n"
161     errors=$((errors + 1))
162 fi
163
164 printf "Checking for GMime 2.4 development files... "
165 if pkg-config --modversion gmime-2.4 > /dev/null 2>&1; then
166     printf "Yes.\n"
167     have_gmime=1
168     gmime_cflags=$(pkg-config --cflags gmime-2.4)
169     gmime_ldflags=$(pkg-config --libs gmime-2.4)
170 else
171     printf "No.\n"
172     have_gmime=0
173     errors=$((errors + 1))
174 fi
175
176 printf "Checking for talloc development files... "
177 if pkg-config --modversion talloc > /dev/null 2>&1; then
178     printf "Yes.\n"
179     have_talloc=1
180     talloc_cflags=$(pkg-config --cflags talloc)
181     talloc_ldflags=$(pkg-config --libs talloc)
182 else
183     printf "No.\n"
184     have_talloc=0
185     talloc_cflags=
186     errors=$((errors + 1))
187 fi
188
189 printf "Checking for valgrind development files... "
190 if pkg-config --modversion valgrind > /dev/null 2>&1; then
191     printf "Yes.\n"
192     have_valgrind=1
193     valgrind_cflags=$(pkg-config --cflags valgrind)
194 else
195     printf "No (but that's fine).\n"
196     have_valgrind=0
197 fi
198
199 if pkg-config --modversion emacs > /dev/null 2>&1; then
200     emacs_lispdir=$(pkg-config emacs --variable sitepkglispdir)
201 else
202     emacs_lispdir='$(prefix)/share/emacs/site-lisp'
203 fi
204
205 printf "Checking if emacs is available... "
206 if emacs --quick --batch > /dev/null 2>&1; then
207     printf "Yes.\n"
208     have_emacs=1
209 else
210     printf "No (so will not byte-compile emacs code)\n"
211     have_emacs=0
212 fi
213
214 if [ $errors -gt 0 ]; then
215     cat <<EOF
216
217 *** Error: The dependencies of notmuch could not be satisfied. You will
218 need to install the following packages before being able to compile
219 notmuch:
220
221 EOF
222     if [ $have_xapian -eq 0 ]; then
223         echo "  Xapian library (including development files such as headers)"
224         echo "  http://xapian.org/"
225     fi
226     if [ $have_gmime -eq 0 ]; then
227         echo "  GMime 2.4 library (including development files such as headers)"
228         echo "  http://spruce.sourceforge.net/gmime/"
229     fi
230     if [ $have_talloc -eq 0 ]; then
231         echo "  The talloc library (including development files such as headers)"
232         echo "  http://talloc.samba.org/"
233     fi
234     cat <<EOF
235
236 With any luck, you're using a modern, package-based operating system
237 that has all of these packages available in the distribution. In that
238 case a simple command will install everything you need. For example:
239
240 On Debian and similar systems:
241
242         sudo apt-get install libxapian-dev libgmime-2.4-dev libtalloc-dev
243
244 Or on Fedora and similar systems:
245
246         sudo yum install xapian-core-devel gmime-devel libtalloc-devel
247
248 On other systems, similar commands can be used, but the details of the
249 package names may be different.
250
251 EOF
252     if [ $have_pkg_config -eq 0 ]; then
253 cat <<EOF
254 Note: the pkg-config program is not available. This configure script
255 uses pkg-config to find the compilation flags required to link against
256 the various libraries needed by notmuch. It's possible you simply need
257 to install pkg-config with a command such as:
258
259         sudo apt-get install pkg-config
260 Or:
261         sudo yum install pkgconfig
262
263 But if pkg-config is not available for your system, then you will need
264 to modify the configure script to manually set the cflags and ldflags
265 variables to the correct values to link against each library in each
266 case that pkg-config could not be used to determine those values.
267
268 EOF
269     fi
270 cat <<EOF
271 When you have installed the necessary dependencies, you can run
272 configure again to ensure the packages can be found, or simply run
273 "make" to compile notmuch.
274
275 EOF
276     exit 1
277 fi
278
279 printf "Checking for getline... "
280 if ${CC} -o compat/have_getline compat/have_getline.c > /dev/null 2>&1
281 then
282     printf "Yes.\n"
283     have_getline=1
284 else
285     printf "No (will use our own instead).\n"
286     have_getline=0
287 fi
288 rm -f compat/have_getline
289
290 cat <<EOF
291
292 All required packages were found. You may now run the following
293 commands to compile and install notmuch:
294
295         make
296         sudo make install
297
298 EOF
299
300 # construct the Makefile.config
301 cat > Makefile.config <<EOF
302 # This Makefile.config was automatically generated by the ./configure
303 # script of notmuch. If the configure script identified anything
304 # incorrectly, then you can edit this file to try to correct things,
305 # but be warned that if configure is run again it will destroy your
306 # changes, (and this could happen by simply calling "make" if the
307 # configure script is updated).
308
309 # The C compiler to use
310 CC = ${CC}
311
312 # The C++ compiler to use
313 CXX = ${CXX}
314
315 # Command to execute emacs from Makefiles
316 EMACS = emacs --quick
317
318 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
319 CFLAGS = ${CFLAGS}
320
321 # Default FLAGS for C++ compiler (can be overridden by user such as "make CXXFLAGS=-g")
322 CXXFLAGS = ${CXXFLAGS}
323
324 # Flags to enable warnings when using the C++ compiler
325 WARN_CXXFLAGS=-Wall -Wextra -Wwrite-strings -Wswitch-enum
326
327 # Flags to enable warnings when using the C compiler
328 WARN_CFLAGS=\$(WARN_CXXFLAGS) -Wmissing-declarations
329
330 # The prefix to which notmuch should be installed
331 prefix = ${PREFIX}
332
333 # The directory to which libraries should be installed
334 libdir = ${LIBDIR:=\$(prefix)/lib}
335
336 # The directory to which header files should be installed
337 includedir = ${INCLUDEDIR:=\$(prefix)/lib}
338
339 # The directory to which man pages should be installed
340 mandir = ${MANDIR:=\$(prefix)/share/man}
341
342 # The directory to which emacs lisp files should be installed
343 emacs_lispdir=${emacs_lispdir}
344
345 # Whether there's an emacs binary available for byte-compiling
346 HAVE_EMACS = ${have_emacs}
347
348 # The directory to which desktop files should be installed
349 desktop_dir = \$(prefix)/share/applications
350
351 # The directory to which bash completions files should be installed
352 bash_completion_dir = /etc/bash_completion.d
353
354 # The directory to which zsh completions files should be installed
355 zsh_completion_dir = \$(prefix)/share/zsh/functions/Completion/Unix
356
357 # Whether the getline function is available (if not, then notmuch will
358 # build its own version)
359 HAVE_GETLINE = ${have_getline}
360
361 # Flags needed to compile and link against Xapian
362 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
363 XAPIAN_LDFLAGS = ${xapian_ldflags}
364
365 # Flags needed to compile and link against GMime-2.4
366 GMIME_CFLAGS = ${gmime_cflags}
367 GMIME_LDFLAGS = ${gmime_ldflags}
368
369 # Flags needed to compile and link against talloc
370 TALLOC_CFLAGS = ${talloc_cflags}
371 TALLOC_LDFLAGS = ${talloc_ldflags}
372
373 # Whether valgrind header files are available
374 HAVE_VALGRIND = ${have_valgrind}
375
376 # And if so, flags needed at compile time for valgrind macros
377 VALGRIND_CFLAGS = ${valgrind_cflags}
378
379 # Combined flags for compiling and linking against all of the above
380 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
381                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
382                    \$(VALGRIND_CFLAGS)
383 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
384                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
385                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)
386 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
387 EOF