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