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