]> git.notmuchmail.org Git - notmuch/blob - configure
1caff940471ea6ed32b1188364e181b2eff920fb
[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 # Set the defaults for values the user can specify with command-line
12 # options.
13 PREFIX=/usr/local
14 LIBDIR=${PREFIX}/lib
15
16 usage ()
17 {
18     cat <<EOF
19 Usage: ./configure [options]...
20
21 This script configures notmuch to build on your system.
22
23 It verifies that dependencies are available, determines flags needed
24 to compile and link against various required libraries, and identifies
25 whether various system functions can be used or if locally-provided
26 replacements will be built instead.
27
28 Finally, it allows you to control various aspects of the build and
29 installation process.
30
31 First, some common variables can specified via environment variables:
32
33         CC              The C compiler to use
34         CFLAGS          Flags to pass to the C compiler
35         CXX             The C++ compiler to use
36         CXXFLAGS        Flags to pass to the C compiler
37         LDFLAGS         Flags to pass when linking
38
39 Each of these values can further be controlled by specifying them
40 later on the "make" command line.
41
42 Other environment variables can be used to control configure itself,
43 (and for which there is no equivalent build-time control):
44
45         XAPIAN_CONFIG   The program to use to determine flags for
46                         compiling and linking against the Xapian
47                         library. [$XAPIAN_CONFIG]
48
49 Additionally, various options can be specified on the configure
50 command line.
51
52         --prefix=PREFIX Install files in PREFIX [$PREFIX]
53         --libdir=LIBDIR Install libraries in LIBDIR [$LIBDIR]
54
55 By default, "make install" will install the resulting program to
56 $PREFIX/bin, documentation to $PREFIX/share, etc. You can
57 specify an installation prefix other than $PREFIX using
58 --prefix, for instance:
59
60         ./configure --prefix=\$HOME
61
62 EOF
63 }
64
65 # Parse command-line options
66 for option; do
67     if [ "${option}" = '--help' ] ; then
68         usage
69         exit 0
70     elif [ "${option%%=*}" = '--prefix' ] ; then
71         PREFIX="${option#*=}"
72     elif [ "${option%%=*}" = '--libdir' ] ; then
73         LIBDIR="${option#*=}"
74     else
75         echo "Unrecognized option: ${option}."
76         echo "See:"
77         echo "  $0 --help"
78         echo ""
79         exit 1
80     fi
81 done
82
83 cat <<EOF
84 Welcome to Notmuch, a system for indexing, searching and tagging your email.
85
86 We hope that the process of building and installing notmuch is quick
87 and smooth so that you can soon be reading and processing your email
88 more efficiently than ever.
89
90 If anything goes wrong in the configure process, you can override any
91 decisions it makes by manually editing the Makefile.config file that
92 it creates. Also please do as much as you can to figure out what could
93 be different on your machine compared to those of the notmuch
94 developers. Then, please email those details to the Notmuch list
95 (notmuch@notmuchmail.org) so that we can hopefully make future
96 versions of notmuch easier for you to use.
97
98 We'll now investigate your system to verify that all required
99 dependencies are available:
100
101 EOF
102
103 errors=0
104
105 if pkg-config --version > /dev/null 2>&1; then
106     have_pkg_config=1
107 else
108     have_pkg_config=0
109 fi
110
111 printf "Checking for Xapian development files... "
112 have_xapian=0
113 for xapian_config in ${XAPIAN_CONFIG}; do
114     if ${xapian_config} --version > /dev/null 2>&1; then
115         printf "Yes.\n"
116         have_xapian=1
117         xapian_cxxflags=$(${xapian_config} --cxxflags)
118         xapian_ldflags=$(${xapian_config} --libs)
119         break
120     fi
121 done
122 if [ ${have_xapian} = "0" ]; then
123     printf "No.\n"
124     errors=$((errors + 1))
125 fi
126
127 printf "Checking for GMime 2.4 development files... "
128 if pkg-config --modversion gmime-2.4 > /dev/null 2>&1; then
129     printf "Yes.\n"
130     have_gmime=1
131     gmime_cflags=$(pkg-config --cflags gmime-2.4)
132     gmime_ldflags=$(pkg-config --libs gmime-2.4)
133 else
134     printf "No.\n"
135     have_gmime=0
136     errors=$((errors + 1))
137 fi
138
139 printf "Checking for talloc development files... "
140 if pkg-config --modversion talloc > /dev/null 2>&1; then
141     printf "Yes.\n"
142     have_talloc=1
143     talloc_cflags=$(pkg-config --cflags talloc)
144     talloc_ldflags=$(pkg-config --libs talloc)
145 else
146     printf "No.\n"
147     have_talloc=0
148     talloc_cflags=
149     errors=$((errors + 1))
150 fi
151
152 printf "Checking for valgrind development files... "
153 if pkg-config --modversion valgrind > /dev/null 2>&1; then
154     printf "Yes.\n"
155     have_valgrind=1
156     valgrind_cflags=$(pkg-config --cflags valgrind)
157 else
158     printf "No (but that's fine).\n"
159     have_valgrind=0
160 fi
161
162 if pkg-config --modversion emacs > /dev/null 2>&1; then
163     emacs_lispdir=$(pkg-config emacs --variable sitepkglispdir)
164 else
165     emacs_lispdir='$(prefix)/share/emacs/site-lisp'
166 fi
167
168 if [ $errors -gt 0 ]; then
169     cat <<EOF
170
171 *** Error: The dependencies of notmuch could not be satisfied. You will
172 need to install the following packages before being able to compile
173 notmuch:
174
175 EOF
176     if [ $have_xapian -eq 0 ]; then
177         echo "  Xapian library (including development files such as headers)"
178         echo "  http://xapian.org/"
179     fi
180     if [ $have_gmime -eq 0 ]; then
181         echo "  GMime 2.4 library (including development files such as headers)"
182         echo "  http://spruce.sourceforge.net/gmime/"
183     fi
184     if [ $have_talloc -eq 0 ]; then
185         echo "  The talloc library (including development files such as headers)"
186         echo "  http://talloc.samba.org/"
187     fi
188     cat <<EOF
189
190 With any luck, you're using a modern, package-based operating system
191 that has all of these packages available in the distribution. In that
192 case a simple command will install everything you need. For example:
193
194 On Debian and similar systems:
195
196         sudo apt-get install libxapian-dev libgmime-2.4-dev libtalloc-dev
197
198 Or on Fedora and similar systems:
199
200         sudo yum install xapian-core-devel gmime-devel libtalloc-devel
201
202 On other systems, similar commands can be used, but the details of the
203 package names may be different.
204
205 EOF
206     if [ $have_pkg_config -eq 0 ]; then
207 cat <<EOF
208 Note: the pkg-config program is not available. This configure script
209 uses pkg-config to find the compilation flags required to link against
210 the various libraries needed by notmuch. It's possible you simply need
211 to install pkg-config with a command such as:
212
213         sudo apt-get install pkg-config
214 Or:
215         sudo yum install pkgconfig
216
217 But if pkg-config is not available for your system, then you will need
218 to modify the configure script to manually set the cflags and ldflags
219 variables to the correct values to link against each library in each
220 case that pkg-config could not be used to determine those values.
221
222 EOF
223     fi
224 cat <<EOF
225 When you have installed the necessary dependencies, you can run
226 configure again to ensure the packages can be found, or simply run
227 "make" to compile notmuch.
228
229 EOF
230     exit 1
231 fi
232
233 printf "Checking for getline... "
234 if ${CC} -o config/have_getline config/have_getline.c > /dev/null 2>&1
235 then
236     printf "Yes.\n"
237     have_getline=1
238 else
239     printf "No (will use our own instead).\n"
240     have_getline=0
241 fi
242 rm -f config/have_getline
243
244 cat <<EOF
245
246 All required packages were found. You may now run the following
247 commands to compile and install notmuch:
248
249         make
250         sudo make install
251
252 EOF
253
254 # construct the Makefile.config
255 cat > Makefile.config <<EOF
256 # This Makefile.config was automatically generated by the ./configure
257 # script of notmuch. If the configure script identified anything
258 # incorrectly, then you can edit this file to try to correct things,
259 # but be warned that if configure is run again it will destroy your
260 # changes, (and this could happen by simply calling "make" if the
261 # configure script is updated).
262
263 # The C compiler to use
264 CC = ${CC}
265
266 # The C++ compiler to use
267 CXX = ${CXX}
268
269 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
270 CFLAGS = ${CFLAGS}
271
272 # Default FLAGS for C++ compiler (can be overridden by user such as "make CXXFLAGS=-g")
273 CXXFLAGS = ${CXXFLAGS}
274
275 # The prefix to which notmuch should be installed
276 prefix = ${PREFIX}
277
278 # The directory to which notmuch libraries should be installed
279 libdir = ${LIBDIR}
280
281 # The directory to which emacs lisp files should be installed
282 emacs_lispdir=${emacs_lispdir}
283
284 # The directory to which desktop files should be installed
285 desktop_dir = \${prefix}/share/applications
286
287 # Whether the getline function is available (if not, then notmuch will
288 # build its own version)
289 HAVE_GETLINE = ${have_getline}
290
291 # Flags needed to compile and link against Xapian
292 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
293 XAPIAN_LDFLAGS = ${xapian_ldflags}
294
295 # Flags needed to compile and link against GMime-2.4
296 GMIME_CFLAGS = ${gmime_cflags}
297 GMIME_LDFLAGS = ${gmime_ldflags}
298
299 # Flags needed to compile and link against talloc
300 TALLOC_CFLAGS = ${talloc_cflags}
301 TALLOC_LDFLAGS = ${talloc_ldflags}
302
303 # Whether valgrind header files are available
304 HAVE_VALGRIND = ${have_valgrind}
305
306 # And if so, flags needed at compile time for valgrind macros
307 VALGRIND_CFLAGS = ${valgrind_cflags}
308
309 # Combined flags for compiling and linking against all of the above
310 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
311                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
312                    \$(VALGRIND_CFLAGS)
313 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
314                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
315                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)
316 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
317 EOF