ef627c09eb90609007199ff7f21c53c2217dafbe
[platform/upstream/libksba.git] / configure.ac
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
4 #
5 # This file is part of KSBA
6 #
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.
11 #
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.
16 #
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/>.
19
20 # Process this file with autoconf to produce a configure script.
21 AC_PREREQ([2.69])
22 min_automake_version="1.14"
23
24
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], [2])
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 #   (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.
53 LIBKSBA_LT_CURRENT=22
54 LIBKSBA_LT_AGE=14
55 LIBKSBA_LT_REVISION=2
56 #-------------------
57 # If the API is changed in an incompatible way: increment the next counter.
58 KSBA_CONFIG_API_VERSION=1
59
60
61 NEED_GPG_ERROR_VERSION=1.8
62
63
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])
69 AC_CANONICAL_HOST
70 AB_INIT
71
72 AC_USE_SYSTEM_EXTENSIONS
73
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.
81 dnl
82 dnl References:
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
85 dnl
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).
88 dnl
89 case $host in
90   *-*-linux*)
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; }
98       ]])],
99       [AC_MSG_RESULT(yes (use it since LD_LIBRARY_PATH is set))],
100       [AC_MSG_RESULT(no)
101        LDADD_FOR_TESTS_KLUDGE=""
102       ])
103       LDFLAGS="$saved_LDFLAGS"
104     fi
105     ;;
106 esac
107 AC_SUBST([LDADD_FOR_TESTS_KLUDGE])
108
109 LT_PREREQ([2.2.6])
110 LT_INIT([win32-dll disable-static])
111 LT_LANG([Windows Resource])
112
113 AM_MAINTAINER_MODE
114
115 # We need to compile and run a program on the build machine.
116 AX_CC_FOR_BUILD
117
118 AC_SUBST(LIBKSBA_LT_CURRENT)
119 AC_SUBST(LIBKSBA_LT_AGE)
120 AC_SUBST(LIBKSBA_LT_REVISION)
121
122 VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_major \
123                           mym4_minor mym4_micro)
124 AC_SUBST(VERSION_NUMBER)
125
126
127 AH_TOP([
128 #ifndef _KSBA_CONFIG_H_INCLUDED
129 #define _KSBA_CONFIG_H_INCLUDED
130
131 /* Enable gpg-error's strerror macro for W32CE.  */
132 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
133 ])
134
135 AH_BOTTOM([
136
137 #endif /*_KSBA_CONFIG_H_INCLUDED*/
138 ])
139
140
141
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)
149 AM_SILENT_RULES
150 AC_PROG_AWK
151 AC_PROG_CC
152 AC_PROG_CPP
153 AM_PROG_CC_C_O
154 if test "x$ac_cv_prog_cc_c89" = "xno" ; then
155   AC_MSG_ERROR([[No C-89 compiler found]])
156 fi
157 AC_PROG_INSTALL
158 AC_PROG_LN_S
159 AC_PROG_MAKE_SET
160 gl_EARLY
161 #AC_ARG_PROGRAM
162 AC_PROG_YACC
163 AX_PROG_BISON([have_bison=yes],[have_bison=no])
164
165 if test "$USE_MAINTAINER_MODE" = "yes"; then
166         AC_CHECK_PROGS(GCOV, [gcov], gcov)
167         # gcov coverage reporting
168         AC_TDD_GCOV
169         AC_SUBST(COVERAGE_CFLAGS)
170         AC_SUBST(COVERAGE_LDFLAGS)
171 else
172         AM_CONDITIONAL(HAVE_GCOV, false)
173 fi
174
175 AC_C_INLINE
176
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
179 #   autoconf 2.57.
180 AC_MSG_CHECKING(for cc for build)
181 if test "$cross_compiling" = "yes"; then
182   CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
183 else
184   CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
185 fi
186 AC_MSG_RESULT($CC_FOR_BUILD)
187 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
188
189
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]]//'`
197                        fi])
198
199 if test "$GCC" = yes; then
200     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
201
202     if test "$USE_MAINTAINER_MODE" = "yes"; then
203         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
204
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"
215         fi
216
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"
225         fi
226     fi
227
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"
236     fi
237
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"
246     fi
247
248 fi
249
250 # Setup some stuff depending on host.
251 have_w32_system=no
252 have_w32ce_system=no
253 case "${host}" in
254     *-*-mingw32ce*)
255       have_w32_system=yes
256       have_w32ce_system=yes
257       ;;
258     *-*-mingw32*)
259       have_w32_system=yes
260       ;;
261      *-apple-darwin*)
262       AC_DEFINE(_DARWIN_C_SOURCE, 1,
263                 Expose all libc features (__DARWIN_C_FULL).)
264       ;;
265     *)
266       ;;
267 esac
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])
272    fi
273 fi
274 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
275 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
276
277
278 # For some systems we know that we have ld_version scripts.
279 # Use it then as default.
280 have_ld_version_script=no
281 case "${host}" in
282     *-*-linux*)
283         have_ld_version_script=yes
284         ;;
285     *-*-gnu*)
286         have_ld_version_script=yes
287         ;;
288 esac
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],
294               [ : ] )
295 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
296
297
298 #
299 # Check for ELF visibility support.
300 #
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;
307           ]])])
308
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
314                 fi
315             fi
316         fi
317        ])
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(
323           [[int foo (int x);
324             int bar (int x) __asm__ ("foo")
325                             __attribute__ ((visibility ("hidden")));
326             int bar (int x) { return x; }
327           ]])])
328
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;
332             then
333                ksba_cv_broken_visibility_attribute=no
334            fi
335         fi
336        ])
337 fi
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")));
346             extern int dfoo;
347             extern __typeof (dfoo) dfoo __asm ("abccb");
348             int dfoo = 1;
349           ]])])
350
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
356            fi
357         fi
358         ])
359 fi
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;
369        ])
370 fi
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"
375  then
376    AC_DEFINE(KSBA_USE_VISIBILITY, 1,
377                [Define to use the GNU C visibility attribute.])
378    CFLAGS="$CFLAGS -fvisibility=hidden"
379 fi
380
381
382 #
383 # Checks for libraries.
384 #
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/ .])
389 fi
390
391 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_KSBA,
392           [The default error source for libksba.])
393
394 AM_CONDITIONAL(USE_GPGRT_CONFIG, [test -n "$GPGRT_CONFIG" \
395                                   -a "$ac_cv_path_GPG_ERROR_CONFIG" = no])
396
397 # Checks for header files.
398
399 # Checks for typedefs, structures, and compiler characteristics.
400 AC_C_CONST
401
402 AC_C_BIGENDIAN
403
404 AC_CHECK_SIZEOF(unsigned int)
405 AC_CHECK_SIZEOF(unsigned long)
406 AC_CHECK_TYPES([u32])
407
408
409 # Checks for library functions.
410 AC_CHECK_FUNCS([stpcpy gmtime_r getenv])
411
412
413 # GNUlib checks
414 gl_SOURCE_BASE(gl)
415 gl_M4_BASE(gl/m4)
416 gl_MODULES(alloca valgrind-tests)
417 gl_INIT
418
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)
427
428 # The Makefiles need to know about cross compiling
429 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling != xno)
430
431
432 # Generate extended version information for W32.
433 if test "$have_w32_system" = yes; then
434    changequote(,)dnl
435    BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
436    changequote([,])dnl
437    BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec"
438 fi
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])
445
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`
452       else
453         BUILD_TIMESTAMP="$enableval"
454       fi],
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])
459
460 build_doc=yes
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])
465
466
467 AC_CONFIG_FILES([
468 Makefile
469 m4/Makefile
470 gl/Makefile
471 src/Makefile
472 src/ksba.h
473 src/ksba-config
474 src/ksba.pc
475 src/versioninfo.rc
476 tests/Makefile
477 doc/Makefile
478 ])
479 AC_OUTPUT
480
481 if test x"$have_bison" = xno; then
482     AC_MSG_NOTICE([[
483 ***
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.
486 ***]])
487 fi
488
489 echo "
490         Libksba v${VERSION} has been configured as follows:
491
492         Revision:  mym4_revision  (mym4_revision_dec)
493         Platform:  $host
494
495 "