Minor glib fix.
[gpgme.git] / configure.ac
1 # configure.ac for GPGME
2 # Copyright (C) 2000 Werner Koch (dd9jn)
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005 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.59)
24 min_automake_version="1.9.3"
25
26 # Version number: Remember to change it immediately *after* a release.
27 #                 Make sure to run  "svn up" before a "make dist".
28 #                 See below for the LT versions.
29 #
30 # The CVS version is usually the next intended release version with
31 # the string "-cvs" appended.  The reason for this is that tests for a
32 # specific feature can already be done under the assumption that the
33 # CVS version is the most recent one in a branch.  To disable the CVS
34 # version for the real release, just comment out the my_iscvs macro.
35 # Note, that we are now using Subversion instead of CVS and append the
36 # SVN revision number to the "cvs" suffix.  To make this most useful
37 # for snapshot releases please do an "svn up" right before recreating
38 # the configure script, so that a proper revision number for all files
39 # is available when running a "make distcheck".
40 m4_define(my_version, [1.1.1])
41 m4_define(my_iscvs, yes)
42 AC_INIT([gpgme], my_version[]m4_ifdef([my_iscvs], [-cvs[]m4_translit(
43                [$Revision$],[Ra-z $:])]),
44                [bug-gpgme@gnupg.org])
45
46 # LT Version numbers, remember to change them just *before* a release.
47 #   (Code changed:                      REVISION++)
48 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
49 #   (Interfaces added:                  AGE++)
50 #   (Interfaces removed/changed:        AGE=0)
51 #
52 LIBGPGME_LT_CURRENT=16
53 # Subtract 2 from this value if you want to make the LFS transition an
54 # ABI break.  [Note to self: Remove this comment with the next regular break.]
55 LIBGPGME_LT_AGE=5
56 LIBGPGME_LT_REVISION=0
57
58 # If the API is changed in an incompatible way: increment the next counter.
59 GPGME_CONFIG_API_VERSION=1
60
61 NEED_GPG_VERSION=1.2.2
62 NEED_GPGSM_VERSION=1.9.6
63 ##############################################
64
65
66 PACKAGE=$PACKAGE_NAME
67 VERSION=$PACKAGE_VERSION
68
69 AC_CONFIG_SRCDIR(gpgme/gpgme.h)
70 dnl FIXME: Enable this with autoconf 2.59.
71 dnl AC_CONFIG_MACRO_DIR(m4)
72 AM_CONFIG_HEADER(config.h)
73 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
74 AM_MAINTAINER_MODE
75 AC_CANONICAL_HOST
76
77 # Enable GNU extensions on systems that have them.
78 AC_GNU_SOURCE
79
80 AH_VERBATIM([_REENTRANT],
81 [/* To allow the use of GPGME in multithreaded programs we have to use
82   special features from the library.
83   IMPORTANT: gpgme is not yet fully reentrant and you should use it
84   only from one thread.  */
85 #ifndef _REENTRANT
86 # define _REENTRANT 1
87 #endif])
88
89 AC_PROG_CC
90
91 AC_SUBST(LIBGPGME_LT_CURRENT)
92 AC_SUBST(LIBGPGME_LT_AGE)
93 AC_SUBST(LIBGPGME_LT_REVISION)
94 AC_DEFINE_UNQUOTED(NEED_GPG_VERSION, "$NEED_GPG_VERSION",
95                                      [Min. needed GnuPG version.])
96 AC_DEFINE_UNQUOTED(NEED_GPGSM_VERSION, "$NEED_GPGSM_VERSION",
97                                        [Min. needed GPGSM version.])
98
99 AC_SUBST(PACKAGE)
100 AC_SUBST(VERSION)
101 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
102 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
103
104 # Don't default to build static libs.
105 AC_DISABLE_STATIC
106 AC_LIBTOOL_WIN32_DLL
107 AC_LIBTOOL_RC
108 AC_PROG_LIBTOOL
109
110 # For now we hardcode the use of version scripts.  It would be better
111 # to write a test for this or even implement this within libtool.
112 have_ld_version_script=no
113 case "${host}" in
114     *-*-linux*)
115         have_ld_version_script=yes
116         ;;
117     *-*-gnu*)
118         have_ld_version_script=yes
119         ;;
120 esac
121 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
122
123 GPG_DEFAULT=no
124 GPGSM_DEFAULT=no
125 component_system=None
126 have_dosish_system=no
127 have_w32_system=no
128 case "${host}" in
129     *-mingw32*)
130         # special stuff for Windoze NT
131         have_dosish_system=yes
132         have_w32_system=yes
133         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
134         # XXX Assuan is not supported in this configuration.
135         #GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
136         #component_system='COM+'
137         ;;
138     *)
139         AC_CHECK_PTH(1.2.0,,,no,have_pth=yes)
140         if test "$have_pth" = yes; then
141           AC_DEFINE(HAVE_PTH, ,[Define if we have Pth.])
142         fi
143         AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
144         if test "$have_pthread" = yes; then
145           AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
146         fi
147
148         # XXX: Probably use exec-prefix here?
149 #       GPG_DEFAULT='/usr/bin/gpg'
150 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
151         ;;
152 esac
153
154 if test "$have_dosish_system" = yes; then
155    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
156              [Defined if we run on some of the PCDOS like systems 
157               (DOS, Windoze. OS/2) with special properties like
158               no file modes])
159 fi
160 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
161
162 if test "$have_w32_system" = yes; then
163    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
164 fi
165 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
166
167 build_w32_glib=no
168 AM_PATH_GLIB_2_0
169 AC_ARG_ENABLE(w32-glib,
170             AC_HELP_STRING([--enable-w32-glib], [build GPGME Glib for W32]),
171             build_w32_glib=$withval)
172 AM_CONDITIONAL(BUILD_W32_GLIB, test "$build_w32_glib" = yes)
173
174 AM_CONDITIONAL(HAVE_PTH, test "$have_pth" = "yes")
175 AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
176
177
178 # Checks for header files.
179 AC_CHECK_HEADERS(sys/select.h)
180
181
182 # Type checks.
183 AC_C_INLINE
184 AC_CHECK_SIZEOF(unsigned int)
185 AC_SYS_LARGEFILE
186 AC_TYPE_OFF_T
187
188 # Checks for compiler features.
189 if test "$GCC" = yes; then
190     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
191     if test "$have_w32_system" = yes; then
192        CFLAGS="$CFLAGS -mms-bitfields"
193     fi
194 fi
195
196
197 # Checks for library functions.
198 AC_FUNC_FSEEKO
199
200 AC_CHECK_FUNCS(stpcpy)
201
202 AC_REPLACE_FUNCS(vasprintf)
203 if test "$ac_cv_func_vasprintf" != yes; then
204   GNUPG_CHECK_VA_COPY
205 fi
206
207 # Try to find a thread-safe version of ttyname().
208 AC_REPLACE_FUNCS(ttyname_r)
209 if test "$ac_cv_func_ttyname_r" != yes; then
210   AC_MSG_WARN([
211 ***
212 *** ttyname() is not thread-safe and ttyname_r() does not exist
213 ***])
214 fi
215
216 # Try to find a thread-safe version of getenv().
217 have_thread_safe_getenv=no
218 jm_GLIBC21
219 if test $GLIBC21 = yes; then
220   have_thread_safe_getenv=yes
221 fi
222 if test $have_thread_safe_getenv = yes; then
223   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
224 fi
225 have_getenv_r=no
226 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
227 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
228   AC_MSG_WARN([
229 ***
230 *** getenv() is not thread-safe and getenv_r() does not exist
231 ***])
232 fi
233
234 # For converting time strings to seconds since Epoch, we need the timegm
235 # function.
236 AC_CHECK_FUNCS(timegm)
237 if test "$ac_cv_func_timegm" != yes; then
238   AC_MSG_WARN([
239 ***
240 *** timegm() not available - a non-thread-safe kludge will be used
241 *** and the TZ variable might be changed at runtime.
242 ***])
243 fi
244
245 # Checking for libgpg-error.
246 AM_PATH_GPG_ERROR(0.5,, AC_MSG_ERROR([libgpg-error was not found]))
247 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
248           [The default error source for GPGME.])
249
250
251
252 # Checks for system services
253 NO_OVERRIDE=no
254 AC_ARG_WITH(gpg,
255             AC_HELP_STRING([--with-gpg=PATH], [use GnuPG binary at PATH]),
256             GPG=$withval, NO_OVERRIDE=yes)
257 if test "$NO_OVERRIDE" = "yes" || test "$GPG" = "yes"; then
258   GPG=
259   NO_OVERRIDE=yes
260   if test "$cross_compiling" != "yes"; then
261     AC_PATH_PROG(GPG, gpg)
262   fi
263   if test -z "$GPG"; then
264     GPG="$GPG_DEFAULT"
265   fi
266 fi
267 if test "$GPG" = no; then
268   if test "$NO_OVERRIDE" = "yes"; then
269     if test "$cross_compiling" != "yes"; then
270       AC_MSG_WARN([
271 ***
272 *** Could not find GnuPG, install GnuPG or use --with-gpg=PATH to enable it
273 ***])
274     else
275       AC_MSG_ERROR([
276 ***
277 *** Can not determine path to GnuPG when cross-compiling, use --with-gpg=PATH
278 ***])
279     fi
280   fi
281 else
282   AC_DEFINE_UNQUOTED(GPG_PATH, "$GPG", [Path to the GnuPG binary.])
283   AC_SUBST(GPG)
284 fi
285 dnl Check for GnuPG version requirement.
286 GPG_VERSION=unknown
287 ok=maybe
288 if test -z "$GPG" -o "x$GPG" = "xno"; then
289   ok=no
290 else
291   if test "$cross_compiling" = "yes"; then
292     AC_MSG_WARN([GnuPG version can not be checked when cross compiling])
293     ok=no
294   else
295     if test ! -x "$GPG"; then
296       AC_MSG_WARN([GnuPG not executable, version check disabled])
297       ok=no
298     fi
299   fi
300 fi
301 if test "$ok" = "maybe"; then
302   AC_MSG_CHECKING(for GnuPG >= $NEED_GPG_VERSION)
303   req_major=`echo $NEED_GPG_VERSION | \
304              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
305   req_minor=`echo $NEED_GPG_VERSION | \
306              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
307   req_micro=`echo $NEED_GPG_VERSION | \
308              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
309   gpg_version=`$GPG --version | grep ^gpg`
310   major=`echo $gpg_version | \
311          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
312   minor=`echo $gpg_version | \
313          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
314   micro=`echo $gpg_version | \
315          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
316   GPG_VERSION=`echo $gpg_version | sed 's/^gpg (GnuPG) //'`
317
318   if test "$major" -gt "$req_major"; then
319     ok=yes
320   else
321     if test "$major" -eq "$req_major"; then
322       if test "$minor" -gt "$req_minor"; then
323         ok=yes
324       else
325         if test "$minor" -eq "$req_minor"; then
326           if test "$micro" -ge "$req_micro"; then
327             ok=yes
328           fi
329         fi
330       fi
331     fi
332   fi
333   if test "$ok" = "yes"; then
334     AC_MSG_RESULT(yes)
335   else
336     AC_MSG_RESULT(no)
337     AC_MSG_WARN([GnuPG must be at least version $NEED_GPG_VERSION])
338   fi
339 fi
340 AM_CONDITIONAL(RUN_GPG_TESTS, test "$ok" = "yes")
341 AC_SUBST(GPG_PATH)
342
343 NO_OVERRIDE=no
344 AC_ARG_WITH(gpgsm,
345             AC_HELP_STRING([--with-gpgsm=PATH], [use GpgSM binary at PATH]),
346             GPGSM=$withval, NO_OVERRIDE=yes)
347 if test "$NO_OVERRIDE" = "yes" || test "$GPGSM" = "yes"; then
348   GPGSM=
349   NO_OVERRIDE=yes
350   if test "$cross_compiling" != "yes"; then
351     AC_PATH_PROG(GPGSM, gpgsm)
352   fi
353   if test -z "$GPGSM"; then
354     GPGSM="$GPGSM_DEFAULT"
355   fi
356 fi
357 if test "$GPGSM" = no; then
358   if test "$NO_OVERRIDE" = "yes"; then
359     if test "$cross_compiling" != "yes"; then
360       AC_MSG_WARN([
361 ***
362 *** Could not find GpgSM, install GpgSM or use --with-gpgsm=PATH to enable it
363 ***])
364     else
365       AC_MSG_ERROR([
366 ***
367 *** Can not determine path to GpgSM when cross-compiling, use --with-gpgsm=PATH
368 ***])
369     fi
370   fi
371 else
372   AC_DEFINE_UNQUOTED(GPGSM_PATH, "$GPGSM", [Path to the GPGSM binary.])
373   AC_DEFINE(ENABLE_GPGSM,1,[Whether GPGSM support is enabled])
374 fi
375 AM_CONDITIONAL(HAVE_GPGSM, test "$GPGSM" != "no")
376
377
378 dnl Check for GPGSM version requirement.
379 GPGSM_VERSION=unknown
380 ok=maybe
381 if test -z "$GPGSM" -o "x$GPGSM" = "xno"; then
382   ok=no
383 else
384   if test "$cross_compiling" = "yes"; then
385     AC_MSG_WARN([GPGSM version can not be checked when cross compiling])
386     ok=no
387   else
388     if test ! -x "$GPGSM"; then
389       AC_MSG_WARN([GPGSM not executable, version check disabled])
390       ok=no
391     fi
392   fi
393 fi
394 if test "$ok" = "maybe"; then
395   AC_MSG_CHECKING(for GPGSM >= $NEED_GPGSM_VERSION)
396   req_major=`echo $NEED_GPGSM_VERSION | \
397              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
398   req_minor=`echo $NEED_GPGSM_VERSION | \
399              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
400   req_micro=`echo $NEED_GPGSM_VERSION | \
401              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
402   gpgsm_version=`$GPGSM --version | grep ^gpgsm`
403   major=`echo $gpgsm_version | \
404          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
405   minor=`echo $gpgsm_version | \
406          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
407   micro=`echo $gpgsm_version | \
408          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
409   GPGSM_VERSION=`echo $gpgsm_version | sed 's/^gpgsm (GnuPG) //'`
410
411   if test "$major" -gt "$req_major"; then
412     ok=yes
413   else
414     if test "$major" -eq "$req_major"; then
415       if test "$minor" -gt "$req_minor"; then
416         ok=yes
417       else
418         if test "$minor" -eq "$req_minor"; then
419           if test "$micro" -ge "$req_micro"; then
420             ok=yes
421           fi
422         fi
423       fi
424     fi
425   fi
426   if test "$ok" = "yes"; then
427     AC_MSG_RESULT(yes)
428   else
429     AC_MSG_RESULT(no)
430     AC_MSG_WARN([GPGSM must be at least version $NEED_GPGSM_VERSION])
431   fi
432 fi
433 AM_CONDITIONAL(RUN_GPGSM_TESTS, test "$ok" = "yes")
434
435 # FIXME: Only build if supported.
436 AM_CONDITIONAL(BUILD_ASSUAN, test "$GPGSM" != "no")
437
438
439 # The assuan code uses funopen but it will also build without it.  So
440 # test for it.  Frankly, this is not required in gpgme, but thats the
441 # way we handle it in libassuan.
442 AC_CHECK_FUNCS(funopen)
443 if test $ac_cv_func_funopen != yes; then
444     # No funopen but we can implement that in terms of fopencookie.
445     AC_CHECK_FUNCS(fopencookie)
446     if test $ac_cv_func_fopencookie = yes; then
447         AC_LIBOBJ([funopen])
448     else
449         AC_MSG_WARN([
450 ***
451 *** No implementation of fopencookie or funopen available
452 ***])
453     fi
454 fi
455
456 # More assuan replacement functions.
457 AC_REPLACE_FUNCS(isascii)
458 AC_REPLACE_FUNCS(putc_unlocked)
459 AC_REPLACE_FUNCS(memrchr)
460
461 # More assuan checks.
462 AC_CHECK_HEADERS([sys/uio.h])
463
464 # End of assuan checks.
465
466 AM_CONDITIONAL(BUILD_COMPLUS, test "$component_system" = "COM+")
467
468 # Make the version number in gpgme/gpgme.h the same as the one here.
469 # (this is easier than to have a *.in file just for one substitution)
470 GNUPG_FIX_HDR_VERSION(gpgme/gpgme.h, GPGME_VERSION)
471
472 # Generate values for the DLL version info
473 changequote(,)dnl 
474 BUILD_REVISION="`echo '$Revision$' | sed 's/[^0-9]//g'`"
475 changequote([,])dnl
476 test -z "$BUILD_REVISION" && BUILD_REVISION="0"
477 if test "$have_w32_system" = yes; then
478     BUILD_TIMESTAMP=`date --iso-8601=minutes`
479     changequote(,)dnl 
480     BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
481     changequote([,])dnl
482     BUILD_FILEVERSION="${BUILD_FILEVERSION}${BUILD_REVISION}"
483 fi
484 AC_SUBST(BUILD_REVISION)
485 AC_SUBST(BUILD_TIMESTAMP)
486 AC_SUBST(BUILD_FILEVERSION)
487
488 # Add a few constants to help porting to W32
489 AH_VERBATIM([SEPCONSTANTS],
490 [
491 /* Separators as used in file names and $PATH. Please note that the
492    string version must not contain more than one character because
493    the using code assumes strlen()==1 */
494 #ifdef HAVE_DOSISH_SYSTEM
495 #define DIRSEP_C '\\\\'
496 #define EXTSEP_C '.'
497 #define DIRSEP_S "\\\\"
498 #define EXTSEP_S "."
499 #define PATHSEP_C ';'
500 #define PATHSEP_S ";"
501 #else
502 #define DIRSEP_C '/'
503 #define EXTSEP_C '.'
504 #define DIRSEP_S "/"
505 #define EXTSEP_S "."
506 #define PATHSEP_C ':'
507 #define PATHSEP_S ":"
508 #endif
509 ])
510
511 AH_BOTTOM([
512 /* Definition of GCC specific attributes.  */
513 #if __GNUC__ > 2 
514 # define GPGME_GCC_A_PURE  __attribute__ ((__pure__))
515 #else
516 # define GPGME_GCC_A_PURE
517 #endif
518 ])
519
520
521 # Substitution used for gpgme-config 
522 GPGME_CONFIG_LIBS="-lgpgme"
523 GPGME_CONFIG_CFLAGS=""
524 AC_SUBST(GPGME_CONFIG_API_VERSION)
525 AC_SUBST(GPGME_CONFIG_LIBS)
526 AC_SUBST(GPGME_CONFIG_CFLAGS)
527
528 # Frob'da Variables
529 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
530            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
531 AC_SUBST(LTLIBOBJS)
532
533 #
534 # Create config files 
535
536 AC_CONFIG_FILES(Makefile assuan/Makefile gpgme/Makefile
537                 tests/Makefile tests/gpg/Makefile tests/gpgsm/Makefile
538                 doc/Makefile complus/Makefile
539                 gpgme/versioninfo.rc)
540 AC_CONFIG_FILES(gpgme/gpgme-config, chmod +x gpgme/gpgme-config)
541 AC_OUTPUT
542
543 echo "
544         GPGME v${VERSION} has been configured as follows:
545
546         GnuPG path:    $GPG
547         GnuPG version: $GPG_VERSION, min. $NEED_GPG_VERSION
548
549         GpgSM path:    $GPGSM
550         GpgSM version: $GPGSM_VERSION, min. $NEED_GPGSM_VERSION
551
552         GPGME Pthread: $have_pthread
553         GPGME Pth:     $have_pth
554 "