2004-09-14 Marcus Brinkmann <marcus@g10code.de>
[gpgme.git] / configure.ac
1 # configure.in for GPGME
2 # Copyright (C) 2000 Werner Koch (dd9jn)
3 # Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
4
5 # This file is part of GPGME.
6
7 # GPGME is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # GPGME is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20  
21 # (Process this file with autoconf to produce a configure script.)
22
23 AC_PREREQ(2.57)
24 min_automake_version="1.7.6"
25
26 # Version number: Remember to change it immediately *after* a release.
27 AC_INIT(gpgme, 0.9.1-cvs, [bug-gpgme@gnupg.org])
28 # LT Version numbers, remember to change them just *before* a release.
29 #   (Code changed:                      REVISION++)
30 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
31 #   (Interfaces added:                  AGE++)
32 #   (Interfaces removed/changed:        AGE=0)
33 #
34 LIBGPGME_LT_CURRENT=14
35 # Subtract 2 from this value if you want to make the LFS transition an
36 # ABI break.  [Note to self: Remove this comment with the next regular break.]
37 LIBGPGME_LT_AGE=3
38 LIBGPGME_LT_REVISION=0
39
40 # If the API is changed in an incompatible way: increment the next counter.
41 GPGME_CONFIG_API_VERSION=1
42
43 NEED_GPG_VERSION=1.2.2
44 NEED_GPGSM_VERSION=1.9.6
45 ##############################################
46 AC_PREREQ(2.52)
47 AC_REVISION($Revision$)
48
49 PACKAGE=$PACKAGE_NAME
50 VERSION=$PACKAGE_VERSION
51
52 AC_CONFIG_SRCDIR(gpgme/gpgme.h)
53 AC_CONFIG_MACRO_DIR(m4)
54 AM_CONFIG_HEADER(config.h)
55 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
56 AM_MAINTAINER_MODE
57 AC_CANONICAL_HOST
58
59 AH_VERBATIM([_GNU_SOURCE],
60 [/* Enable GNU extensions on systems that have them.  */
61 #ifndef _GNU_SOURCE
62 # define _GNU_SOURCE
63 #endif])
64
65 AH_VERBATIM([_REENTRANT],
66 [/* To allow the use of GPGME in multithreaded programs we have to use
67   special features from the library.
68   IMPORTANT: gpgme is not yet fully reentrant and you should use it
69   only from one thread.  */
70 #ifndef _REENTRANT
71 # define _REENTRANT 1
72 #endif])
73
74
75 AC_PROG_CC
76
77
78 AC_SUBST(LIBGPGME_LT_CURRENT)
79 AC_SUBST(LIBGPGME_LT_AGE)
80 AC_SUBST(LIBGPGME_LT_REVISION)
81 AC_DEFINE_UNQUOTED(NEED_GPG_VERSION, "$NEED_GPG_VERSION",
82                                      [Min. needed GnuPG version.])
83 AC_DEFINE_UNQUOTED(NEED_GPGSM_VERSION, "$NEED_GPGSM_VERSION",
84                                        [Min. needed GPGSM version.])
85
86 AC_SUBST(PACKAGE)
87 AC_SUBST(VERSION)
88 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
89 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
90
91 # Don't default to build static libs.
92 AC_DISABLE_STATIC
93 AC_PROG_LIBTOOL
94
95 # For now we hardcode the use of version scripts.  It would be better
96 # to write a test for this or even implement this within libtool.
97 have_ld_version_script=no
98 case "${host}" in
99     *-*-linux*)
100         have_ld_version_script=yes
101         ;;
102     *-*-gnu*)
103         have_ld_version_script=yes
104         ;;
105 esac
106 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
107
108 GPG_DEFAULT=no
109 GPGSM_DEFAULT=no
110 component_system=None
111 case "${host}" in
112     *-*-mingw32* | i?86-emx-os2 | i?86-*-os2*emx | i?86-*-msdosdjgpp* )
113         # special stuff for Windoze NT
114         # OS/2 with the EMX environment
115         # DOS with the DJGPP environment
116         AC_DEFINE(HAVE_DRIVE_LETTERS, ,
117                   [Defined if we run on some of the PCDOS like systems (DOS,
118                    Windoze, OS/2) with special properties like no file modes.])
119         AC_DEFINE(HAVE_DOSISH_SYSTEM, ,
120                   [Defined if the filesystem uses driver letters.])
121         have_dosish_system=yes
122         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
123         # XXX Assuan is not supported in this configuration.
124         #GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
125         #component_system='COM+'
126         ;;
127     *)
128         AC_CHECK_PTH(1.2.0,,,no,have_pth=yes)
129         if test "$have_pth" = yes; then
130           AC_DEFINE(HAVE_PTH, ,[Define if we have Pth.])
131           CFLAGS="$CFLAGS $PTH_CFLAGS"
132         fi
133         AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
134         if test "$have_pthread" = yes; then
135           AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
136         fi
137
138         # XXX: Probably use exec-prefix here?
139 #       GPG_DEFAULT='/usr/bin/gpg'
140 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
141         ;;
142 esac
143 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = "yes")
144 AM_CONDITIONAL(HAVE_PTH, test "$have_pth" = "yes")
145 AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
146
147
148 # Checks for header files.
149 AC_CHECK_HEADERS(sys/select.h)
150
151
152 # Type checks.
153 AC_CHECK_SIZEOF(unsigned int)
154 AC_SYS_LARGEFILE
155 AC_TYPE_OFF_T
156
157 # Checks for compiler features.
158 if test "$GCC" = yes; then
159     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
160 fi
161
162
163 # Checks for library functions.
164 AC_FUNC_FSEEKO
165
166 AC_REPLACE_FUNCS(stpcpy)
167
168 AC_REPLACE_FUNCS(vasprintf)
169 if test "$ac_cv_func_vasprintf" != yes; then
170   GNUPG_CHECK_VA_COPY
171 fi
172
173 # Try to find a thread-safe version of getenv().
174 have_thread_safe_getenv=no
175 jm_GLIBC21
176 if test $GLIBC21 = yes; then
177   have_thread_safe_getenv=yes
178 fi
179 if test $have_thread_safe_getenv = yes; then
180   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
181 fi
182 have_getenv_r=no
183 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
184 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
185   AC_MSG_WARN([
186 ***
187 *** getenv() is not thread-safe and getenv_r() does not exist
188 ***])
189 fi
190
191 # For converting time strings to seconds since Epoch, we need the timegm
192 # function.
193 AC_CHECK_FUNCS(timegm)
194 if test "$ac_cv_func_timegm" != yes; then
195   AC_MSG_WARN([
196 ***
197 *** timegm() not available - a non-thread-safe kludge will be used
198 *** and the TZ variable might be changed at runtime.
199 ***])
200 fi
201
202 # Checking for libgpg-error.
203 AM_PATH_GPG_ERROR(0.5,, AC_MSG_ERROR([libgpg-error was not found]))
204 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
205           [The default error source for GPGME.])
206
207
208
209 # Checks for system services
210 NO_OVERRIDE=no
211 AC_ARG_WITH(gpg,
212             AC_HELP_STRING([--with-gpg=PATH], [use GnuPG binary at PATH]),
213             GPG=$withval, NO_OVERRIDE=yes)
214 if test "$NO_OVERRIDE" = "yes" || test "$GPG" = "yes"; then
215   GPG=
216   NO_OVERRIDE=yes
217   if test "$cross_compiling" != "yes"; then
218     AC_PATH_PROG(GPG, gpg)
219   fi
220   if test -z "$GPG"; then
221     GPG="$GPG_DEFAULT"
222   fi
223 fi
224 if test "$GPG" = no; then
225   if test "$NO_OVERRIDE" = "yes"; then
226     if test "$cross_compiling" != "yes"; then
227       AC_MSG_WARN([
228 ***
229 *** Could not find GnuPG, install GnuPG or use --with-gpg=PATH to enable it
230 ***])
231     else
232       AC_MSG_ERROR([
233 ***
234 *** Can not determine path to GnuPG when cross-compiling, use --with-gpg=PATH
235 ***])
236     fi
237   fi
238 else
239   AC_DEFINE_UNQUOTED(GPG_PATH, "$GPG", [Path to the GnuPG binary.])
240   AC_SUBST(GPG)
241 fi
242 dnl Check for GnuPG version requirement.
243 GPG_VERSION=unknown
244 ok=no
245 if test "$cross_compiling" != "yes" -a -n "$GPG" -a -r "$GPG"; then
246   AC_MSG_CHECKING(for GnuPG >= $NEED_GPG_VERSION)
247   req_major=`echo $NEED_GPG_VERSION | \
248              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
249   req_minor=`echo $NEED_GPG_VERSION | \
250              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
251   req_micro=`echo $NEED_GPG_VERSION | \
252              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
253   gpg_version=`$GPG --version | grep ^gpg`
254   major=`echo $gpg_version | \
255          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
256   minor=`echo $gpg_version | \
257          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
258   micro=`echo $gpg_version | \
259          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
260   GPG_VERSION=`echo $gpg_version | sed 's/^gpg (GnuPG) //'`
261
262   if test "$major" -gt "$req_major"; then
263     ok=yes
264   else
265     if test "$major" -eq "$req_major"; then
266       if test "$minor" -gt "$req_minor"; then
267         ok=yes
268       else
269         if test "$minor" -eq "$req_minor"; then
270           if test "$micro" -ge "$req_micro"; then
271             ok=yes
272           fi
273         fi
274       fi
275     fi
276   fi
277   if test "$ok" = "yes"; then
278     AC_MSG_RESULT(yes)
279   else
280     AC_MSG_WARN([GnuPG must be at least version $NEED_GPG_VERSION])
281   fi
282 fi
283 AM_CONDITIONAL(RUN_GPG_TESTS, [test "$ok" = "yes" ])
284 AC_SUBST(GPG_PATH)
285
286 NO_OVERRIDE=no
287 AC_ARG_WITH(gpgsm,
288             AC_HELP_STRING([--with-gpgsm=PATH], [use GpgSM binary at PATH]),
289             GPGSM=$withval, NO_OVERRIDE=yes)
290 if test "$NO_OVERRIDE" = "yes" || test "$GPGSM" = "yes"; then
291   GPGSM=
292   NO_OVERRIDE=yes
293   if test "$cross_compiling" != "yes"; then
294     AC_PATH_PROG(GPGSM, gpgsm)
295   fi
296   if test -z "$GPGSM"; then
297     GPGSM="$GPGSM_DEFAULT"
298   fi
299 fi
300 if test "$GPGSM" = no; then
301   if test "$NO_OVERRIDE" = "yes"; then
302     if test "$cross_compiling" != "yes"; then
303       AC_MSG_WARN([
304 ***
305 *** Could not find GpgSM, install GpgSM or use --with-gpgsm=PATH to enable it
306 ***])
307     else
308       AC_MSG_ERROR([
309 ***
310 *** Can not determine path to GpgSM when cross-compiling, use --with-gpgsm=PATH
311 ***])
312     fi
313   fi
314 else
315   AC_DEFINE_UNQUOTED(GPGSM_PATH, "$GPGSM", [Path to the GPGSM binary.])
316   AC_SUBST(GPGSM)
317 fi
318 AM_CONDITIONAL(HAVE_GPGSM, [test -n "$GPGSM"])
319 dnl Check for GPGSM version requirement.
320 GPGSM_VERSION=unknown
321 ok=no
322 if test "$cross_compiling" != "yes" -a -n "$GPGSM" -a -r "$GPGSM"; then
323   AC_MSG_CHECKING(for GPGSM >= $NEED_GPGSM_VERSION)
324   req_major=`echo $NEED_GPGSM_VERSION | \
325              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
326   req_minor=`echo $NEED_GPGSM_VERSION | \
327              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
328   req_micro=`echo $NEED_GPGSM_VERSION | \
329              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
330   gpgsm_version=`$GPGSM --version | grep ^gpgsm`
331   major=`echo $gpgsm_version | \
332          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
333   minor=`echo $gpgsm_version | \
334          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
335   micro=`echo $gpgsm_version | \
336          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
337   GPGSM_VERSION=`echo $gpgsm_version | sed 's/^gpg (GnuPG) //'`
338
339   if test "$major" -gt "$req_major"; then
340     ok=yes
341   else
342     if test "$major" -eq "$req_major"; then
343       if test "$minor" -gt "$req_minor"; then
344         ok=yes
345       else
346         if test "$minor" -eq "$req_minor"; then
347           if test "$micro" -ge "$req_micro"; then
348             ok=yes
349           fi
350         fi
351       fi
352     fi
353   fi
354   if test "$ok" = "yes"; then
355     AC_MSG_RESULT(yes)
356   else
357     AC_MSG_WARN([GPGSM must be at least version $NEED_GPGSM_VERSION])
358   fi
359 fi
360 AM_CONDITIONAL(RUN_GPGSM_TESTS, [test "$ok" = "yes" ])
361
362 # FIXME: Only build if supported.
363 AM_CONDITIONAL(BUILD_ASSUAN, test "$GPGSM" != "no")
364
365
366 # The assuan code uses funopen but it will also build without it.  So
367 # test for it.  Frankly, this is not required in gpgme, but thats the
368 # way we handle it in libassuan.
369 AC_CHECK_FUNCS(funopen)
370 if test $ac_cv_func_funopen != yes; then
371     # No funopen but we can implement that in terms of fopencookie.
372     AC_CHECK_FUNCS(fopencookie)
373     if test $ac_cv_func_fopencookie = yes; then
374         AC_LIBOBJ([funopen])
375     else
376         AC_MSG_WARN([
377 ***
378 *** No implementation of fopencookie or funopen available
379 ***])
380     fi
381 fi
382
383 # More assuan replacement functions.
384 AC_REPLACE_FUNCS(isascii)
385 AC_REPLACE_FUNCS(putc_unlocked)
386 AC_REPLACE_FUNCS(memrchr)
387
388 # More assuan checks.
389 AC_CHECK_HEADERS([sys/uio.h])
390
391 # End of assuan checks.
392
393 AM_CONDITIONAL(BUILD_COMPLUS, test "$component_system" = "COM+")
394
395 # Make the version number in gpgme/gpgme.h the same as the one here.
396 # (this is easier than to have a *.in file just for one substitution)
397 GNUPG_FIX_HDR_VERSION(gpgme/gpgme.h, GPGME_VERSION)
398
399 # Substitution used for gpgme-config 
400 GPGME_CONFIG_LIBS="-lgpgme"
401 GPGME_CONFIG_CFLAGS=""
402 AC_SUBST(GPGME_CONFIG_API_VERSION)
403 AC_SUBST(GPGME_CONFIG_LIBS)
404 AC_SUBST(GPGME_CONFIG_CFLAGS)
405
406 # Frob'da Variables
407 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
408            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
409 AC_SUBST(LTLIBOBJS)
410
411 #
412 # Create config files 
413
414 AC_CONFIG_FILES(Makefile assuan/Makefile gpgme/Makefile
415                 tests/Makefile tests/gpg/Makefile tests/gpgsm/Makefile
416                 doc/Makefile complus/Makefile)
417 AC_CONFIG_FILES(gpgme/gpgme-config, chmod +x gpgme/gpgme-config)
418 AC_OUTPUT
419
420 echo "
421         GPGME v${VERSION} has been configured as follows:
422
423         GnuPG path:    $GPG
424         GnuPG version: $GPG_VERSION, min. $NEED_GPG_VERSION
425
426         GpgSM path:    $GPGSM
427         GpgSM version: $GPGSM_VERSION, min. $NEED_GPGSM_VERSION
428
429         GPGME Pthread: $have_pthread
430         GPGME Pth:     $have_pth
431 "