python: Build for both Python2 and Python3.
[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, 2014, 2015  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.14"
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, [7])
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=25
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=14
62 LIBGPGME_LT_REVISION=0
63
64 LIBGPGMEPP_LT_CURRENT=6
65 LIBGPGMEPP_LT_AGE=0
66 LIBGPGMEPP_LT_REVISION=1
67
68 LIBQGPGME_LT_CURRENT=6
69 LIBQGPGME_LT_AGE=0
70 LIBQGPGME_LT_REVISION=1
71
72 # If the API is changed in an incompatible way: increment the next counter.
73 GPGME_CONFIG_API_VERSION=1
74 ##############################################
75
76 NEED_GPG_ERROR_VERSION=1.11
77 NEED_LIBASSUAN_API=2
78 NEED_LIBASSUAN_VERSION=2.0.2
79
80
81 PACKAGE=$PACKAGE_NAME
82 VERSION=$PACKAGE_VERSION
83
84 AC_CONFIG_AUX_DIR([build-aux])
85 AC_CONFIG_MACRO_DIR([m4])
86 AC_CONFIG_SRCDIR(src/gpgme.h.in)
87 AC_CONFIG_HEADER(config.h)
88 AM_INIT_AUTOMAKE([serial-tests dist-bzip2 no-dist-gzip])
89 AM_MAINTAINER_MODE
90 AC_CANONICAL_HOST
91 AM_SILENT_RULES
92 AC_ARG_VAR(SYSROOT,[locate config scripts also below that directory])
93
94 # Enable GNU extensions on systems that have them.
95 AC_GNU_SOURCE
96
97 AH_VERBATIM([_REENTRANT],
98 [/* To allow the use of GPGME in multithreaded programs we have to use
99   special features from the library.
100   IMPORTANT: gpgme is not yet fully reentrant and you should use it
101   only from one thread.  */
102 #ifndef _REENTRANT
103 # define _REENTRANT 1
104 #endif])
105
106 AC_PROG_CC
107 AC_PROG_CXX
108
109 # Note: A suitable gitlog-to-changelog script can be found in GnuPG master.
110 AC_CHECK_PROGS(GITLOG_TO_CHANGELOG, gitlog-to-changelog, [gitlog-to-changelog])
111
112 AC_SUBST(LIBGPGME_LT_CURRENT)
113 AC_SUBST(LIBGPGME_LT_AGE)
114 AC_SUBST(LIBGPGME_LT_REVISION)
115 AC_SUBST(LIBGPGMEPP_LT_CURRENT)
116 AC_SUBST(LIBGPGMEPP_LT_AGE)
117 AC_SUBST(LIBGPGMEPP_LT_REVISION)
118 AC_SUBST(LIBQGPGME_LT_CURRENT)
119 AC_SUBST(LIBQGPGME_LT_AGE)
120 AC_SUBST(LIBQGPGME_LT_REVISION)
121
122 AC_SUBST(PACKAGE)
123 AC_SUBST(VERSION)
124 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
125 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
126 VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_version_major \
127                           mym4_version_minor mym4_version_micro)
128 AC_SUBST(VERSION_NUMBER)
129
130 # We need to compile and run a program on the build machine.  A
131 # comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in
132 # the AC archive is broken for autoconf 2.57.  Given that there is no
133 # newer version of that macro, we assume that it is also broken for
134 # autoconf 2.61 and thus we use a simple but usually sufficient
135 # approach.
136 AC_MSG_CHECKING(for cc for build)
137 if test "$cross_compiling" = "yes"; then
138   CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
139 else
140   CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
141 fi
142 AC_MSG_RESULT($CC_FOR_BUILD)
143 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
144
145
146 # Don't default to build static libs.
147 LT_PREREQ([2.2.6])
148 LT_INIT([win32-dll disable-static])
149 LT_LANG([Windows Resource])
150
151 # For now we hardcode the use of version scripts.  It would be better
152 # to write a test for this or even implement this within libtool.
153 have_ld_version_script=no
154 case "${host}" in
155     *-*-linux*)
156         have_ld_version_script=yes
157         ;;
158     *-*-gnu*)
159         have_ld_version_script=yes
160         ;;
161     *-apple-darwin*)
162         AC_DEFINE(_XOPEN_SOURCE, 500, Activate POSIX interface on MacOS X)
163         ;;
164 esac
165
166 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
167
168 GPG_DEFAULT=no
169 GPGSM_DEFAULT=no
170 GPGCONF_DEFAULT=no
171 G13_DEFAULT=no
172 component_system=None
173 have_dosish_system=no
174 have_android_system=no
175 have_w32_system=no
176 have_w64_system=no
177 build_w32_glib=no
178 build_w32_qt=no
179 available_languages="cl cpp python python2 python3 qt"
180 default_languages="cl cpp python qt"
181 case "${host}" in
182     x86_64-*mingw32*)
183         have_w64_system=yes
184         ;;
185     *-mingw32ce*)
186         have_w32ce_system=yes
187         ;;
188     *-linux-androideabi)
189         have_android_system=yes
190         ;;
191 esac
192 case "${host}" in
193     *-mingw32ce*|*-mingw32*)
194         have_dosish_system=yes
195         have_w32_system=yes
196         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
197         GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
198         GPGCONF_DEFAULT='c:\\gnupg\\gpgconf.exe'
199         G13_DEFAULT='c:\\gnupg\\g13.exe'
200         #component_system='COM+'
201
202         AM_PATH_GLIB_2_0
203         AC_ARG_ENABLE(w32-glib,
204             AC_HELP_STRING([--enable-w32-glib], [build GPGME Glib for W32]),
205                            build_w32_glib=$enableval)
206        ;;
207     *)
208
209         AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
210         if test "$have_pthread" = yes; then
211           AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
212         fi
213
214         # XXX: Probably use exec-prefix here?
215 #       GPG_DEFAULT='/usr/bin/gpg'
216 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
217 #       GPGCONF_DEFAULT='/usr/bin/gpgconf'
218 #       G13_DEFAULT='/usr/bin/g13'
219         ;;
220 esac
221
222 if test "$have_dosish_system" = yes; then
223    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
224              [Defined if we run on some of the PCDOS like systems
225               (DOS, Windoze. OS/2) with special properties like
226               no file modes])
227 fi
228 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
229
230 if test "$have_w32_system" = yes; then
231    AC_DEFINE(HAVE_W32_SYSTEM,1,
232              [Defined if we run on any kind of W32 API based system])
233 fi
234 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
235
236 if test "$have_w64_system" = yes; then
237    AC_DEFINE(HAVE_W64_SYSTEM,1,
238              [Defined if we run on a 64 bit W32 API based system])
239 fi
240 AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
241
242 if test "$have_w32ce_system" = yes; then
243    AC_DEFINE(HAVE_W32CE_SYSTEM,1,
244              [Defined if we run on a W32 CE API based system])
245 fi
246 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
247
248 if test "$have_android_system" = yes; then
249    AC_DEFINE(HAVE_ANDROID_SYSTEM,1, [Defined if we build for an Android system])
250 fi
251 AM_CONDITIONAL(HAVE_ANDROID_SYSTEM, test "$have_android_system" = yes)
252
253 AM_CONDITIONAL(BUILD_W32_GLIB, test "$build_w32_glib" = yes)
254
255 AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
256
257
258 AC_ARG_ENABLE([fixed-path],
259               AC_HELP_STRING([--enable-fixed-path=PATH],
260                              [locate binaries only via this PATH]),
261               [fixed_search_path="$enableval"],
262               [fixed_search_path=""])
263 if test x$fixed_search_path != x ; then
264   AC_DEFINE_UNQUOTED(FIXED_SEARCH_PATH, "$fixed_search_path",
265                     [Locate binaries only via this PATH])
266 fi
267
268
269 # Note: You need to declare all possible langauges also in
270 #       lang/Makefile.am's DIST_SUBDIRS.
271 AC_ARG_ENABLE([languages],
272               AC_HELP_STRING([--enable-languages=languages],
273                              [enable only specific language bindings]),
274                              [enabled_languages=`echo $enableval | \
275                              tr ',:' '  ' | tr '[A-Z]' '[a-z]' | \
276                              sed 's/c++/cpp/'`],
277                              [enabled_languages="maybe"])
278 if test "x$enabled_languages" = "x" \
279    -o "$enabled_languages" = "no"; then
280    enabled_languages=
281 fi
282
283 # If languages are explicitly set missing requirements
284 # for the languages are treated as errors otherwise
285 # there will be a warning.
286 explicit_languages=1
287 if test "x$enabled_languages" = "xmaybe"; then
288     explicit_languages=0
289     enabled_languages="$default_languages"
290 fi
291
292 for language in $enabled_languages; do
293     LIST_MEMBER($language, $available_languages)
294     if test "$found" = "0"; then
295        AC_MSG_ERROR([unsupported language binding specified])
296     fi
297 done
298
299
300
301 # Enable C++ 11 if cpp language is requested
302 LIST_MEMBER("cpp", $enabled_languages)
303 if test "$found" = "1"; then
304     AX_CXX_COMPILE_STDCXX(11, noext, optional)
305     if test "$HAVE_CXX11" != "1"; then
306         if test "$explicit_languages" = "1"; then
307             AC_MSG_ERROR([[
308 ***
309 *** A compiler with c++11 support is required for the c++ binding.
310 ***]])
311         else
312             enabled_languages=$(echo $enabled_languages | sed 's/cpp//')
313             enabled_languages=$(echo $enabled_languages | sed 's/qt//')
314             AC_MSG_WARN([[
315 ***
316 *** No c++11 support detected. C++ and Qt bindings will be disabled.
317 ***]])
318         fi
319     fi
320 fi
321
322 # Check that if qt is enabled cpp also is enabled
323 LIST_MEMBER("qt", $enabled_languages)
324 if test "$found" = "1"; then
325     # We need to ensure that in the langauge order qt comes after cpp
326     # so we remove qt first and explicitly add it as last list member.
327     enabled_languages=$(echo $enabled_languages | sed 's/qt//')
328     LIST_MEMBER("cpp", $enabled_languages)
329     if test "$found" = "0"; then
330         AC_MSG_ERROR([[
331 ***
332 *** Qt language binding depends on cpp binding.
333 ***]])
334     fi
335     FIND_QT
336     if test "$have_qt5_libs" != "yes"; then
337         if test "$explicit_languages" = "1"; then
338         AC_MSG_ERROR([[
339 ***
340 *** Qt5 (Qt5Core) is required for Qt binding.
341 ***]])
342         else
343            AC_MSG_WARN([[
344 ***
345 *** Qt5 (Qt5Core) not found Qt Binding will be disabled.
346 ***]])
347         fi
348     else
349         enabled_languages=`echo $enabled_languages qt`
350
351         AC_CHECK_PROGS([DOXYGEN], [doxygen])
352         if test -z "$DOXYGEN";
353             # This is not highlighted becase it's not really important.
354             then AC_MSG_WARN([Doxygen not found - Qt binding doc will not be built.])
355         fi
356         AC_CHECK_PROGS([GRAPHVIZ], [dot])
357         if test -z "$GRAPHVIZ";
358             then AC_MSG_WARN([Graphviz not found - Qt binding doc will not have diagrams.])
359         fi
360     fi
361 fi
362 AM_CONDITIONAL([HAVE_DOXYGEN],
363                [test -n "$DOXYGEN"])
364 if test -n "$GRAPHVIZ"; then
365     HAVE_DOT="YES"
366 else
367     HAVE_DOT="NO"
368 fi
369 AC_SUBST(HAVE_DOT)
370
371 # Python bindings.
372 LIST_MEMBER("python2", $enabled_languages)
373 found_py2=$found
374 LIST_MEMBER("python3", $enabled_languages)
375 found_py3=$found
376 LIST_MEMBER("python", $enabled_languages)
377 found_py=$found
378 if test "$found_py" = "1" -o "$found_py2" = "1" -o "$found_py3" = "1"; then
379     AX_PKG_SWIG
380     if test -z "$SWIG"; then
381         if test "$explicit_languages" = "1"; then
382             AC_MSG_ERROR([[
383 ***
384 *** You need SWIG to build the Python bindings.
385 ***]])
386         else
387             enabled_languages=$(echo $enabled_languages | sed 's/python//')
388         fi
389     else
390         # Reset all the stuff, just to be sure.
391         PYTHONS=
392         PYTHON_VERSIONS=
393         unset PYTHON
394         unset PYTHON_VERSION
395         unset ac_cv_path_PYTHON
396         unset am_cv_pathless_PYTHON
397         unset am_cv_python_version
398         unset am_cv_python_platform
399         unset am_cv_python_pythondir
400         unset am_cv_python_pyexecdir
401
402         if test "$found_py" = "1" -o "$found_py2" = "1"; then
403             AM_PATH_PYTHON([2.7])
404             if test "$PYTHON"; then
405                 PYTHONS="$(echo $PYTHONS $PYTHON)"
406                 PYTHON_VERSIONS="$(echo $PYTHON_VERSIONS $PYTHON_VERSION)"
407             fi
408         fi
409
410         if test "$found_py" = "1" -o "$found_py3" = "1"; then
411             # Reset everything, so that we can look for another Python.
412             unset PYTHON
413             unset PYTHON_VERSION
414             unset ac_cv_path_PYTHON
415             unset am_cv_pathless_PYTHON
416             unset am_cv_python_version
417             unset am_cv_python_platform
418             unset am_cv_python_pythondir
419             unset am_cv_python_pyexecdir
420             AM_PATH_PYTHON([3.4])
421             if test "$PYTHON"; then
422                 PYTHONS="$(echo $PYTHONS $PYTHON)"
423                 PYTHON_VERSIONS="$(echo $PYTHON_VERSIONS $PYTHON_VERSION)"
424             fi
425         fi
426
427         if test "$PYTHON_VERSIONS"; then
428            enabled_languages_v=$(echo $enabled_languages | sed "s/python\([[23]]\)\?/python ($PYTHON_VERSIONS)/")
429            enabled_languages=$(echo $enabled_languages | sed "s/python\([[23]]\)\?/python/")
430         else
431             if test "$explicit_languages" = "1"; then
432                 AC_MSG_ERROR([[
433 ***
434 *** Please install the python development packages.
435 ***]])
436             else
437                 enabled_languages=$(echo $enabled_languages | sed 's/python//')
438             fi
439         fi
440
441         AC_SUBST(PYTHONS, $PYTHONS)
442         AC_SUBST(PYTHON_VERSIONS, $PYTHON_VERSIONS)
443     fi
444 fi
445
446 AC_SUBST(ENABLED_LANGUAGES, $enabled_languages)
447
448 #
449 # Provide information about the build.
450 #
451 BUILD_REVISION="mym4_revision"
452 AC_SUBST(BUILD_REVISION)
453 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
454                    [GIT commit id revision used to build this package])
455
456 changequote(,)dnl
457 BUILD_FILEVERSION=`echo "$PACKAGE_VERSION"|sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
458 changequote([,])dnl
459 BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec"
460 AC_SUBST(BUILD_FILEVERSION)
461
462 AC_ARG_ENABLE([build-timestamp],
463   AC_HELP_STRING([--enable-build-timestamp],
464                  [set an explicit build timestamp for reproducibility.
465                   (default is the current time in ISO-8601 format)]),
466      [if test "$enableval" = "yes"; then
467         BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
468       else
469         BUILD_TIMESTAMP="$enableval"
470       fi],
471      [BUILD_TIMESTAMP="<none>"])
472 AC_SUBST(BUILD_TIMESTAMP)
473 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
474                    [The time this package was configured for a build])
475
476
477 #
478 # Options to disable some regression tests
479 #
480 run_gpgconf_test="yes"
481 AC_ARG_ENABLE(gpgconf-test,
482   AC_HELP_STRING([--disable-gpgconf-test], [disable GPGCONF regression test]),
483          run_gpgconf_test=$enableval)
484 AM_CONDITIONAL(RUN_GPGCONF_TESTS, test "$run_gpgconf_test" = "yes")
485
486 run_gpg_test="yes"
487 AC_ARG_ENABLE(gpg-test,
488   AC_HELP_STRING([--disable-gpg-test], [disable GPG regression test]),
489          run_gpg_test=$enableval)
490 AM_CONDITIONAL(RUN_GPG_TESTS, test "$run_gpg_test" = "yes")
491
492 run_gpgsm_test="yes"
493 AC_ARG_ENABLE(gpgsm-test,
494   AC_HELP_STRING([--disable-gpgsm-test], [disable GPGSM regression test]),
495          run_gpgsm_test=$enableval)
496 AM_CONDITIONAL(RUN_GPGSM_TESTS, test "$run_gpgsm_test" = "yes")
497
498 run_g13_test="yes"
499 AC_ARG_ENABLE(g13-test,
500   AC_HELP_STRING([--disable-g13-test], [disable G13 regression test]),
501          run_g13_test=$enableval)
502 AM_CONDITIONAL(RUN_G13_TESTS, test "$run_g13_test" = "yes")
503
504
505 # Checks for header files.
506 AC_CHECK_HEADERS_ONCE([locale.h sys/select.h sys/uio.h argp.h
507                        unistd.h sys/time.h sys/types.h sys/stat.h])
508
509
510 # Type checks.
511 AC_C_INLINE
512 AC_CHECK_SIZEOF(unsigned int)
513 AC_SYS_LARGEFILE
514 AC_TYPE_OFF_T
515 AC_TYPE_UINTPTR_T
516
517 # A simple compile time check in gpgme.h for GNU/Linux systems that
518 # prevents a file offset bits mismatch between gpgme and the application.
519 NEED__FILE_OFFSET_BITS=0
520 if test "$have_w32_system" != yes; then
521   case "$ac_cv_sys_file_offset_bits" in
522     "" | no | unknown) ;;
523     *)
524     NEED__FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits
525     ;;
526   esac
527 fi
528 AC_SUBST(NEED__FILE_OFFSET_BITS)
529
530 # Figure out platform dependent typedefs for gpgme.h
531 if test "$have_w32_system" = yes; then
532     INSERT__TYPEDEFS_FOR_GPGME_H="
533 #ifdef _WIN64
534 # include <stdint.h>
535   typedef int64_t gpgme_off_t;
536   typedef int64_t gpgme_ssize_t;
537 #else /* _WIN32 */
538   typedef long gpgme_off_t;
539   typedef long gpgme_ssize_t;
540 #endif /* _WIN32 */"
541     API__OFF_T="gpgme_off_t"
542     API__SSIZE_T="gpgme_ssize_t"
543 else
544     INSERT__TYPEDEFS_FOR_GPGME_H="
545 #include <sys/types.h>
546 typedef off_t   gpgme_off_t;
547 typedef ssize_t gpgme_ssize_t;"
548     API__OFF_T="off_t"
549     API__SSIZE_T="ssize_t"
550 fi
551 AC_SUBST(INSERT__TYPEDEFS_FOR_GPGME_H)
552 AM_SUBST_NOTMAKE(INSERT__TYPEDEFS_FOR_GPGME_H)
553 AC_SUBST(API__OFF_T)
554 AM_SUBST_NOTMAKE(API__OFF_T)
555 AC_SUBST(API__SSIZE_T)
556 AM_SUBST_NOTMAKE(API__SSIZE_T)
557
558 # Checks for compiler features.
559 if test "$GCC" = yes; then
560     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
561     if test "$USE_MAINTAINER_MODE" = "yes"; then
562         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
563
564         # If -Wno-missing-field-initializers is supported we can enable a
565         # a bunch of really useful warnings.
566         AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
567         _gcc_cflags_save=$CFLAGS
568         CFLAGS="-Wno-missing-field-initializers"
569         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
570         AC_MSG_RESULT($_gcc_wopt)
571         CFLAGS=$_gcc_cflags_save;
572         if test x"$_gcc_wopt" = xyes ; then
573           CFLAGS="$CFLAGS -W -Wextra -Wbad-function-cast"
574           CFLAGS="$CFLAGS -Wwrite-strings"
575           CFLAGS="$CFLAGS -Wdeclaration-after-statement"
576           CFLAGS="$CFLAGS -Wno-missing-field-initializers"
577           CFLAGS="$CFLAGS -Wno-sign-compare"
578         fi
579
580         AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
581         _gcc_cflags_save=$CFLAGS
582         CFLAGS="-Wpointer-arith"
583         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
584         AC_MSG_RESULT($_gcc_wopt)
585         CFLAGS=$_gcc_cflags_save;
586         if test x"$_gcc_wopt" = xyes ; then
587           CFLAGS="$CFLAGS -Wpointer-arith"
588         fi
589     fi
590     if test "$have_w32_system" = yes; then
591        CFLAGS="$CFLAGS -mms-bitfields"
592     fi
593 fi
594
595 # Only used for debugging, so no serious test needed (for actual
596 # functionality you have to test libc as well, this only tests the
597 # compiler).
598 AC_CACHE_CHECK([for __thread],[gpgme_cv_tls_works],
599    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([__thread int foo;])],
600                      gpgme_cv_tls_works=yes,gpgme_cv_tls_works=no))
601 if test "$gpgme_cv_tls_works" = yes; then
602   AC_DEFINE(HAVE_TLS, [1], [Define if __thread is supported])
603 fi
604
605
606 # Checks for library functions.
607 AC_MSG_NOTICE([checking for libraries])
608
609 AC_FUNC_FSEEKO
610
611 AC_REPLACE_FUNCS(vasprintf)
612 if test "$ac_cv_func_vasprintf" != yes; then
613   GNUPG_CHECK_VA_COPY
614 fi
615
616 # Try to find a thread-safe version of ttyname().
617 gnupg_REPLACE_TTYNAME_R
618 if test "$ac_cv_func_ttyname_r" != yes; then
619   AC_MSG_WARN([
620 ***
621 *** ttyname() is not thread-safe and ttyname_r() does not exist
622 ***])
623 fi
624
625 # Try to find a thread-safe version of getenv().
626 have_thread_safe_getenv=no
627 jm_GLIBC21
628 if test $GLIBC21 = yes; then
629   have_thread_safe_getenv=yes
630 fi
631 if test $have_thread_safe_getenv = yes; then
632   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
633 fi
634 have_getenv_r=no
635 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
636 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
637   AC_MSG_WARN([
638 ***
639 *** getenv() is not thread-safe and getenv_r() does not exist
640 ***])
641 fi
642
643 # For converting time strings to seconds since Epoch, we need the timegm
644 # function.
645 AC_CHECK_FUNCS(timegm)
646 if test "$ac_cv_func_timegm" != yes; then
647   AC_MSG_WARN([
648 ***
649 *** timegm() not available - a non-thread-safe kludge will be used
650 *** and the TZ variable might be changed at runtime.
651 ***])
652 fi
653
654 AC_CHECK_FUNCS(setlocale)
655
656 # Checking for libgpg-error.
657 have_gpg_error=no
658 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION",
659                   have_gpg_error=yes, have_gpg_error=no)
660 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
661           [The default error source for GPGME.])
662
663 # And for libassuan.
664 have_libassuan=no
665 AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
666                   have_libassuan=yes, have_libassuan=no)
667 if test "$have_libassuan" = "yes"; then
668   AC_DEFINE_UNQUOTED(GPGME_LIBASSUAN_VERSION, "$libassuan_version",
669                      [version of the libassuan library])
670 fi
671
672
673 #
674 # Other checks
675 #
676
677 # Check for funopen
678 AC_CHECK_FUNCS(funopen)
679 if test $ac_cv_func_funopen != yes; then
680     # No funopen but we can implement that in terms of fopencookie.
681     AC_CHECK_FUNCS(fopencookie)
682     if test $ac_cv_func_fopencookie = yes; then
683         AC_REPLACE_FUNCS(funopen)
684     else
685         AC_MSG_WARN([
686 ***
687 *** No implementation of fopencookie or funopen available
688 ***])
689     fi
690 fi
691
692 # Check for getgid etc
693 AC_CHECK_FUNCS(getgid getegid)
694
695
696 # Replacement functions.
697 AC_REPLACE_FUNCS(stpcpy)
698 AC_REPLACE_FUNCS(setenv)
699
700 # Assuan check for descriptor passing.
701 AC_CHECK_MEMBER(struct cmsghdr.cmsg_len,
702                 [supports_descriptor_passing=yes],
703                 [supports_descriptor_passing=no
704                  AC_MSG_WARN([
705 ***
706 *** Data structure for sending ancillary data missing.
707 *** Descriptor passing won't work.
708 ***])],[
709 #include <stdlib.h>
710 #include <stddef.h>
711 #include <stdio.h>
712 #include <sys/types.h>
713 #include <sys/socket.h>
714 #include <sys/un.h>
715 #if HAVE_SYS_UIO_H
716 #include <sys/uio.h>
717 #endif
718 #include <unistd.h>
719        ])
720
721
722 dnl There seems to be a problem with Apple and decriptor passing.
723 dnl Until we found a solution we change the default to no.
724 dnl See bug 1483.
725 case "${host}" in
726     *-apple-darwin*)
727       use_descriptor_passing=no
728       ;;
729     *)
730       use_descriptor_passing=yes
731       ;;
732 esac
733 AC_ARG_ENABLE(fd-passing,
734   AC_HELP_STRING([--disable-fd-passing], [do not use FD passing]),
735   use_descriptor_passing=$enableval)
736
737 if test "$supports_descriptor_passing" != "yes"; then
738   use_descriptor_passing=no
739 fi
740
741 if test "$use_descriptor_passing" = "yes"; then
742 AC_DEFINE(USE_DESCRIPTOR_PASSING,1,
743           [Defined if descriptor passing is enabled and supported])
744 fi
745
746 AM_CONDITIONAL(USE_DESCRIPTOR_PASSING, test "$use_descriptor_passing" = "yes")
747
748
749 uiserver=no
750 if test "$use_descriptor_passing" = "yes" && test "$have_libassuan" = "yes"; then
751   uiserver=yes
752 fi
753 if test "$uiserver" != "no"; then
754   AC_DEFINE(ENABLE_UISERVER, 1,
755             [Defined if we are building with uiserver support.])
756 fi
757 AM_CONDITIONAL(HAVE_UISERVER, test "$uiserver" != "no")
758
759
760 # Add a few constants to help porting to W32
761 AH_VERBATIM([SEPCONSTANTS],
762 [
763 /* Separators as used in $PATH and file name.  */
764 #ifdef HAVE_DOSISH_SYSTEM
765 #define PATHSEP_C ';'
766 #define DIRSEP_C '\\'
767 #define DIRSEP_S "\\"
768 #else
769 #define PATHSEP_C ':'
770 #define DIRSEP_C '/'
771 #define DIRSEP_S "/"
772 #endif
773 ])
774
775 AH_BOTTOM([
776 /* Definition of GCC specific attributes.  */
777 #if __GNUC__ > 2
778 # define GPGME_GCC_A_PURE  __attribute__ ((__pure__))
779 #else
780 # define GPGME_GCC_A_PURE
781 #endif
782
783 /* Under WindowsCE we need gpg-error's strerror macro.  */
784 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
785
786 #define CRIGHTBLURB "Copyright (C) 2000 Werner Koch\n" \
787                     "Copyright (C) 2001--2015 g10 Code GmbH\n"
788 ])
789
790
791 # Substitution used for gpgme-config
792 GPGME_CONFIG_LIBS="-lgpgme"
793 GPGME_CONFIG_CFLAGS=""
794 GPGME_CONFIG_HOST="$host"
795 GPGME_CONFIG_AVAIL_LANG="$enabled_languages"
796 AC_SUBST(GPGME_CONFIG_API_VERSION)
797 AC_SUBST(GPGME_CONFIG_LIBS)
798 AC_SUBST(GPGME_CONFIG_CFLAGS)
799 AC_SUBST(GPGME_CONFIG_HOST)
800 AC_SUBST(GPGME_CONFIG_AVAIL_LANG)
801
802 # Frob'da Variables
803 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
804            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
805 AC_SUBST(LTLIBOBJS)
806
807 # Some checks for gpgme-tool
808 # Done at top: AC_CHECK_HEADER([argp.h])
809 AC_CHECK_TYPES([error_t], [],
810    [AC_DEFINE([error_t], [int],
811    [Define to a type to use for `error_t' if it is not otherwise available.])],
812    [#include <errno.h>])
813
814
815 # A substitution to set generated files in a Emacs buffer to read-only.
816 AC_SUBST(emacs_local_vars_begin, [['Local][ ][Variables:']])
817 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
818 AC_SUBST(emacs_local_vars_end, ['End:'])
819
820 # Last check.
821 die=no
822 if test "$have_gpg_error" = "no"; then
823    die=yes
824    AC_MSG_NOTICE([[
825 ***
826 *** You need libgpg-error to build this program.
827 **  This library is for example available at
828 ***   ftp://ftp.gnupg.org/gcrypt/libgpg-error
829 *** (at least version $NEED_GPG_ERROR_VERSION is required.)
830 ***]])
831 fi
832 if test "$have_libassuan" = "no"; then
833    die=yes
834    AC_MSG_NOTICE([[
835 ***
836 *** You need libassuan to build this program.
837 *** This library is for example available at
838 ***   ftp://ftp.gnupg.org/gcrypt/libassuan/
839 *** (at least version $NEED_LIBASSUAN_VERSION (API $NEED_LIBASSUAN_API) is required).
840 ***]])
841 fi
842
843 if test "$die" = "yes"; then
844     AC_MSG_ERROR([[
845 ***
846 *** Required libraries not found. Please consult the above messages
847 *** and install them before running configure again.
848 ***]])
849 fi
850
851
852 #
853 # Create config files
854
855 AC_CONFIG_FILES(Makefile src/Makefile
856                 tests/Makefile
857                 tests/gpg/Makefile
858                 tests/gpgsm/Makefile
859                 tests/opassuan/Makefile
860                 doc/Makefile
861                 src/versioninfo.rc
862                 src/gpgme.h)
863 AC_CONFIG_FILES(src/gpgme-config, chmod +x src/gpgme-config)
864 AC_CONFIG_FILES(lang/cpp/Makefile lang/cpp/src/Makefile)
865 AC_CONFIG_FILES(lang/cpp/src/GpgmeppConfig.cmake.in)
866 AC_CONFIG_FILES(lang/cpp/src/GpgmeppConfigVersion.cmake)
867 AC_CONFIG_FILES(lang/cpp/src/gpgmepp_version.h)
868 AC_CONFIG_FILES(lang/qt/Makefile lang/qt/src/Makefile)
869 AC_CONFIG_FILES(lang/qt/src/QGpgmeConfig.cmake.in)
870 AC_CONFIG_FILES(lang/qt/src/QGpgmeConfigVersion.cmake)
871 AC_CONFIG_FILES(lang/qt/tests/Makefile)
872 AC_CONFIG_FILES(lang/qt/src/qgpgme_version.h)
873 AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpgme.asd])
874 AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([lang/qt/doc/Doxyfile])])
875 AC_CONFIG_FILES(lang/qt/doc/Makefile)
876 AC_CONFIG_FILES([lang/python/Makefile
877                  lang/python/setup.py
878                  lang/python/pyme/version.py
879                  lang/python/tests/Makefile])
880 AC_OUTPUT
881
882 echo "
883         GPGME v${VERSION} has been configured as follows:
884
885         Revision:          mym4_revision  (mym4_revision_dec)
886         Platform:          $host
887
888         UI Server:         $uiserver
889         FD Passing:        $use_descriptor_passing
890         GPGME Pthread:     $have_pthread
891
892         Language bindings: ${enabled_languages_v:-$enabled_languages}
893 "
894 if test "x${gpg_config_script_warn}" != x; then
895 cat <<G10EOF
896         Mismatches between the target platform and the to
897         be used libraries have been been detected for:
898          ${gpg_config_script_warn}
899         Please check above for warning messages.
900
901 G10EOF
902 fi