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