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