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