Insert platform dependent typedefs into gpgme.h
[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, 2007, 2008,
4 #               2009, 2010, 2011  g10 Code GmbH
5 #
6 # This file is part of GPGME.
7 #
8 # GPGME is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as
10 # published by the Free Software Foundation; either version 2.1 of the
11 # License, or (at your option) any later version.
12 #
13 # GPGME is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
16 # Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21
22 # (Process this file with autoconf to produce a configure script.)
23 AC_PREREQ(2.59)
24 min_automake_version="1.10"
25
26 # Version number: Remember to change it immediately *after* a release.
27 #                 Make sure to run  "svn up" and "./autogen.sh --force"
28 #                  before a "make dist".  See below for the LT versions.
29 #
30 # The SVN version is usually the next intended release version with
31 # the string "-svnNNN" appended.  The reason for this is that tests for a
32 # specific feature can already be done under the assumption that the
33 # SVN version is the most recent one in a branch.  To disable the SVN
34 # version for the real release, set the my_issvn macro to no.
35 m4_define(my_version, [1.3.1])
36 m4_define(my_issvn, [yes])
37
38 m4_define([svn_revision], m4_esyscmd([printf "%d" $( (svn info 2>/dev/null \
39             || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')]))
40 m4_define([git_revision], m4_esyscmd([git branch -v 2>/dev/null \
41           | awk '/^\* / {printf "%s",$3}']))
42 AC_INIT([gpgme],
43         [my_version[]m4_if(my_issvn,[yes],
44         [m4_if(git_revision,[],[-svn[]svn_revision],[-git[]git_revision])])],
45         [bug-gpgme@gnupg.org])
46
47
48 # LT Version numbers, remember to change them just *before* a release.
49 #   (Code changed:                      REVISION++)
50 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
51 #   (Interfaces added:                  AGE++)
52 #   (Interfaces removed/changed:        AGE=0)
53 #
54 LIBGPGME_LT_CURRENT=18
55 # Subtract 2 from this value if you want to make the LFS transition an
56 # ABI break.  [Note to self: Remove this comment with the next regular break.]
57 LIBGPGME_LT_AGE=7
58 LIBGPGME_LT_REVISION=0
59
60 # If the API is changed in an incompatible way: increment the next counter.
61 GPGME_CONFIG_API_VERSION=1
62 ##############################################
63
64 NEED_LIBASSUAN_API=2
65 NEED_LIBASSUAN_VERSION=2.0.2
66
67
68 m4_define([git_brevis],m4_esyscmd(printf "%u" 0x[]m4_substr(git_revision,0,4)))
69 BUILD_REVISION=m4_if(git_revision,[],[svn_revision],[git_brevis])
70 PACKAGE=$PACKAGE_NAME
71 VERSION=$PACKAGE_VERSION
72
73 AC_CONFIG_SRCDIR(src/gpgme.h.in)
74 dnl FIXME: Enable this with autoconf 2.59.
75 dnl AC_CONFIG_MACRO_DIR(m4)
76 AM_CONFIG_HEADER(config.h)
77 AC_CONFIG_MACRO_DIR([m4])
78 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
79 AM_MAINTAINER_MODE
80 AC_CANONICAL_HOST
81
82 # Enable GNU extensions on systems that have them.
83 AC_GNU_SOURCE
84
85 AH_VERBATIM([_REENTRANT],
86 [/* To allow the use of GPGME in multithreaded programs we have to use
87   special features from the library.
88   IMPORTANT: gpgme is not yet fully reentrant and you should use it
89   only from one thread.  */
90 #ifndef _REENTRANT
91 # define _REENTRANT 1
92 #endif])
93
94 AC_PROG_CC
95 AC_PROG_CXX
96
97 AC_SUBST(LIBGPGME_LT_CURRENT)
98 AC_SUBST(LIBGPGME_LT_AGE)
99 AC_SUBST(LIBGPGME_LT_REVISION)
100
101 AC_SUBST(PACKAGE)
102 AC_SUBST(VERSION)
103 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
104 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
105
106 # Don't default to build static libs.
107 LT_PREREQ([2.2.6])
108 LT_INIT([win32-dll disable-static])
109 LT_LANG([Windows Resource])
110
111 # For now we hardcode the use of version scripts.  It would be better
112 # to write a test for this or even implement this within libtool.
113 have_ld_version_script=no
114 case "${host}" in
115     *-*-linux*)
116         have_ld_version_script=yes
117         ;;
118     *-*-gnu*)
119         have_ld_version_script=yes
120         ;;
121     *-apple-darwin*)
122         AC_DEFINE(_XOPEN_SOURCE, 500, Activate POSIX interface on MacOS X)
123         ;;
124 esac
125
126 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
127
128 GPG_DEFAULT=no
129 GPGSM_DEFAULT=no
130 GPGCONF_DEFAULT=no
131 G13_DEFAULT=no
132 component_system=None
133 have_dosish_system=no
134 have_w32_system=no
135 have_w64_system=no
136 build_w32_glib=no
137 build_w32_qt=no
138 case "${host}" in
139     x86_64-*mingw32*)
140         have_w64_system=yes
141         ;;
142     *-mingw32ce*)
143         have_w32ce_system=yes
144         ;;
145 esac
146 case "${host}" in
147     *-mingw32ce*|*-mingw32*)
148         have_dosish_system=yes
149         have_w32_system=yes
150         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
151         GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
152         GPGCONF_DEFAULT='c:\\gnupg\\gpgconf.exe'
153         G13_DEFAULT='c:\\gnupg\\g13.exe'
154         #component_system='COM+'
155
156         AM_PATH_GLIB_2_0
157         AC_ARG_ENABLE(w32-glib,
158             AC_HELP_STRING([--enable-w32-glib], [build GPGME Glib for W32]),
159                            build_w32_glib=$enableval)
160
161         # Check disabled, because the qt-dev packages in gpg4win do
162         # not provide any support for cross compilation.
163         # PKG_CHECK_MODULES(QT4_CORE, QtCore)
164
165         # Use it like this:
166         # ./configure --enable-w32-qt QT4_CORE_CFLAGS="..." QT4_CORE_LIBS="..."
167         AC_SUBST(QT4_CORE_CFLAGS)
168         AC_SUBST(QT4_CORE_LIBS)
169         AC_ARG_ENABLE(w32-qt,
170             AC_HELP_STRING([--enable-w32-qt], [build GPGME Qt for W32]),
171                            build_w32_qt=$enableval)
172         ;;
173     *)
174         AC_CHECK_PTH(1.2.0,,,no,have_pth=yes)
175         if test "$have_pth" = yes; then
176           AC_DEFINE(HAVE_PTH, ,[Define if we have Pth.])
177         fi
178         AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
179         if test "$have_pthread" = yes; then
180           AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
181         fi
182
183         # XXX: Probably use exec-prefix here?
184 #       GPG_DEFAULT='/usr/bin/gpg'
185 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
186 #       GPGCONF_DEFAULT='/usr/bin/gpgconf'
187 #       G13_DEFAULT='/usr/bin/g13'
188         ;;
189 esac
190
191 if test "$have_dosish_system" = yes; then
192    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
193              [Defined if we run on some of the PCDOS like systems
194               (DOS, Windoze. OS/2) with special properties like
195               no file modes])
196 fi
197 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
198
199 if test "$have_w32_system" = yes; then
200    AC_DEFINE(HAVE_W32_SYSTEM,1,
201              [Defined if we run on any kind of W32 API based system])
202    ACSUBST
203 fi
204 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
205
206 if test "$have_w64_system" = yes; then
207    AC_DEFINE(HAVE_W64_SYSTEM,1,
208              [Defined if we run on a 64 bit W32 API based system])
209 fi
210 AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
211
212 if test "$have_w32ce_system" = yes; then
213    AC_DEFINE(HAVE_W32CE_SYSTEM,1,
214              [Defined if we run on a W32 CE API based system])
215 fi
216 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
217
218 AM_CONDITIONAL(BUILD_W32_GLIB, test "$build_w32_glib" = yes)
219 AM_CONDITIONAL(BUILD_W32_QT, test "$build_w32_qt" = yes)
220
221 AM_CONDITIONAL(HAVE_PTH, test "$have_pth" = "yes")
222 AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
223
224
225
226 # Checks for header files.
227 AC_CHECK_HEADERS([locale.h])
228 AC_CHECK_HEADERS(sys/select.h)
229 AC_CHECK_HEADERS([sys/uio.h])
230
231
232 # Type checks.
233 AC_C_INLINE
234 AC_CHECK_SIZEOF(unsigned int)
235 AC_SYS_LARGEFILE
236 AC_TYPE_OFF_T
237 AC_TYPE_UINTPTR_T
238
239 # A simple compile time check in gpgme.h for GNU/Linux systems that
240 # prevents a file offset bits mismatch between gpgme and the application.
241 NEED__FILE_OFFSET_BITS=0
242 case "$ac_cv_sys_file_offset_bits" in
243   "" | no | unknown) ;;
244   *)
245   NEED__FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits
246   ;;
247 esac
248 AC_SUBST(NEED__FILE_OFFSET_BITS)
249
250 # Figure out platform dependent typedefs for gpgme.h
251 if test "$have_w32_system" = yes; then
252    if test "$have_w64_system" = yes; then
253       INSERT__TYPEDEFS_FOR_GPGME_H="/* Typedefs for the 64 bit W32 API.  */
254 #include <basetsd.h>
255 typedef long off_t;
256 typedef __int64 ssize_t;"
257    else
258       INSERT__TYPEDEFS_FOR_GPGME_H="/* Typedefs for the 32 bit W32 API.  */
259 typedef long off_t;
260 typedef long ssize_t;"
261    fi
262 else
263    INSERT__TYPEDEFS_FOR_GPGME_H="#include <sys/types.h>"
264 fi
265 AC_SUBST(INSERT__TYPEDEFS_FOR_GPGME_H)
266
267 # Checks for compiler features.
268 if test "$GCC" = yes; then
269     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
270     if test "$have_w32_system" = yes; then
271        CFLAGS="$CFLAGS -mms-bitfields"
272     fi
273 fi
274
275 # Only used for debugging, so no serious test needed (for actual
276 # functionality you have to test libc as well, this only tests the
277 # compiler).
278 AC_CACHE_CHECK([for __thread],[gpgme_cv_tls_works],
279    AC_COMPILE_IFELSE([__thread int foo;],
280      gpgme_cv_tls_works=yes,gpgme_cv_tls_works=no))
281 if test "$gpgme_cv_tls_works" = yes; then
282   AC_DEFINE(HAVE_TLS, [1], [Define if __thread is supported])
283 fi
284
285
286 # Checks for library functions.
287 AC_FUNC_FSEEKO
288
289 AC_REPLACE_FUNCS(vasprintf)
290 if test "$ac_cv_func_vasprintf" != yes; then
291   GNUPG_CHECK_VA_COPY
292 fi
293
294 # Try to find a thread-safe version of ttyname().
295 AC_REPLACE_FUNCS(ttyname_r)
296 if test "$ac_cv_func_ttyname_r" != yes; then
297   AC_MSG_WARN([
298 ***
299 *** ttyname() is not thread-safe and ttyname_r() does not exist
300 ***])
301 fi
302
303 # Try to find a thread-safe version of getenv().
304 have_thread_safe_getenv=no
305 jm_GLIBC21
306 if test $GLIBC21 = yes; then
307   have_thread_safe_getenv=yes
308 fi
309 if test $have_thread_safe_getenv = yes; then
310   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
311 fi
312 have_getenv_r=no
313 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
314 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
315   AC_MSG_WARN([
316 ***
317 *** getenv() is not thread-safe and getenv_r() does not exist
318 ***])
319 fi
320
321 # For converting time strings to seconds since Epoch, we need the timegm
322 # function.
323 AC_CHECK_FUNCS(timegm)
324 if test "$ac_cv_func_timegm" != yes; then
325   AC_MSG_WARN([
326 ***
327 *** timegm() not available - a non-thread-safe kludge will be used
328 *** and the TZ variable might be changed at runtime.
329 ***])
330 fi
331
332 AC_CHECK_FUNCS(setlocale)
333
334 # Checking for libgpg-error.
335 AM_PATH_GPG_ERROR(1.8,, AC_MSG_ERROR([libgpg-error was not found]))
336 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
337           [The default error source for GPGME.])
338
339 # And for libassuan.
340 have_libassuan=no
341 AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
342                   have_libassuan=yes, have_libassuan=no)
343 if test "$have_libassuan" = "yes"; then
344   AC_DEFINE_UNQUOTED(GPGME_LIBASSUAN_VERSION, "$libassuan_version",
345                      [version of the libassuan library])
346 fi
347 AM_CONDITIONAL(HAVE_ASSUAN, test "$have_libassuan" = "yes")
348 if test "$have_libassuan" = "yes"; then
349   AC_DEFINE(ENABLE_ASSUAN,1,[Whether Assuan support is enabled])
350 fi
351
352 # Checks for system services
353 NEED_GPG_VERSION_DEFAULT=1.4.0
354 NEED_GPGSM_VERSION_DEFAULT=1.9.6
355 NEED_GPGCONF_VERSION_DEFAULT=2.0.4
356 NEED_G13_VERSION_DEFAULT=2.1.0
357 NEED_GPG_VERSION="$NEED_GPG_VERSION_DEFAULT"
358 NEED_GPGSM_VERSION="$NEED_GPGSM_VERSION_DEFAULT"
359 NEED_GPGCONF_VERSION="$NEED_GPGCONF_VERSION_DEFAULT"
360 NEED_G13_VERSION="$NEED_G13_VERSION_DEFAULT"
361 AC_ARG_WITH(gpg-version,
362             AC_HELP_STRING([--with-gpg-version=VER], [require GnuPG version VER]),
363             NEED_GPG_VERSION=$withval)
364 if test "$NEED_GPG_VERSION" = "yes"; then
365   NEED_GPG_VERSION="$NEED_GPG_VERSION_DEFAULT"
366 fi
367 if test "$NEED_GPG_VERSION" = "no"; then
368   NEED_GPG_VERSION=0.0.0
369 fi
370 AC_ARG_WITH(gpgsm-version,
371             AC_HELP_STRING([--with-gpgsm-version=VER], [require GPGSM version VER]),
372             NEED_GPGSM_VERSION=$withval)
373 if test "$NEED_GPGSM_VERSION" = "yes"; then
374   NEED_GPGSM_VERSION="$NEED_GPGSM_VERSION_DEFAULT"
375 fi
376 if test "$NEED_GPGSM_VERSION" = "no"; then
377   NEED_GPGSM_VERSION=0.0.0
378 fi
379 AC_ARG_WITH(gpgconf-version,
380             AC_HELP_STRING([--with-gpgconf-version=VER], [require GPGCONF version VER]),
381             NEED_GPGCONF_VERSION=$withval)
382 if test "$NEED_GPGCONF_VERSION" = "yes"; then
383   NEED_GPGCONF_VERSION="$NEED_GPGCONF_VERSION_DEFAULT"
384 fi
385 if test "$NEED_GPGCONF_VERSION" = "no"; then
386   NEED_GPGCONF_VERSION=0.0.0
387 fi
388 AC_ARG_WITH(g13-version,
389             AC_HELP_STRING([--with-g13-version=VER], [require G13 version VER]),
390             NEED_G13_VERSION=$withval)
391 if test "$NEED_G13_VERSION" = "yes"; then
392   NEED_G13_VERSION="$NEED_G13_VERSION_DEFAULT"
393 fi
394 if test "$NEED_G13_VERSION" = "no"; then
395   NEED_G13_VERSION=0.0.0
396 fi
397
398 AC_DEFINE_UNQUOTED(NEED_GPG_VERSION, "$NEED_GPG_VERSION",
399                                      [Min. needed GnuPG version.])
400 AC_DEFINE_UNQUOTED(NEED_GPGSM_VERSION, "$NEED_GPGSM_VERSION",
401                                        [Min. needed GPGSM version.])
402 AC_DEFINE_UNQUOTED(NEED_GPGCONF_VERSION, "$NEED_GPGCONF_VERSION",
403                                          [Min. needed GPGCONF version.])
404 AC_DEFINE_UNQUOTED(NEED_G13_VERSION, "$NEED_G13_VERSION",
405                                      [Min. needed G13 version.])
406
407
408 NO_OVERRIDE=no
409 AC_ARG_WITH(gpg,
410             AC_HELP_STRING([--with-gpg=PATH], [use GnuPG binary at PATH]),
411             GPG=$withval, NO_OVERRIDE=yes)
412 if test "$NO_OVERRIDE" = "yes" || test "$GPG" = "yes"; then
413   GPG=
414   NO_OVERRIDE=yes
415   if test "$cross_compiling" != "yes"; then
416     AC_PATH_PROG(GPG, gpg)
417   fi
418   if test -z "$GPG"; then
419     GPG="$GPG_DEFAULT"
420   fi
421 fi
422 if test "$GPG" = no; then
423   if test "$NO_OVERRIDE" = "yes"; then
424     if test "$cross_compiling" != "yes"; then
425       AC_MSG_WARN([
426 ***
427 *** Could not find GnuPG, install GnuPG or use --with-gpg=PATH to enable it
428 ***])
429     else
430       AC_MSG_ERROR([
431 ***
432 *** Can not determine path to GnuPG when cross-compiling, use --with-gpg=PATH
433 ***])
434     fi
435   fi
436 else
437   AC_DEFINE_UNQUOTED(GPG_PATH, "$GPG", [Path to the GnuPG binary.])
438   AC_SUBST(GPG)
439 fi
440 dnl Check for GnuPG version requirement.
441 GPG_VERSION=unknown
442 ok=maybe
443 if test -z "$GPG" -o "x$GPG" = "xno"; then
444   ok=no
445 else
446   if test "$cross_compiling" = "yes"; then
447     AC_MSG_WARN([GnuPG version can not be checked when cross compiling])
448     ok=no
449   else
450     if test ! -x "$GPG"; then
451       AC_MSG_WARN([GnuPG not executable, version check disabled])
452       ok=no
453     fi
454   fi
455 fi
456 if test "$ok" = "maybe"; then
457   AC_MSG_CHECKING(for GPG >= $NEED_GPG_VERSION)
458   req_major=`echo $NEED_GPG_VERSION | \
459              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
460   req_minor=`echo $NEED_GPG_VERSION | \
461              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
462   req_micro=`echo $NEED_GPG_VERSION | \
463              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
464   GPG_VERSION=`$GPG --version | sed -n '1 s/[[^0-9]]*\(.*\)/\1/p'`
465   major=`echo $GPG_VERSION | \
466          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
467   minor=`echo $GPG_VERSION | \
468          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
469   micro=`echo $GPG_VERSION | \
470          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
471
472   if test "$major" -gt "$req_major"; then
473     ok=yes
474   else
475     if test "$major" -eq "$req_major"; then
476       if test "$minor" -gt "$req_minor"; then
477         ok=yes
478       else
479         if test "$minor" -eq "$req_minor"; then
480           if test "$micro" -ge "$req_micro"; then
481             ok=yes
482           fi
483         fi
484       fi
485     fi
486   fi
487   if test "$ok" = "yes"; then
488     AC_MSG_RESULT(yes)
489   else
490     AC_MSG_RESULT(no)
491     AC_MSG_WARN([GPG must be at least version $NEED_GPG_VERSION])
492   fi
493 fi
494 run_gpg_test="$ok"
495 AC_ARG_ENABLE(gpg-test,
496   AC_HELP_STRING([--disable-gpg-test], [disable GPG run test]),
497          run_gpg_test=$enableval)
498 AM_CONDITIONAL(RUN_GPG_TESTS, test "$run_gpg_test" = "yes")
499 AC_SUBST(GPG_PATH)
500
501 NO_OVERRIDE=no
502 AC_ARG_WITH(gpgsm,
503             AC_HELP_STRING([--with-gpgsm=PATH], [use GpgSM binary at PATH]),
504             GPGSM=$withval, NO_OVERRIDE=yes)
505 if test "$NO_OVERRIDE" = "yes" || test "$GPGSM" = "yes"; then
506   GPGSM=
507   NO_OVERRIDE=yes
508   if test "$cross_compiling" != "yes"; then
509     AC_PATH_PROG(GPGSM, gpgsm)
510   fi
511   if test -z "$GPGSM"; then
512     GPGSM="$GPGSM_DEFAULT"
513   fi
514 fi
515 if test "$GPGSM" = no; then
516   if test "$NO_OVERRIDE" = "yes"; then
517     if test "$cross_compiling" != "yes"; then
518       AC_MSG_WARN([
519 ***
520 *** Could not find GpgSM, install GpgSM or use --with-gpgsm=PATH to enable it
521 ***])
522     else
523       AC_MSG_ERROR([
524 ***
525 *** Can not determine path to GpgSM when cross-compiling, use --with-gpgsm=PATH
526 ***])
527     fi
528   fi
529 else
530   AC_DEFINE_UNQUOTED(GPGSM_PATH, "$GPGSM", [Path to the GPGSM binary.])
531   AC_DEFINE(ENABLE_GPGSM,1,[Whether GPGSM support is enabled])
532 fi
533 AM_CONDITIONAL(HAVE_GPGSM, test "$GPGSM" != "no")
534
535
536 dnl Check for GPGSM version requirement.
537 GPGSM_VERSION=unknown
538 ok=maybe
539 if test -z "$GPGSM" -o "x$GPGSM" = "xno"; then
540   ok=no
541 else
542   if test "$cross_compiling" = "yes"; then
543     AC_MSG_WARN([GPGSM version can not be checked when cross compiling])
544     ok=no
545   else
546     if test ! -x "$GPGSM"; then
547       AC_MSG_WARN([GPGSM not executable, version check disabled])
548       ok=no
549     fi
550   fi
551 fi
552 if test "$ok" = "maybe"; then
553   AC_MSG_CHECKING(for GPGSM >= $NEED_GPGSM_VERSION)
554   req_major=`echo $NEED_GPGSM_VERSION | \
555              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
556   req_minor=`echo $NEED_GPGSM_VERSION | \
557              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
558   req_micro=`echo $NEED_GPGSM_VERSION | \
559              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
560   GPGSM_VERSION=`$GPGSM --version | sed -n '1 s/[[^0-9]]*\(.*\)/\1/p'`
561   major=`echo $GPGSM_VERSION | \
562          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
563   minor=`echo $GPGSM_VERSION | \
564          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
565   micro=`echo $GPGSM_VERSION | \
566          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
567
568   if test "$major" -gt "$req_major"; then
569     ok=yes
570   else
571     if test "$major" -eq "$req_major"; then
572       if test "$minor" -gt "$req_minor"; then
573         ok=yes
574       else
575         if test "$minor" -eq "$req_minor"; then
576           if test "$micro" -ge "$req_micro"; then
577             ok=yes
578           fi
579         fi
580       fi
581     fi
582   fi
583   if test "$ok" = "yes"; then
584     AC_MSG_RESULT(yes)
585   else
586     AC_MSG_RESULT(no)
587     AC_MSG_WARN([GPGSM must be at least version $NEED_GPGSM_VERSION])
588   fi
589 fi
590 run_gpgsm_test="$ok"
591 AC_ARG_ENABLE(gpgsm-test,
592   AC_HELP_STRING([--disable-gpgsm-test], [disable GPGSM run test]),
593          run_gpgsm_test=$enableval)
594 AM_CONDITIONAL(RUN_GPGSM_TESTS, test "$run_gpgsm_test" = "yes")
595
596
597 NO_OVERRIDE=no
598 AC_ARG_WITH(gpgconf,
599             AC_HELP_STRING([--with-gpgconf=PATH],
600                            [use gpgconf binary at PATH]),
601             GPGCONF=$withval, NO_OVERRIDE=yes)
602 if test "$NO_OVERRIDE" = "yes" || test "$GPGCONF" = "yes"; then
603   GPGCONF=
604   NO_OVERRIDE=yes
605   if test "$cross_compiling" != "yes"; then
606     AC_PATH_PROG(GPGCONF, gpgconf)
607   fi
608   if test -z "$GPGCONF"; then
609     GPGCONF="$GPGCONF_DEFAULT"
610   fi
611 fi
612 if test "$GPGCONF" = no; then
613   if test "$NO_OVERRIDE" = "yes"; then
614     if test "$cross_compiling" != "yes"; then
615       AC_MSG_WARN([
616 ***
617 *** Could not find gpgconf, install gpgconf or use --with-gpgconf=PATH to enable it
618 ***])
619     else
620       AC_MSG_ERROR([
621 ***
622 *** Can not determine path to gpgconf when cross-compiling, use --with-gpgconf=PATH
623 ***])
624     fi
625   fi
626 else
627   AC_DEFINE_UNQUOTED(GPGCONF_PATH, "$GPGCONF", [Path to the GPGCONF binary.])
628   AC_DEFINE(ENABLE_GPGCONF,1,[Whether GPGCONF support is enabled])
629 fi
630 AM_CONDITIONAL(HAVE_GPGCONF, test "$GPGCONF" != "no")
631
632 dnl Check for GPGCONF version requirement.
633 GPGCONF_VERSION=unknown
634 ok=maybe
635 if test -z "$GPGCONF" -o "x$GPGCONF" = "xno"; then
636   ok=no
637 else
638   if test "$cross_compiling" = "yes"; then
639     AC_MSG_WARN([GPGCONF version can not be checked when cross compiling])
640     ok=no
641   else
642     if test ! -x "$GPGCONF"; then
643       AC_MSG_WARN([GPGCONF not executable, version check disabled])
644       ok=no
645     fi
646   fi
647 fi
648 if test "$ok" = "maybe"; then
649   AC_MSG_CHECKING(for GPGCONF >= $NEED_GPGCONF_VERSION)
650   req_major=`echo $NEED_GPGCONF_VERSION | \
651              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
652   req_minor=`echo $NEED_GPGCONF_VERSION | \
653              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
654   req_micro=`echo $NEED_GPGCONF_VERSION | \
655              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
656   GPGCONF_VERSION=`$GPGCONF --version | sed -n '1 s/[[^0-9]]*\(.*\)/\1/p'`
657   major=`echo $GPGCONF_VERSION | \
658          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
659   minor=`echo $GPGCONF_VERSION | \
660          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
661   micro=`echo $GPGCONF_VERSION | \
662          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
663
664   if test "$major" -gt "$req_major"; then
665     ok=yes
666   else
667     if test "$major" -eq "$req_major"; then
668       if test "$minor" -gt "$req_minor"; then
669         ok=yes
670       else
671         if test "$minor" -eq "$req_minor"; then
672           if test "$micro" -ge "$req_micro"; then
673             ok=yes
674           fi
675         fi
676       fi
677     fi
678   fi
679   if test "$ok" = "yes"; then
680     AC_MSG_RESULT(yes)
681   else
682     AC_MSG_RESULT(no)
683     AC_MSG_WARN([GPGCONF must be at least version $NEED_GPGCONF_VERSION])
684   fi
685 fi
686 run_gpgconf_test="$ok"
687 AC_ARG_ENABLE(gpgconf-test,
688   AC_HELP_STRING([--disable-gpgconf-test], [disable GPGCONF run test]),
689          run_gpgconf_test=$enableval)
690 AM_CONDITIONAL(RUN_GPGCONF_TESTS, test "$run_gpgconf_test" = "yes")
691
692
693 NO_OVERRIDE=no
694 AC_ARG_WITH(g13,
695             AC_HELP_STRING([--with-g13=PATH],
696                            [use g13 binary at PATH]),
697             G13=$withval, NO_OVERRIDE=yes)
698 if test "$NO_OVERRIDE" = "yes" || test "$G13" = "yes"; then
699   G13=
700   NO_OVERRIDE=yes
701   if test "$cross_compiling" != "yes"; then
702     AC_PATH_PROG(G13, g13)
703   fi
704   if test -z "$G13"; then
705     G13="$G13_DEFAULT"
706   fi
707 fi
708 if test "$G13" = no; then
709   if test "$NO_OVERRIDE" = "yes"; then
710     if test "$cross_compiling" != "yes"; then
711       AC_MSG_WARN([
712 ***
713 *** Could not find g13, install g13 or use --with-g13=PATH to enable it
714 ***])
715     else
716       AC_MSG_ERROR([
717 ***
718 *** Can not determine path to g13 when cross-compiling, use --with-g13=PATH
719 ***])
720     fi
721   fi
722 else
723   AC_DEFINE_UNQUOTED(G13_PATH, "$G13", [Path to the G13 binary.])
724   AC_DEFINE(ENABLE_G13,1,[Whether G13 support is enabled])
725 fi
726 AM_CONDITIONAL(HAVE_G13, test "$G13" != "no")
727
728 dnl Check for G13 version requirement.
729 G13_VERSION=unknown
730 ok=maybe
731 if test -z "$G13" -o "x$G13" = "xno"; then
732   ok=no
733 else
734   if test "$cross_compiling" = "yes"; then
735     AC_MSG_WARN([G13 version can not be checked when cross compiling])
736     ok=no
737   else
738     if test ! -x "$G13"; then
739       AC_MSG_WARN([G13 not executable, version check disabled])
740       ok=no
741     fi
742   fi
743 fi
744 if test "$ok" = "maybe"; then
745   AC_MSG_CHECKING(for G13 >= $NEED_G13_VERSION)
746   req_major=`echo $NEED_G13_VERSION | \
747              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
748   req_minor=`echo $NEED_G13_VERSION | \
749              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
750   req_micro=`echo $NEED_G13_VERSION | \
751              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
752   G13_VERSION=`$G13 --version | sed -n '1 s/.*\ \([[0-9]].*\)/\1/p'`
753   major=`echo $G13_VERSION | \
754          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
755   minor=`echo $G13_VERSION | \
756          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
757   micro=`echo $G13_VERSION | \
758          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
759
760   if test "$major" -gt "$req_major"; then
761     ok=yes
762   else
763     if test "$major" -eq "$req_major"; then
764       if test "$minor" -gt "$req_minor"; then
765         ok=yes
766       else
767         if test "$minor" -eq "$req_minor"; then
768           if test "$micro" -ge "$req_micro"; then
769             ok=yes
770           fi
771         fi
772       fi
773     fi
774   fi
775   if test "$ok" = "yes"; then
776     AC_MSG_RESULT(yes)
777   else
778     AC_MSG_RESULT(no)
779     AC_MSG_WARN([G13 must be at least version $NEED_G13_VERSION])
780   fi
781 fi
782 run_g13_test="$ok"
783 AC_ARG_ENABLE(g13-test,
784   AC_HELP_STRING([--disable-g13-test], [disable G13 run test]),
785          run_g13_test=$enableval)
786 AM_CONDITIONAL(RUN_G13_TESTS, test "$run_g13_test" = "yes")
787
788
789 # Check for funopen
790 AC_CHECK_FUNCS(funopen)
791 if test $ac_cv_func_funopen != yes; then
792     # No funopen but we can implement that in terms of fopencookie.
793     AC_CHECK_FUNCS(fopencookie)
794     if test $ac_cv_func_fopencookie = yes; then
795         AC_REPLACE_FUNCS(funopen)
796     else
797         AC_MSG_WARN([
798 ***
799 *** No implementation of fopencookie or funopen available
800 ***])
801     fi
802 fi
803
804 # Check for getgid etc
805 AC_CHECK_FUNCS(getgid getegid)
806
807
808 # Replacement functions.
809 AC_REPLACE_FUNCS(stpcpy)
810 # Check for unistd.h for setenv replacement function.
811 AC_CHECK_HEADERS([unistd.h sys/time.h sys/types.h sys/stat.h])
812 AC_REPLACE_FUNCS(setenv)
813
814 # Assuan check for descriptor passing.
815 AC_CHECK_MEMBER(struct cmsghdr.cmsg_len,
816                 [supports_descriptor_passing=yes],
817                 [supports_descriptor_passing=no
818                  AC_MSG_WARN([
819 ***
820 *** Data structure for sending ancillary data missing.
821 *** Descriptor passing won't work.
822 ***])],[
823 #include <stdlib.h>
824 #include <stddef.h>
825 #include <stdio.h>
826 #include <sys/types.h>
827 #include <sys/socket.h>
828 #include <sys/un.h>
829 #if HAVE_SYS_UIO_H
830 #include <sys/uio.h>
831 #endif
832 #include <unistd.h>
833        ])
834
835 use_descriptor_passing=no
836 AC_ARG_ENABLE(fd-passing,
837   AC_HELP_STRING([--enable-fd-passing], [use FD passing if supported]),
838   use_descriptor_passing=$enableval)
839
840 if test "$supports_descriptor_passing" != "yes"; then
841   use_descriptor_passing=no
842 fi
843
844 if test "$use_descriptor_passing" = "yes"; then
845 AC_DEFINE(USE_DESCRIPTOR_PASSING,1,
846           [Defined if descriptor passing is enabled and supported])
847 fi
848
849 AM_CONDITIONAL(USE_DESCRIPTOR_PASSING, test "$use_descriptor_passing" = "yes")
850
851
852 uiserver=no
853 if test "$use_descriptor_passing" = "yes" && test "$have_libassuan" = "yes"; then
854   uiserver=yes
855 fi
856 if test "$uiserver" != "no"; then
857   AC_DEFINE(ENABLE_UISERVER, 1,
858             [Defined if we are building with uiserver support.])
859 fi
860 AM_CONDITIONAL(HAVE_UISERVER, test "$uiserver" != "no")
861
862
863 AM_CONDITIONAL(BUILD_COMPLUS, test "$component_system" = "COM+")
864
865 # Generate values for the DLL version info
866 if test "$have_w32_system" = yes; then
867     BUILD_TIMESTAMP=`date --iso-8601=minutes`
868     changequote(,)dnl
869     BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
870     changequote([,])dnl
871     BUILD_FILEVERSION="${BUILD_FILEVERSION}${BUILD_REVISION}"
872 fi
873 AC_SUBST(BUILD_REVISION)
874 AC_SUBST(BUILD_TIMESTAMP)
875 AC_SUBST(BUILD_FILEVERSION)
876
877 # Add a few constants to help porting to W32
878 AH_VERBATIM([SEPCONSTANTS],
879 [
880 /* Separators as used in $PATH.  */
881 #ifdef HAVE_DOSISH_SYSTEM
882 #define PATHSEP_C ';'
883 #else
884 #define PATHSEP_C ':'
885 #endif
886 ])
887
888 AH_BOTTOM([
889 /* Definition of GCC specific attributes.  */
890 #if __GNUC__ > 2
891 # define GPGME_GCC_A_PURE  __attribute__ ((__pure__))
892 #else
893 # define GPGME_GCC_A_PURE
894 #endif
895
896 /* Under WindowsCE we need gpg-error's strerror macro.  */
897 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
898 ])
899
900
901 # Substitution used for gpgme-config
902 GPGME_CONFIG_LIBS="-lgpgme"
903 GPGME_CONFIG_CFLAGS=""
904 AC_SUBST(GPGME_CONFIG_API_VERSION)
905 AC_SUBST(GPGME_CONFIG_LIBS)
906 AC_SUBST(GPGME_CONFIG_CFLAGS)
907
908 # Frob'da Variables
909 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
910            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
911 AC_SUBST(LTLIBOBJS)
912
913 # Some checks for gpgme-tool
914 AC_CHECK_HEADER([argp.h])
915 AC_CHECK_TYPES([error_t], [],
916    [AC_DEFINE([error_t], [int],
917    [Define to a type to use for `error_t' if it is not otherwise available.])],
918    [#include <errno.h>])
919
920
921 # A substitution to set generated files in a Emacs buffer to read-only.
922 AC_SUBST(emacs_local_vars_begin, ['Local Variables:'])
923 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
924 AC_SUBST(emacs_local_vars_end, ['End:'])
925
926
927 # Last check.
928 die=no
929 if test "$have_libassuan" = "no"; then
930    die=yes
931    AC_MSG_NOTICE([[
932 ***
933 *** You need libassuan to build this program with GPGSM support.
934 *** This library is for example available at
935 ***   ftp://ftp.gnupg.org/gcrypt/libassuan/
936 *** (at least version $NEED_LIBASSUAN_VERSION (API $NEED_LIBASSUAN_API) is required).
937 ***]])
938 fi
939
940 if test "$die" = "yes"; then
941     AC_MSG_ERROR([[
942 ***
943 *** Required libraries not found. Please consult the above messages
944 *** and install them before running configure again.
945 ***]])
946 fi
947
948
949 #
950 # Create config files
951
952 AC_CONFIG_FILES(Makefile src/Makefile
953                 tests/Makefile
954                 tests/gpg/Makefile
955                 tests/gpgsm/Makefile
956                 tests/opassuan/Makefile
957                 doc/Makefile complus/Makefile
958                 src/versioninfo.rc
959                 src/gpgme.h)
960 AC_CONFIG_FILES(src/gpgme-config, chmod +x src/gpgme-config)
961 AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpgme.asd])
962 AC_OUTPUT
963
964 echo "
965         GPGME v${VERSION} has been configured as follows:
966
967         GnuPG path:      $GPG
968         GnuPG version:   $GPG_VERSION, min. $NEED_GPG_VERSION
969
970         GpgSM path:      $GPGSM
971         GpgSM version:   $GPGSM_VERSION, min. $NEED_GPGSM_VERSION
972
973         GpgConf path:    $GPGCONF
974         GpgConf version: $GPGCONF_VERSION, min. $NEED_GPGCONF_VERSION
975
976         G13 path:        $G13
977         G13 version:     $G13_VERSION, min. $NEED_G13_VERSION
978
979         Assuan version:  $libassuan_version, min. $NEED_LIBASSUAN_VERSION
980
981         UI Server:       $uiserver
982         FD Passing:      $use_descriptor_passing
983
984         GPGME Pthread:   $have_pthread
985         GPGME Pth:       $have_pth
986 "