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