Imported Upstream version 1.3.4
[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  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.61)
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], [3])
33 m4_define([mym4_micro], [4])
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], [http://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=19
54 LIBKSBA_LT_AGE=11
55 LIBKSBA_LT_REVISION=5
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 PACKAGE=$PACKAGE_NAME
65 VERSION=$PACKAGE_VERSION
66
67 AC_CONFIG_AUX_DIR([build-aux])
68 AC_CONFIG_SRCDIR([src/ksba.h])
69 AM_INIT_AUTOMAKE([serial-tests dist-bzip2 no-dist-gzip])
70 AM_CONFIG_HEADER(config.h)
71 AC_CONFIG_MACRO_DIR([m4])
72 AC_CANONICAL_HOST
73 AB_INIT
74
75 AC_GNU_SOURCE
76
77 LT_PREREQ([2.2.6])
78 LT_INIT([win32-dll disable-static])
79 LT_LANG([Windows Resource])
80
81 AM_MAINTAINER_MODE
82
83
84 AC_SUBST(LIBKSBA_LT_CURRENT)
85 AC_SUBST(LIBKSBA_LT_AGE)
86 AC_SUBST(LIBKSBA_LT_REVISION)
87 AC_SUBST(PACKAGE)
88 AC_SUBST(VERSION)
89 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
90 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
91
92 AH_TOP([
93 #ifndef _KSBA_CONFIG_H_INCLUDED
94 #define _KSBA_CONFIG_H_INCLUDED
95
96 /* Enable gpg-error's strerror macro for W32CE.  */
97 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
98 ])
99
100 AH_BOTTOM([
101
102 #endif /*_KSBA_CONFIG_H_INCLUDED*/
103 ])
104
105
106
107 # Checks for programs.
108 missing_dir=`cd $ac_aux_dir && pwd`
109 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
110 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
111 AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
112 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
113 AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
114 AM_SILENT_RULES
115 AC_PROG_AWK
116 AC_PROG_CC
117 AC_PROG_CPP
118 AM_PROG_CC_C_O
119 if test "x$ac_cv_prog_cc_c89" = "xno" ; then
120   AC_MSG_ERROR([[No C-89 compiler found]])
121 fi
122 AC_PROG_INSTALL
123 AC_PROG_LN_S
124 AC_PROG_MAKE_SET
125 gl_EARLY
126 #AC_ARG_PROGRAM
127 AC_PROG_YACC
128 AC_C_INLINE
129
130 # We need to compile and run a program on the build machine.
131 #   The AC_PROG_CC_FOR_BUILD macro in the AC archive is broken for
132 #   autoconf 2.57.
133 AC_MSG_CHECKING(for cc for build)
134 if test "$cross_compiling" = "yes"; then
135   CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
136 else
137   CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
138 fi
139 AC_MSG_RESULT($CC_FOR_BUILD)
140 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
141
142
143 # This is handy for debugging so the compiler doesn't rearrange
144 # things and eliminate variables.
145 AC_ARG_ENABLE(optimization,
146        AC_HELP_STRING([--disable-optimization],
147                       [disable compiler optimization]),
148                       [if test $enableval = no ; then
149                          CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
150                        fi])
151
152 if test "$GCC" = yes; then
153     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
154
155     if test "$USE_MAINTAINER_MODE" = "yes"; then
156         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
157
158         # We use -W only if -Wno-missing-field-initializers is supported.
159         # -W is important because it detects errors like "if (foo);"
160         AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
161         _gcc_cflags_save=$CFLAGS
162         CFLAGS="-Wno-missing-field-initializers"
163         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
164         AC_MSG_RESULT($_gcc_wopt)
165         CFLAGS=$_gcc_cflags_save;
166         if test x"$_gcc_wopt" = xyes ; then
167           CFLAGS="$CFLAGS -W -Wno-sign-compare -Wno-missing-field-initializers"
168         fi
169
170         AC_MSG_CHECKING([if gcc supports -Wdeclaration-after-statement])
171         _gcc_cflags_save=$CFLAGS
172         CFLAGS="-Wdeclaration-after-statement"
173         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
174         AC_MSG_RESULT($_gcc_wopt)
175         CFLAGS=$_gcc_cflags_save;
176         if test x"$_gcc_wopt" = xyes ; then
177           CFLAGS="$CFLAGS -Wdeclaration-after-statement"
178         fi
179     fi
180
181     AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
182     _gcc_cflags_save=$CFLAGS
183     CFLAGS="-Wpointer-arith"
184     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
185     AC_MSG_RESULT($_gcc_wopt)
186     CFLAGS=$_gcc_cflags_save;
187     if test x"$_gcc_wopt" = xyes ; then
188        CFLAGS="$CFLAGS -Wpointer-arith"
189     fi
190
191     AC_MSG_CHECKING([if gcc supports -Wno-pointer-sign])
192     _gcc_cflags_save=$CFLAGS
193     CFLAGS="-Wno-pointer-sign"
194     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_psign=yes,_gcc_psign=no)
195     AC_MSG_RESULT($_gcc_psign)
196     CFLAGS=$_gcc_cflags_save;
197     if test x"$_gcc_psign" = xyes ; then
198        CFLAGS="$CFLAGS -Wno-pointer-sign"
199     fi
200
201 fi
202
203 # Setup some stuff depending on host.
204 have_w32_system=no
205 have_w32ce_system=no
206 case "${host}" in
207     *-*-mingw32ce*)
208       have_w32_system=yes
209       have_w32ce_system=yes
210       ;;
211     *-*-mingw32*)
212       have_w32_system=yes
213       ;;
214     *)
215       ;;
216 esac
217 if test "$have_w32_system" = yes; then
218    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
219    if test "$have_w32ce_system" = yes; then
220      AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
221    fi
222 fi
223 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
224 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
225
226
227 # For some systems we know that we have ld_version scripts.
228 # Use it then as default.
229 have_ld_version_script=no
230 case "${host}" in
231     *-*-linux*)
232         have_ld_version_script=yes
233         ;;
234     *-*-gnu*)
235         have_ld_version_script=yes
236         ;;
237 esac
238 AC_ARG_ENABLE([ld-version-script],
239               AC_HELP_STRING([--enable-ld-version-script],
240                              [enable/disable use of linker version script.
241                               (default is system dependent)]),
242               [have_ld_version_script=$enableval],
243               [ : ] )
244 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
245
246
247 #
248 # Check for ELF visibility support.
249 #
250 AC_CACHE_CHECK(whether the visibility attribute is supported,
251        ksba_cv_visibility_attribute,
252        [ksba_cv_visibility_attribute=no
253         AC_LANG_CONFTEST([AC_LANG_SOURCE(
254           [[int foo __attribute__ ((visibility ("hidden"))) = 1;
255             int bar __attribute__ ((visibility ("protected"))) = 1;
256           ]])])
257
258         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
259                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
260             if grep '\.hidden.*foo' conftest.s >/dev/null 2>&1 ; then
261                 if grep '\.protected.*bar' conftest.s >/dev/null 2>&1; then
262                     ksba_cv_visibility_attribute=yes
263                 fi
264             fi
265         fi
266        ])
267 if test "$ksba_cv_visibility_attribute" = "yes"; then
268     AC_CACHE_CHECK(for broken visibility attribute,
269        ksba_cv_broken_visibility_attribute,
270        [ksba_cv_broken_visibility_attribute=yes
271         AC_LANG_CONFTEST([AC_LANG_SOURCE(
272           [[int foo (int x);
273             int bar (int x) __asm__ ("foo")
274                             __attribute__ ((visibility ("hidden")));
275             int bar (int x) { return x; }
276           ]])])
277
278         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
279                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
280            if grep '\.hidden@<:@        _@:>@foo' conftest.s >/dev/null 2>&1;
281             then
282                ksba_cv_broken_visibility_attribute=no
283            fi
284         fi
285        ])
286 fi
287 if test "$ksba_cv_visibility_attribute" = "yes"; then
288     AC_CACHE_CHECK(for broken alias attribute,
289        ksba_cv_broken_alias_attribute,
290        [ksba_cv_broken_alias_attribute=yes
291         AC_LANG_CONFTEST([AC_LANG_SOURCE(
292           [[extern int foo (int x) __asm ("xyzzy");
293             int bar (int x) { return x; }
294             extern __typeof (bar) foo __attribute ((weak, alias ("bar")));
295             extern int dfoo;
296             extern __typeof (dfoo) dfoo __asm ("abccb");
297             int dfoo = 1;
298           ]])])
299
300         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
301                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
302            if grep 'xyzzy' conftest.s >/dev/null 2>&1 && \
303               grep 'abccb' conftest.s >/dev/null 2>&1; then
304               ksba_cv_broken_alias_attribute=no
305            fi
306         fi
307         ])
308 fi
309 if test "$ksba_cv_visibility_attribute" = "yes"; then
310     AC_CACHE_CHECK(if gcc supports -fvisibility=hidden,
311        ksba_cv_gcc_has_f_visibility,
312        [ksba_cv_gcc_has_f_visibility=no
313         _gcc_cflags_save=$CFLAGS
314         CFLAGS="-fvisibility=hidden"
315         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
316                           ksba_cv_gcc_has_f_visibility=yes)
317         CFLAGS=$_gcc_cflags_save;
318        ])
319 fi
320 if test "$ksba_cv_visibility_attribute" = "yes" \
321    && test "$ksba_cv_broken_visibility_attribute" != "yes" \
322    && test "$ksba_cv_broken_alias_attribute" != "yes" \
323    && test "$ksba_cv_gcc_has_f_visibility" = "yes"
324  then
325    AC_DEFINE(KSBA_USE_VISIBILITY, 1,
326                [Define to use the GNU C visibility attribute.])
327    CFLAGS="$CFLAGS -fvisibility=hidden"
328 fi
329
330
331 #
332 # Checks for libraries.
333 #
334 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION")
335 if test "x$GPG_ERROR_LIBS" = "x"; then
336   AC_MSG_ERROR([libgpg-error is needed.
337                 See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .])
338 fi
339
340 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_KSBA,
341           [The default error source for libksba.])
342
343
344 # Checks for header files.
345 AC_HEADER_STDC
346 AC_CHECK_HEADERS([string.h])
347
348 # Checks for typedefs, structures, and compiler characteristics.
349 AC_C_CONST
350
351 AC_C_BIGENDIAN
352
353 AC_CHECK_SIZEOF(unsigned int)
354 AC_CHECK_SIZEOF(unsigned long)
355 GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF)
356
357
358 # Checks for library functions.
359 AC_CHECK_FUNCS([memmove strchr strtol strtoul stpcpy gmtime_r getenv])
360
361
362 # GNUlib checks
363 gl_SOURCE_BASE(gl)
364 gl_M4_BASE(gl/m4)
365 gl_MODULES(alloca valgrind-tests)
366 gl_INIT
367
368 # To be used in ksba-config
369 KSBA_CONFIG_LIBS="-lksba"
370 KSBA_CONFIG_CFLAGS=""
371 KSBA_CONFIG_HOST="$host"
372 AC_SUBST(KSBA_CONFIG_LIBS)
373 AC_SUBST(KSBA_CONFIG_CFLAGS)
374 AC_SUBST(KSBA_CONFIG_API_VERSION)
375 AC_SUBST(KSBA_CONFIG_HOST)
376
377 # The Makefiles need to know about cross compiling
378 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling != xno)
379
380
381 # Generate extended version information for W32.
382 if test "$have_w32_system" = yes; then
383    changequote(,)dnl
384    BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
385    changequote([,])dnl
386    BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec"
387 fi
388 AC_SUBST(BUILD_REVISION)
389 AC_SUBST(BUILD_FILEVERSION)
390 BUILD_REVISION="mym4_revision"
391 AC_SUBST(BUILD_REVISION)
392 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
393                    [GIT commit id revision used to build this package])
394
395 AC_ARG_ENABLE([build-timestamp],
396   AC_HELP_STRING([--enable-build-timestamp],
397                  [set an explicit build timestamp for reproducibility.
398                   (default is the current time in ISO-8601 format)]),
399      [if test "$enableval" = "yes"; then
400         BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
401       else
402         BUILD_TIMESTAMP="$enableval"
403       fi],
404      [BUILD_TIMESTAMP="<none>"])
405 AC_SUBST(BUILD_TIMESTAMP)
406 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
407                    [The time this package was configured for a build])
408
409
410 AC_CONFIG_FILES([
411 Makefile
412 m4/Makefile
413 gl/Makefile
414 src/Makefile
415 src/ksba-config
416 src/versioninfo.rc
417 tests/Makefile
418 doc/Makefile
419 ])
420 AC_OUTPUT
421
422
423 echo "
424         Libksba v${VERSION} has been configured as follows:
425
426         Revision:  mym4_revision  (mym4_revision_dec)
427         Platform:  $host
428
429 "