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