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