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