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