13989931b4699b2d0ee2f2d2074211cee9debe35
[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     *-linux-androideabi)
190         have_android_system=yes
191         ;;
192     *-apple-darwin*)
193         have_macos_system=yes
194         ;;
195 esac
196 case "${host}" in
197     *-mingw32*)
198         have_dosish_system=yes
199         have_w32_system=yes
200         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
201         GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
202         GPGCONF_DEFAULT='c:\\gnupg\\gpgconf.exe'
203         G13_DEFAULT='c:\\gnupg\\g13.exe'
204         #component_system='COM+'
205
206         AM_PATH_GLIB_2_0
207         AC_ARG_ENABLE(w32-glib,
208             AC_HELP_STRING([--enable-w32-glib], [build GPGME Glib for W32]),
209                            build_w32_glib=$enableval)
210        ;;
211     *)
212
213         # XXX: Probably use exec-prefix here?
214 #       GPG_DEFAULT='/usr/bin/gpg'
215 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
216 #       GPGCONF_DEFAULT='/usr/bin/gpgconf'
217 #       G13_DEFAULT='/usr/bin/g13'
218         ;;
219 esac
220
221 if test "$have_dosish_system" = yes; then
222    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
223              [Defined if we run on some of the PCDOS like systems
224               (DOS, Windoze. OS/2) with special properties like
225               no file modes])
226 fi
227 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
228
229 if test "$have_w32_system" = yes; then
230    AC_DEFINE(HAVE_W32_SYSTEM,1,
231              [Defined if we run on any kind of W32 API based system])
232 fi
233 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
234
235 if test "$have_w64_system" = yes; then
236    AC_DEFINE(HAVE_W64_SYSTEM,1,
237              [Defined if we run on a 64 bit W32 API based system])
238 fi
239 AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
240
241 if test "$have_android_system" = yes; then
242    AC_DEFINE(HAVE_ANDROID_SYSTEM,1, [Defined if we build for an Android system])
243 fi
244 AM_CONDITIONAL(HAVE_ANDROID_SYSTEM, test "$have_android_system" = yes)
245
246 if test "$have_macos_system" = yes; then
247    AC_DEFINE(HAVE_MACOS_SYSTEM,1,
248              [Defined if we build for an MacOS system])
249 fi
250 AM_CONDITIONAL(HAVE_MACOS_SYSTEM, test "$have_macos_system" = yes)
251
252 AM_CONDITIONAL(BUILD_W32_GLIB, test "$build_w32_glib" = yes)
253
254
255 AC_ARG_ENABLE([fixed-path],
256               AC_HELP_STRING([--enable-fixed-path=PATH],
257                              [locate binaries only via this PATH]),
258               [fixed_search_path="$enableval"],
259               [fixed_search_path=""])
260 if test x$fixed_search_path != x ; then
261   AC_DEFINE_UNQUOTED(FIXED_SEARCH_PATH, "$fixed_search_path",
262                     [Locate binaries only via this PATH])
263 fi
264
265
266 # Note: You need to declare all possible languages also in
267 #       lang/Makefile.am's DIST_SUBDIRS.
268 AC_ARG_ENABLE([languages],
269               AC_HELP_STRING([--enable-languages=languages],
270                              [enable only specific language bindings]),
271                              [enabled_languages=`echo $enableval | \
272                              tr ',:' '  ' | tr '[A-Z]' '[a-z]' | \
273                              sed 's/c++/cpp/'`],
274                              [enabled_languages="maybe"])
275 if test "x$enabled_languages" = "x" \
276    -o "$enabled_languages" = "no"; then
277    enabled_languages=
278 fi
279
280 # If languages are explicitly set missing requirements
281 # for the languages are treated as errors otherwise
282 # there will be a warning.
283 explicit_languages=1
284 if test "x$enabled_languages" = "xmaybe"; then
285     explicit_languages=0
286     enabled_languages="$default_languages"
287 fi
288
289 for language in $enabled_languages; do
290     LIST_MEMBER($language, $available_languages)
291     if test "$found" = "0"; then
292        AC_MSG_ERROR([unsupported language binding specified])
293     fi
294 done
295
296
297
298 # Enable C++ 11 if cpp language is requested
299 LIST_MEMBER("cpp", $enabled_languages)
300 if test "$found" = "1"; then
301     AX_CXX_COMPILE_STDCXX(11, noext, optional)
302     if test "$HAVE_CXX11" != "1"; then
303         if test "$explicit_languages" = "1"; then
304             AC_MSG_ERROR([[
305 ***
306 *** A compiler with c++11 support is required for the c++ binding.
307 ***]])
308         else
309             enabled_languages=$(echo $enabled_languages | sed 's/cpp//')
310             enabled_languages=$(echo $enabled_languages | sed 's/qt//')
311             AC_MSG_WARN([[
312 ***
313 *** No c++11 support detected. C++ and Qt bindings will be disabled.
314 ***]])
315         fi
316     fi
317 fi
318
319 # Check that if qt is enabled cpp also is enabled
320 LIST_MEMBER("qt", $enabled_languages)
321 if test "$found" = "1"; then
322     # We need to ensure that in the language order qt comes after cpp
323     # so we remove qt first and explicitly add it as last list member.
324     enabled_languages=$(echo $enabled_languages | sed 's/qt//')
325     LIST_MEMBER("cpp", $enabled_languages)
326     if test "$found" = "0"; then
327         AC_MSG_ERROR([[
328 ***
329 *** Qt language binding depends on cpp binding.
330 ***]])
331     fi
332     FIND_QT
333     if test "$have_qt5_libs" != "yes"; then
334         if test "$explicit_languages" = "1"; then
335         AC_MSG_ERROR([[
336 ***
337 *** Qt5 (Qt5Core) is required for Qt binding.
338 ***]])
339         else
340            AC_MSG_WARN([[
341 ***
342 *** Qt5 (Qt5Core) not found Qt Binding will be disabled.
343 ***]])
344         fi
345     else
346         enabled_languages=`echo $enabled_languages qt`
347
348         AC_CHECK_PROGS([DOXYGEN], [doxygen])
349         if test -z "$DOXYGEN";
350             # This is not highlighted becase it's not really important.
351             then AC_MSG_WARN([Doxygen not found - Qt binding doc will not be built.])
352         fi
353         AC_CHECK_PROGS([GRAPHVIZ], [dot])
354         if test -z "$GRAPHVIZ";
355             then AC_MSG_WARN([Graphviz not found - Qt binding doc will not have diagrams.])
356         fi
357     fi
358 fi
359 AM_CONDITIONAL([HAVE_DOXYGEN],
360                [test -n "$DOXYGEN"])
361 if test -n "$GRAPHVIZ"; then
362     HAVE_DOT="YES"
363 else
364     HAVE_DOT="NO"
365 fi
366 AC_SUBST(HAVE_DOT)
367
368 # Python bindings.
369 LIST_MEMBER("python", $enabled_languages)
370 found_py=$found
371 if test "$found_py" = "1"; then
372     AX_PKG_SWIG
373     if test -z "$SWIG"; then
374         if test "$explicit_languages" = "1"; then
375             AC_MSG_ERROR([[
376 ***
377 *** You need SWIG to build the Python bindings.
378 ***]])
379         else
380             enabled_languages=$(echo $enabled_languages | sed 's/python//')
381         fi
382     else
383         # Reset the version collecting vars.
384         PYTHONS=
385         PYTHON_VERSIONS=
386
387         if test "$found_py" = "1" -o "$found_py3" = "1"; then
388           # Reset everything, so that we can look for another Python.
389           m4_foreach([mym4pythonver],
390                      [[2.7],[3.4],[3.5],[3.6],[3.7],[3.8],[all]],
391            [unset PYTHON
392             unset PYTHON_VERSION
393             unset PYTHON_CPPFLAGS
394             unset PYTHON_LDFLAGS
395             unset PYTHON_SITE_PKG
396             unset PYTHON_EXTRA_LIBS
397             unset PYTHON_EXTRA_LDFLAGS
398             unset ac_cv_path_PYTHON
399             unset am_cv_pathless_PYTHON
400             unset am_cv_python_version
401             unset am_cv_python_platform
402             unset am_cv_python_pythondir
403             unset am_cv_python_pyexecdir
404             AM_PATH_PYTHON(mym4pythonver, [
405                 AX_PYTHON_DEVEL
406                 if test "$PYTHON_VERSION"; then
407                         PYTHONS="$(echo $PYTHONS $PYTHON)"
408                         PYTHON_VERSIONS="$(echo $PYTHON_VERSIONS $PYTHON_VERSION)"
409                 fi
410             ], :, m4_if([mym4pythonver],[all],[],[python]mym4pythonver))
411            ])
412         fi
413
414         # Recover some values lost in the second attempt to find Python.
415         PYTHON="$(echo $PYTHONS | cut -d ' ' -f 1)"
416         PYTHON_VERSION="$(echo $PYTHON_VERSIONS | cut -d ' ' -f 1)"
417
418         # Remove duplicates.
419         PYTHONS="$(echo $PYTHONS | tr '[[:space:]]' '\n' | sort | uniq | tr '\n' ' ' | sed -e 's/ $//')"
420         PYTHON_VERSIONS="$(echo $PYTHON_VERSIONS | tr '[[:space:]]' '\n' | sort | uniq | tr '\n' ' ' | sed -e 's/ $//')"
421
422         if test "$PYTHON_VERSIONS"; then
423            enabled_languages_v=$(echo $enabled_languages | sed -Ee "s/python[[23]]?/python ($PYTHON_VERSIONS)/")
424            enabled_languages=$(echo $enabled_languages | sed -Ee "s/python[[23]]?/python/")
425         else
426             if test "$explicit_languages" = "1"; then
427                 AC_MSG_ERROR([[
428 ***
429 *** Please install the python development packages.
430 ***]])
431             else
432                 enabled_languages=$(echo $enabled_languages | sed 's/python//')
433             fi
434         fi
435
436         AC_SUBST(PYTHONS, $PYTHONS)
437     fi
438 fi
439
440 AC_SUBST(ENABLED_LANGUAGES, $enabled_languages)
441
442 #
443 # Provide information about the build.
444 #
445 BUILD_REVISION="mym4_revision"
446 AC_SUBST(BUILD_REVISION)
447 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
448                    [GIT commit id revision used to build this package])
449
450 changequote(,)dnl
451 BUILD_VERSION=`echo "$PACKAGE_VERSION" | sed 's/\([0-9.]*\).*/\1./'`
452 changequote([,])dnl
453 BUILD_VERSION="${BUILD_VERSION}mym4_revision_dec"
454 BUILD_FILEVERSION=`echo "${BUILD_VERSION}" | tr . ,`
455 AC_SUBST(BUILD_VERSION)
456 AC_SUBST(BUILD_FILEVERSION)
457
458 AC_ARG_ENABLE([build-timestamp],
459   AC_HELP_STRING([--enable-build-timestamp],
460                  [set an explicit build timestamp for reproducibility.
461                   (default is the current time in ISO-8601 format)]),
462      [if test "$enableval" = "yes"; then
463         BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
464       else
465         BUILD_TIMESTAMP="$enableval"
466       fi],
467      [BUILD_TIMESTAMP="<none>"])
468 AC_SUBST(BUILD_TIMESTAMP)
469 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
470                    [The time this package was configured for a build])
471
472
473 #
474 # Options to disable some regression tests
475 #
476 run_gpgconf_test="yes"
477 AC_ARG_ENABLE(gpgconf-test,
478   AC_HELP_STRING([--disable-gpgconf-test], [disable GPGCONF regression test]),
479          run_gpgconf_test=$enableval)
480 AM_CONDITIONAL(RUN_GPGCONF_TESTS, test "$run_gpgconf_test" = "yes")
481
482 run_gpg_test="yes"
483 AC_ARG_ENABLE(gpg-test,
484   AC_HELP_STRING([--disable-gpg-test], [disable GPG regression test]),
485          run_gpg_test=$enableval)
486 AM_CONDITIONAL(RUN_GPG_TESTS, test "$run_gpg_test" = "yes")
487
488 run_gpgsm_test="yes"
489 AC_ARG_ENABLE(gpgsm-test,
490   AC_HELP_STRING([--disable-gpgsm-test], [disable GPGSM regression test]),
491          run_gpgsm_test=$enableval)
492 AM_CONDITIONAL(RUN_GPGSM_TESTS, test "$run_gpgsm_test" = "yes")
493
494 run_g13_test="yes"
495 AC_ARG_ENABLE(g13-test,
496   AC_HELP_STRING([--disable-g13-test], [disable G13 regression test]),
497          run_g13_test=$enableval)
498 AM_CONDITIONAL(RUN_G13_TESTS, test "$run_g13_test" = "yes")
499
500
501 # Checks for header files.
502 AC_CHECK_HEADERS_ONCE([locale.h sys/select.h sys/uio.h argp.h stdint.h
503                        unistd.h sys/time.h sys/types.h sys/stat.h])
504
505
506 # Type checks.
507 AC_C_INLINE
508 AC_CHECK_SIZEOF(unsigned int)
509 AC_SYS_LARGEFILE
510 AC_TYPE_OFF_T
511 AC_TYPE_UINTPTR_T
512
513 # We require uint64_t
514 if test "$ac_cv_header_stdint_h" != yes; then
515    AC_MSG_ERROR([[
516 ***
517 *** No stdint.h and thus no uint64_t type.  Can't build this library.
518 ***]])
519 fi
520
521
522 # A simple compile time check in gpgme.h for GNU/Linux systems that
523 # prevents a file offset bits mismatch between gpgme and the application.
524 NEED__FILE_OFFSET_BITS=0
525 if test "$have_w32_system" != yes; then
526   case "$ac_cv_sys_file_offset_bits" in
527     "" | no | unknown) ;;
528     *)
529     NEED__FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits
530     ;;
531   esac
532 fi
533 AC_SUBST(NEED__FILE_OFFSET_BITS)
534
535 # Figure out platform dependent typedefs for gpgme.h
536 if test "$have_w32_system" = yes; then
537     INSERT__TYPEDEFS_FOR_GPGME_H="
538 #ifdef _WIN64
539 # include <stdint.h>
540   typedef int64_t gpgme_off_t;
541   typedef int64_t gpgme_ssize_t;
542 #else /* _WIN32 */
543   typedef long gpgme_off_t;
544   typedef long gpgme_ssize_t;
545 #endif /* _WIN32 */"
546     API__OFF_T="gpgme_off_t"
547     API__SSIZE_T="gpgme_ssize_t"
548 else
549     INSERT__TYPEDEFS_FOR_GPGME_H="
550 #include <sys/types.h>
551 typedef off_t   gpgme_off_t;
552 typedef ssize_t gpgme_ssize_t;"
553     API__OFF_T="off_t"
554     API__SSIZE_T="ssize_t"
555 fi
556 AC_SUBST(INSERT__TYPEDEFS_FOR_GPGME_H)
557 AM_SUBST_NOTMAKE(INSERT__TYPEDEFS_FOR_GPGME_H)
558 AC_SUBST(API__OFF_T)
559 AM_SUBST_NOTMAKE(API__OFF_T)
560 AC_SUBST(API__SSIZE_T)
561 AM_SUBST_NOTMAKE(API__SSIZE_T)
562
563 # Checks for compiler features.
564 if test "$GCC" = yes; then
565     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
566     if test "$USE_MAINTAINER_MODE" = "yes"; then
567         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
568
569         # If -Wno-missing-field-initializers is supported we can enable a
570         # a bunch of really useful warnings.
571         AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
572         _gcc_cflags_save=$CFLAGS
573         CFLAGS="-Wno-missing-field-initializers"
574         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
575         AC_MSG_RESULT($_gcc_wopt)
576         CFLAGS=$_gcc_cflags_save;
577         if test x"$_gcc_wopt" = xyes ; then
578           CFLAGS="$CFLAGS -W -Wextra -Wbad-function-cast"
579           CFLAGS="$CFLAGS -Wwrite-strings"
580           CFLAGS="$CFLAGS -Wdeclaration-after-statement"
581           CFLAGS="$CFLAGS -Wno-missing-field-initializers"
582           CFLAGS="$CFLAGS -Wno-sign-compare"
583         fi
584         CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wno-shadow"
585
586         AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
587         _gcc_cflags_save=$CFLAGS
588         CFLAGS="-Wpointer-arith"
589         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
590         AC_MSG_RESULT($_gcc_wopt)
591         CFLAGS=$_gcc_cflags_save;
592         if test x"$_gcc_wopt" = xyes ; then
593           CFLAGS="$CFLAGS -Wpointer-arith"
594         fi
595     fi
596     if test "$have_w32_system" = yes; then
597        CFLAGS="$CFLAGS -mms-bitfields"
598     fi
599 fi
600
601 # Only used for debugging, so no serious test needed (for actual
602 # functionality you have to test libc as well, this only tests the
603 # compiler).
604 AC_CACHE_CHECK([for __thread],[gpgme_cv_tls_works],
605    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([__thread int foo;])],
606                      gpgme_cv_tls_works=yes,gpgme_cv_tls_works=no))
607 if test "$gpgme_cv_tls_works" = yes; then
608   AC_DEFINE(HAVE_TLS, [1], [Define if __thread is supported])
609 fi
610
611
612 # Checks for library functions.
613 AC_MSG_NOTICE([checking for libraries])
614
615 AC_FUNC_FSEEKO
616
617 # Try to find a thread-safe version of ttyname().
618 gnupg_REPLACE_TTYNAME_R
619 if test "$ac_cv_func_ttyname_r" != yes; then
620   AC_MSG_WARN([
621 ***
622 *** ttyname() is not thread-safe and ttyname_r() does not exist
623 ***])
624 fi
625
626 # Try to find a thread-safe version of getenv().
627 have_thread_safe_getenv=no
628 jm_GLIBC21
629 if test $GLIBC21 = yes -o $have_w32_system = yes; then
630   have_thread_safe_getenv=yes
631 fi
632 if test $have_thread_safe_getenv = yes; then
633   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
634 fi
635 have_getenv_r=no
636 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
637 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
638   AC_MSG_WARN([
639 ***
640 *** getenv() is not thread-safe and getenv_r() does not exist
641 ***])
642 fi
643
644 # For converting time strings to seconds since Epoch, we need the timegm
645 # function.
646 AC_CHECK_FUNCS(timegm)
647 if test "$ac_cv_func_timegm" != yes; then
648   AC_MSG_WARN([
649 ***
650 *** timegm() not available - a non-thread-safe kludge will be used
651 *** and the TZ variable might be changed at runtime.
652 ***])
653 fi
654
655 AC_CHECK_FUNCS(setlocale)
656
657 # Checking for libgpg-error.
658 have_gpg_error=no
659 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION",
660                   have_gpg_error=yes, have_gpg_error=no)
661 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
662           [The default error source for GPGME.])
663
664 # And for libassuan.
665 have_libassuan=no
666 AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
667                   have_libassuan=yes, have_libassuan=no)
668 if test "$have_libassuan" = "yes"; then
669   AC_DEFINE_UNQUOTED(GPGME_LIBASSUAN_VERSION, "$libassuan_version",
670                      [version of the libassuan library])
671 fi
672
673
674 #
675 # Other checks
676 #
677
678 # Check for getgid etc
679 AC_CHECK_FUNCS(getgid getegid closefrom)
680
681
682 # Replacement functions.
683 AC_REPLACE_FUNCS(stpcpy)
684 AC_REPLACE_FUNCS(setenv)
685
686 # Assuan check for descriptor passing.
687 AC_CHECK_MEMBER(struct cmsghdr.cmsg_len,
688                 [supports_descriptor_passing=yes],
689                 [supports_descriptor_passing=no
690                  AC_MSG_WARN([
691 ***
692 *** Data structure for sending ancillary data missing.
693 *** Descriptor passing won't work.
694 ***])],[
695 #include <stdlib.h>
696 #include <stddef.h>
697 #include <stdio.h>
698 #include <sys/types.h>
699 #include <sys/socket.h>
700 #include <sys/un.h>
701 #if HAVE_SYS_UIO_H
702 #include <sys/uio.h>
703 #endif
704 #include <unistd.h>
705        ])
706
707 use_descriptor_passing=yes
708 AC_ARG_ENABLE(fd-passing,
709   AC_HELP_STRING([--disable-fd-passing], [do not use FD passing]),
710   use_descriptor_passing=$enableval)
711
712 if test "$supports_descriptor_passing" != "yes"; then
713   use_descriptor_passing=no
714 fi
715
716 if test "$use_descriptor_passing" = "yes"; then
717 AC_DEFINE(USE_DESCRIPTOR_PASSING,1,
718           [Defined if descriptor passing is enabled and supported])
719 fi
720
721 AM_CONDITIONAL(USE_DESCRIPTOR_PASSING, test "$use_descriptor_passing" = "yes")
722
723
724 uiserver=no
725 if test "$use_descriptor_passing" = "yes" && test "$have_libassuan" = "yes"; then
726   uiserver=yes
727 fi
728 if test "$uiserver" != "no"; then
729   AC_DEFINE(ENABLE_UISERVER, 1,
730             [Defined if we are building with uiserver support.])
731 fi
732 AM_CONDITIONAL(HAVE_UISERVER, test "$uiserver" != "no")
733
734
735 # Option --disable-linux-getdents
736 #
737 # By default we use SYS_getdents on Linux to optimize fd closing
738 # before an exec.  This option allows to switch this optimization off.
739 use_linux_getdents=yes
740 AC_ARG_ENABLE(linux-getdents,
741               AC_HELP_STRING([--disable-linux-getdents],
742                              [do not use SYS_getdents on Linux]),
743               use_linux_getdents=$enableval)
744 if test "$use_linux_getdents" = "yes"; then
745     case "${host}" in
746         *-*-linux*)
747            AC_DEFINE(USE_LINUX_GETDENTS,1,
748                      [Defined if SYS_getdents can be used on Linux])
749            ;;
750     esac
751 fi
752
753
754 #
755 # Add a few constants to help porting to W32
756 #
757 AH_VERBATIM([SEPCONSTANTS],
758 [
759 /* Separators as used in $PATH and file name.  */
760 #ifdef HAVE_DOSISH_SYSTEM
761 #define PATHSEP_C ';'
762 #define DIRSEP_C '\\'
763 #define DIRSEP_S "\\"
764 #else
765 #define PATHSEP_C ':'
766 #define DIRSEP_C '/'
767 #define DIRSEP_S "/"
768 #endif
769 ])
770
771 AH_BOTTOM([
772 /* Definition of GCC specific attributes.  */
773 #if __GNUC__ > 2
774 # define GPGME_GCC_A_PURE  __attribute__ ((__pure__))
775 #else
776 # define GPGME_GCC_A_PURE
777 #endif
778
779 /* Under WindowsCE we need gpg-error's strerror macro.  */
780 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
781
782 #define CRIGHTBLURB "Copyright (C) 2000 Werner Koch\n" \
783                     "Copyright (C) 2001--2018 g10 Code GmbH\n"
784 ])
785
786
787 # Substitution used for gpgme-config
788 GPGME_CONFIG_LIBS="-lgpgme"
789 GPGME_CONFIG_CFLAGS=""
790 GPGME_CONFIG_HOST="$host"
791 GPGME_CONFIG_AVAIL_LANG="$enabled_languages"
792 AC_SUBST(GPGME_CONFIG_API_VERSION)
793 AC_SUBST(GPGME_CONFIG_LIBS)
794 AC_SUBST(GPGME_CONFIG_CFLAGS)
795 AC_SUBST(GPGME_CONFIG_HOST)
796 AC_SUBST(GPGME_CONFIG_AVAIL_LANG)
797
798 # Frob'da Variables
799 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
800            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
801 AC_SUBST(LTLIBOBJS)
802
803 # Some checks for gpgme-tool
804 # Done at top: AC_CHECK_HEADER([argp.h])
805 AC_CHECK_TYPES([error_t], [],
806    [AC_DEFINE([error_t], [int],
807    [Define to a type to use for `error_t' if it is not otherwise available.])],
808    [#include <errno.h>])
809
810
811 # A substitution to set generated files in a Emacs buffer to read-only.
812 AC_SUBST(emacs_local_vars_begin, [['Local][ ][Variables:']])
813 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
814 AC_SUBST(emacs_local_vars_end, ['End:'])
815
816 # Last check.
817 die=no
818 if test "$have_gpg_error" = "no"; then
819    die=yes
820    AC_MSG_NOTICE([[
821 ***
822 *** You need libgpg-error to build this program.
823 **  This library is for example available at
824 ***   https://www.gnupg.org/ftp/gcrypt/libgpg-error/
825 *** (at least version $NEED_GPG_ERROR_VERSION is required.)
826 ***]])
827 fi
828 if test "$have_libassuan" = "no"; then
829    die=yes
830    AC_MSG_NOTICE([[
831 ***
832 *** You need libassuan to build this program.
833 *** This library is for example available at
834 ***   https://www.gnupg.org/ftp/gcrypt/libassuan/
835 *** (at least version $NEED_LIBASSUAN_VERSION (API $NEED_LIBASSUAN_API) is required).
836 ***]])
837 fi
838
839 if test "$die" = "yes"; then
840     AC_MSG_ERROR([[
841 ***
842 *** Required libraries not found. Please consult the above messages
843 *** and install them before running configure again.
844 ***]])
845 fi
846
847
848 #
849 # Create config files
850
851 AC_CONFIG_FILES(Makefile src/Makefile
852                 tests/Makefile
853                 tests/gpg/Makefile
854                 tests/gpgsm/Makefile
855                 tests/opassuan/Makefile
856                 doc/Makefile
857                 src/versioninfo.rc
858                 src/gpgme.h)
859 AC_CONFIG_FILES(src/gpgme-config, chmod +x src/gpgme-config)
860 AC_CONFIG_FILES(lang/cpp/Makefile lang/cpp/src/Makefile)
861 AC_CONFIG_FILES(lang/cpp/tests/Makefile)
862 AC_CONFIG_FILES(lang/cpp/src/GpgmeppConfig-w32.cmake.in)
863 AC_CONFIG_FILES(lang/cpp/src/GpgmeppConfig.cmake.in)
864 AC_CONFIG_FILES(lang/cpp/src/GpgmeppConfigVersion.cmake)
865 AC_CONFIG_FILES(lang/cpp/src/gpgmepp_version.h)
866 AC_CONFIG_FILES(lang/qt/Makefile lang/qt/src/Makefile)
867 AC_CONFIG_FILES(lang/qt/src/QGpgmeConfig-w32.cmake.in)
868 AC_CONFIG_FILES(lang/qt/src/QGpgmeConfig.cmake.in)
869 AC_CONFIG_FILES(lang/qt/src/QGpgmeConfigVersion.cmake)
870 AC_CONFIG_FILES(lang/qt/tests/Makefile)
871 AC_CONFIG_FILES(lang/qt/src/qgpgme_version.h)
872 AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpgme.asd])
873 AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([lang/qt/doc/Doxyfile])])
874 AC_CONFIG_FILES([lang/js/Makefile lang/js/src/Makefile
875                  lang/js/BrowserTestExtension/Makefile
876                  lang/js/DemoExtension/Makefile])
877 AC_CONFIG_FILES(lang/qt/doc/Makefile)
878 AC_CONFIG_FILES([lang/python/Makefile
879                  lang/python/version.py
880                  lang/python/tests/Makefile])
881 AC_CONFIG_FILES([lang/python/setup.py], [chmod a+x lang/python/setup.py])
882 AC_OUTPUT
883
884 echo "
885         GPGME v${VERSION} has been configured as follows:
886
887         Revision:          mym4_revision  (mym4_revision_dec)
888         Platform:          $host
889
890         UI Server:         $uiserver
891         FD Passing:        $use_descriptor_passing
892
893         Language bindings: ${enabled_languages_v:-$enabled_languages}
894 "
895 if test "x${gpg_config_script_warn}" != x; then
896 cat <<G10EOF
897         Mismatches between the target platform and the to
898         be used libraries have been been detected for:
899          ${gpg_config_script_warn}
900         Please check above for warning messages.
901
902 G10EOF
903 fi