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