1 # configure.ac - for libksba
2 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 # 2010, 2011, 2012, 2018, 2019 g10 Code GmbH
5 # This file is part of KSBA
7 # KSBA is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # KSBA is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, see <http://www.gnu.org/licenses/>.
20 # Process this file with autoconf to produce a configure script.
22 min_automake_version="1.14"
25 # To build a release you need to create a tag with the version number
26 # (git tag -s libksba-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],[libksba])
31 m4_define([mym4_major], [1])
32 m4_define([mym4_minor], [6])
33 m4_define([mym4_micro], [3])
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])
48 # LT Version numbers: Remember to change them just *before* a release.
49 # (Interfaces removed: CURRENT++, AGE=0, REVISION=0)
50 # (Interfaces added: CURRENT++, AGE++, REVISION=0)
51 # (No interfaces changed: REVISION++)
52 # Please remember to document interface changes in the NEWS file.
57 # If the API is changed in an incompatible way: increment the next counter.
58 KSBA_CONFIG_API_VERSION=1
61 NEED_GPG_ERROR_VERSION=1.8
64 AC_CONFIG_AUX_DIR([build-aux])
65 AC_CONFIG_SRCDIR([src/ksba.h.in])
66 AM_INIT_AUTOMAKE([serial-tests dist-bzip2 no-dist-gzip])
67 AC_CONFIG_HEADERS([config.h])
68 AC_CONFIG_MACRO_DIR([m4])
72 AC_USE_SYSTEM_EXTENSIONS
74 # Taken from mpfr-4.0.1, then modified for LDADD_FOR_TESTS_KLUDGE
75 dnl Under Linux, make sure that the old dtags are used if LD_LIBRARY_PATH
76 dnl is defined. The issue is that with the new dtags, LD_LIBRARY_PATH has
77 dnl the precedence over the run path, so that if a compatible MPFR library
78 dnl is installed in some directory from $LD_LIBRARY_PATH, then the tested
79 dnl MPFR library will be this library instead of the MPFR library from the
80 dnl build tree. Other OS with the same issue might be added later.
83 dnl https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=859732
84 dnl http://lists.gnu.org/archive/html/libtool/2017-05/msg00000.html
86 dnl We need to check whether --disable-new-dtags is supported as alternate
87 dnl linkers may be used (e.g., with tcc: CC=tcc LD=tcc).
91 if test -n "$LD_LIBRARY_PATH"; then
92 saved_LDFLAGS="$LDFLAGS"
93 LDADD_FOR_TESTS_KLUDGE="-Wl,--disable-new-dtags"
94 LDFLAGS="$LDFLAGS $LDADD_FOR_TESTS_KLUDGE"
95 AC_MSG_CHECKING(whether --disable-new-dtags is supported by the linker)
96 AC_LINK_IFELSE([AC_LANG_SOURCE([[
97 int main (void) { return 0; }
99 [AC_MSG_RESULT(yes (use it since LD_LIBRARY_PATH is set))],
101 LDADD_FOR_TESTS_KLUDGE=""
103 LDFLAGS="$saved_LDFLAGS"
107 AC_SUBST([LDADD_FOR_TESTS_KLUDGE])
110 LT_INIT([win32-dll disable-static])
111 LT_LANG([Windows Resource])
115 # We need to compile and run a program on the build machine.
118 AC_SUBST(LIBKSBA_LT_CURRENT)
119 AC_SUBST(LIBKSBA_LT_AGE)
120 AC_SUBST(LIBKSBA_LT_REVISION)
122 VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_major \
123 mym4_minor mym4_micro)
124 AC_SUBST(VERSION_NUMBER)
128 #ifndef _KSBA_CONFIG_H_INCLUDED
129 #define _KSBA_CONFIG_H_INCLUDED
131 /* Enable gpg-error's strerror macro for W32CE. */
132 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
137 #endif /*_KSBA_CONFIG_H_INCLUDED*/
142 # Checks for programs.
143 missing_dir=`cd $ac_aux_dir && pwd`
144 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
145 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
146 AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
147 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
148 AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
154 if test "x$ac_cv_prog_cc_c89" = "xno" ; then
155 AC_MSG_ERROR([[No C-89 compiler found]])
163 AX_PROG_BISON([have_bison=yes],[have_bison=no])
165 if test "$USE_MAINTAINER_MODE" = "yes"; then
166 AC_CHECK_PROGS(GCOV, [gcov], gcov)
167 # gcov coverage reporting
169 AC_SUBST(COVERAGE_CFLAGS)
170 AC_SUBST(COVERAGE_LDFLAGS)
172 AM_CONDITIONAL(HAVE_GCOV, false)
177 # We need to compile and run a program on the build machine.
178 # The AC_PROG_CC_FOR_BUILD macro in the AC archive is broken for
180 AC_MSG_CHECKING(for cc for build)
181 if test "$cross_compiling" = "yes"; then
182 CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
184 CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
186 AC_MSG_RESULT($CC_FOR_BUILD)
187 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
190 # This is handy for debugging so the compiler doesn't rearrange
191 # things and eliminate variables.
192 AC_ARG_ENABLE(optimization,
193 AS_HELP_STRING([--disable-optimization],
194 [disable compiler optimization]),
195 [if test $enableval = no ; then
196 CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
199 if test "$GCC" = yes; then
200 CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
202 if test "$USE_MAINTAINER_MODE" = "yes"; then
203 CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
205 # We use -W only if -Wno-missing-field-initializers is supported.
206 # -W is important because it detects errors like "if (foo);"
207 AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
208 _gcc_cflags_save=$CFLAGS
209 CFLAGS="-Wno-missing-field-initializers"
210 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
211 AC_MSG_RESULT($_gcc_wopt)
212 CFLAGS=$_gcc_cflags_save;
213 if test x"$_gcc_wopt" = xyes ; then
214 CFLAGS="$CFLAGS -W -Wno-sign-compare -Wno-missing-field-initializers"
217 AC_MSG_CHECKING([if gcc supports -Wdeclaration-after-statement])
218 _gcc_cflags_save=$CFLAGS
219 CFLAGS="-Wdeclaration-after-statement"
220 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
221 AC_MSG_RESULT($_gcc_wopt)
222 CFLAGS=$_gcc_cflags_save;
223 if test x"$_gcc_wopt" = xyes ; then
224 CFLAGS="$CFLAGS -Wdeclaration-after-statement"
228 AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
229 _gcc_cflags_save=$CFLAGS
230 CFLAGS="-Wpointer-arith"
231 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
232 AC_MSG_RESULT($_gcc_wopt)
233 CFLAGS=$_gcc_cflags_save;
234 if test x"$_gcc_wopt" = xyes ; then
235 CFLAGS="$CFLAGS -Wpointer-arith"
238 AC_MSG_CHECKING([if gcc supports -Wno-pointer-sign])
239 _gcc_cflags_save=$CFLAGS
240 CFLAGS="-Wno-pointer-sign"
241 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_psign=yes,_gcc_psign=no)
242 AC_MSG_RESULT($_gcc_psign)
243 CFLAGS=$_gcc_cflags_save;
244 if test x"$_gcc_psign" = xyes ; then
245 CFLAGS="$CFLAGS -Wno-pointer-sign"
250 # Setup some stuff depending on host.
256 have_w32ce_system=yes
262 AC_DEFINE(_DARWIN_C_SOURCE, 1,
263 Expose all libc features (__DARWIN_C_FULL).)
268 if test "$have_w32_system" = yes; then
269 AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
270 if test "$have_w32ce_system" = yes; then
271 AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
274 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
275 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
278 # For some systems we know that we have ld_version scripts.
279 # Use it then as default.
280 have_ld_version_script=no
283 have_ld_version_script=yes
286 have_ld_version_script=yes
289 AC_ARG_ENABLE([ld-version-script],
290 AS_HELP_STRING([--enable-ld-version-script],
291 [enable/disable use of linker version script.
292 (default is system dependent)]),
293 [have_ld_version_script=$enableval],
295 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
299 # Check for ELF visibility support.
301 AC_CACHE_CHECK(whether the visibility attribute is supported,
302 ksba_cv_visibility_attribute,
303 [ksba_cv_visibility_attribute=no
304 AC_LANG_CONFTEST([AC_LANG_SOURCE(
305 [[int foo __attribute__ ((visibility ("hidden"))) = 1;
306 int bar __attribute__ ((visibility ("protected"))) = 1;
309 if ${CC-cc} -Werror -S conftest.c -o conftest.s \
310 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
311 if grep '\.hidden.*foo' conftest.s >/dev/null 2>&1 ; then
312 if grep '\.protected.*bar' conftest.s >/dev/null 2>&1; then
313 ksba_cv_visibility_attribute=yes
318 if test "$ksba_cv_visibility_attribute" = "yes"; then
319 AC_CACHE_CHECK(for broken visibility attribute,
320 ksba_cv_broken_visibility_attribute,
321 [ksba_cv_broken_visibility_attribute=yes
322 AC_LANG_CONFTEST([AC_LANG_SOURCE(
324 int bar (int x) __asm__ ("foo")
325 __attribute__ ((visibility ("hidden")));
326 int bar (int x) { return x; }
329 if ${CC-cc} -Werror -S conftest.c -o conftest.s \
330 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
331 if grep '\.hidden@<:@ _@:>@foo' conftest.s >/dev/null 2>&1;
333 ksba_cv_broken_visibility_attribute=no
338 if test "$ksba_cv_visibility_attribute" = "yes"; then
339 AC_CACHE_CHECK(for broken alias attribute,
340 ksba_cv_broken_alias_attribute,
341 [ksba_cv_broken_alias_attribute=yes
342 AC_LANG_CONFTEST([AC_LANG_SOURCE(
343 [[extern int foo (int x) __asm ("xyzzy");
344 int bar (int x) { return x; }
345 extern __typeof (bar) foo __attribute ((weak, alias ("bar")));
347 extern __typeof (dfoo) dfoo __asm ("abccb");
351 if ${CC-cc} -Werror -S conftest.c -o conftest.s \
352 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
353 if grep 'xyzzy' conftest.s >/dev/null 2>&1 && \
354 grep 'abccb' conftest.s >/dev/null 2>&1; then
355 ksba_cv_broken_alias_attribute=no
360 if test "$ksba_cv_visibility_attribute" = "yes"; then
361 AC_CACHE_CHECK(if gcc supports -fvisibility=hidden,
362 ksba_cv_gcc_has_f_visibility,
363 [ksba_cv_gcc_has_f_visibility=no
364 _gcc_cflags_save=$CFLAGS
365 CFLAGS="-fvisibility=hidden"
366 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
367 ksba_cv_gcc_has_f_visibility=yes)
368 CFLAGS=$_gcc_cflags_save;
371 if test "$ksba_cv_visibility_attribute" = "yes" \
372 && test "$ksba_cv_broken_visibility_attribute" != "yes" \
373 && test "$ksba_cv_broken_alias_attribute" != "yes" \
374 && test "$ksba_cv_gcc_has_f_visibility" = "yes"
376 AC_DEFINE(KSBA_USE_VISIBILITY, 1,
377 [Define to use the GNU C visibility attribute.])
378 CFLAGS="$CFLAGS -fvisibility=hidden"
383 # Checks for libraries.
385 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION")
386 if test "x$GPG_ERROR_LIBS" = "x"; then
387 AC_MSG_ERROR([libgpg-error is needed.
388 See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .])
391 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_KSBA,
392 [The default error source for libksba.])
394 AM_CONDITIONAL(USE_GPGRT_CONFIG, [test -n "$GPGRT_CONFIG" \
395 -a "$ac_cv_path_GPG_ERROR_CONFIG" = no])
397 # Checks for header files.
399 # Checks for typedefs, structures, and compiler characteristics.
404 AC_CHECK_SIZEOF(unsigned int)
405 AC_CHECK_SIZEOF(unsigned long)
406 AC_CHECK_TYPES([u32])
409 # Checks for library functions.
410 AC_CHECK_FUNCS([stpcpy gmtime_r getenv])
416 gl_MODULES(alloca valgrind-tests)
419 # To be used in ksba-config
420 KSBA_CONFIG_LIBS="-lksba"
421 KSBA_CONFIG_CFLAGS=""
422 KSBA_CONFIG_HOST="$host"
423 AC_SUBST(KSBA_CONFIG_LIBS)
424 AC_SUBST(KSBA_CONFIG_CFLAGS)
425 AC_SUBST(KSBA_CONFIG_API_VERSION)
426 AC_SUBST(KSBA_CONFIG_HOST)
428 # The Makefiles need to know about cross compiling
429 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling != xno)
432 # Generate extended version information for W32.
433 if test "$have_w32_system" = yes; then
435 BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
437 BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec"
439 AC_SUBST(BUILD_REVISION)
440 AC_SUBST(BUILD_FILEVERSION)
441 BUILD_REVISION="mym4_revision"
442 AC_SUBST(BUILD_REVISION)
443 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
444 [GIT commit id revision used to build this package])
446 AC_ARG_ENABLE([build-timestamp],
447 AS_HELP_STRING([--enable-build-timestamp],
448 [set an explicit build timestamp for reproducibility.
449 (default is the current time in ISO-8601 format)]),
450 [if test "$enableval" = "yes"; then
451 BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
453 BUILD_TIMESTAMP="$enableval"
455 [BUILD_TIMESTAMP="<none>"])
456 AC_SUBST(BUILD_TIMESTAMP)
457 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
458 [The time this package was configured for a build])
461 AC_ARG_ENABLE([doc], AS_HELP_STRING([--disable-doc],
462 [do not build the documentation]),
463 build_doc=$enableval, build_doc=yes)
464 AM_CONDITIONAL([BUILD_DOC], [test "x$build_doc" != xno])
481 if test x"$have_bison" = xno; then
484 *** Note: The installed yacc version is not GNU Bison. You need
485 *** to install Bison if you want to change any grammar (.y) file.
490 Libksba v${VERSION} has been configured as follows:
492 Revision: mym4_revision (mym4_revision_dec)