151607fd505e9a221c26e19299d340707bc16364
[libksba.git] / configure.ac
1 # configure.ac - for libksba
2 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 g10 Code GmbH
3
4 # This file is part of KSBA
5
6 # KSBA is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10
11 # KSBA is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http://www.gnu.org/licenses/>.
18
19 # Process this file with autoconf to produce a configure script.
20 AC_PREREQ(2.61)
21 min_automake_version="1.10"
22
23
24 # Remember to change the version number immediately *after* a release.
25 # Set my_issvn to "yes" for non-released code.  Remember to run an
26 # "svn up" and "autogen.sh" right before creating a distribution.
27 m4_define([my_version], [1.0.8])
28 m4_define([my_issvn], [no])
29
30 m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \
31           | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)]))
32 AC_INIT([libksba],
33         [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])],
34         [gnupg-devel@gnupg.org])
35
36 # LT Version numbers: Remember to change them just *before* a release.
37 #   (Interfaces removed:    CURRENT++, AGE=0, REVISION=0)
38 #   (Interfaces added:      CURRENT++, AGE++, REVISION=0)
39 #   (No interfaces changed:                   REVISION++)
40 # Please remember to document interface changes in the NEWS file.
41 LIBKSBA_LT_CURRENT=17
42 LIBKSBA_LT_AGE=9
43 LIBKSBA_LT_REVISION=8
44 #-------------------
45 # If the API is changed in an incompatible way: increment the next counter.
46 KSBA_CONFIG_API_VERSION=1
47
48
49 NEED_GPG_ERROR_VERSION=1.8
50
51 BUILD_REVISION=svn_revision
52 PACKAGE=$PACKAGE_NAME
53 VERSION=$PACKAGE_VERSION
54
55 AC_CONFIG_SRCDIR([src/ksba.h])
56 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
57 AM_CONFIG_HEADER(config.h)
58 AC_CONFIG_MACRO_DIR([m4])
59 AC_CANONICAL_HOST
60 AB_INIT
61
62 AC_GNU_SOURCE
63
64 LT_PREREQ([2.2.6])
65 LT_INIT([win32-dll disable-static])
66 LT_LANG([Windows Resource])
67
68 AM_MAINTAINER_MODE
69
70
71 AC_SUBST(LIBKSBA_LT_CURRENT)
72 AC_SUBST(LIBKSBA_LT_AGE)
73 AC_SUBST(LIBKSBA_LT_REVISION)
74 AC_SUBST(PACKAGE)
75 AC_SUBST(VERSION)
76 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
77 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
78
79
80
81 # Checks for programs.
82 missing_dir=`cd $ac_aux_dir && pwd`
83 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
84 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
85 AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
86 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
87 AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
88 AC_PROG_AWK
89 AC_PROG_CC
90 AC_PROG_CPP
91 AM_PROG_CC_C_O
92 if test "x$ac_cv_prog_cc_c89" = "xno" ; then
93   AC_MSG_ERROR([[No C-89 compiler found]])
94 fi
95 AC_PROG_INSTALL
96 AC_PROG_LN_S
97 AC_PROG_MAKE_SET
98 gl_EARLY
99 #AC_ARG_PROGRAM
100 AC_PROG_YACC
101 AC_C_INLINE
102
103 # We need to compile and run a program on the build machine.
104 #   The AC_PROG_CC_FOR_BUILD macro in the AC archive is broken for
105 #   autoconf 2.57.
106 AC_MSG_CHECKING(for cc for build)
107 if test "$cross_compiling" = "yes"; then
108   CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
109 else
110   CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
111 fi
112 AC_MSG_RESULT($CC_FOR_BUILD)
113 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
114
115
116 # This is handy for debugging so the compiler doesn't rearrange
117 # things and eliminate variables.
118 AC_ARG_ENABLE(optimization,
119        AC_HELP_STRING([--disable-optimization],
120                       [disable compiler optimization]),
121                       [if test $enableval = no ; then
122                          CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
123                        fi])
124
125 if test "$GCC" = yes; then
126     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
127
128     if test "$USE_MAINTAINER_MODE" = "yes"; then
129         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
130
131         # We use -W only if -Wno-missing-field-initializers is supported.
132         # -W is important because it detects errors like "if (foo);"
133         AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
134         _gcc_cflags_save=$CFLAGS
135         CFLAGS="-Wno-missing-field-initializers"
136         AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_wopt=yes,_gcc_wopt=no)
137         AC_MSG_RESULT($_gcc_wopt)
138         CFLAGS=$_gcc_cflags_save;
139         if test x"$_gcc_wopt" = xyes ; then
140           CFLAGS="$CFLAGS -W -Wno-sign-compare -Wno-missing-field-initializers"
141         fi
142
143         AC_MSG_CHECKING([if gcc supports -Wdeclaration-after-statement])
144         _gcc_cflags_save=$CFLAGS
145         CFLAGS="-Wdeclaration-after-statement"
146         AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_wopt=yes,_gcc_wopt=no)
147         AC_MSG_RESULT($_gcc_wopt)
148         CFLAGS=$_gcc_cflags_save;
149         if test x"$_gcc_wopt" = xyes ; then
150           CFLAGS="$CFLAGS -Wdeclaration-after-statement"
151         fi
152     fi
153
154     AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
155     _gcc_cflags_save=$CFLAGS
156     CFLAGS="-Wpointer-arith"
157     AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_wopt=yes,_gcc_wopt=no)
158     AC_MSG_RESULT($_gcc_wopt)
159     CFLAGS=$_gcc_cflags_save;
160     if test x"$_gcc_wopt" = xyes ; then
161        CFLAGS="$CFLAGS -Wpointer-arith"
162     fi
163
164     AC_MSG_CHECKING([if gcc supports -Wno-pointer-sign])
165     _gcc_cflags_save=$CFLAGS
166     CFLAGS="-Wno-pointer-sign"
167     AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_psign=yes,_gcc_psign=no)
168     AC_MSG_RESULT($_gcc_psign)
169     CFLAGS=$_gcc_cflags_save;
170     if test x"$_gcc_psign" = xyes ; then
171        CFLAGS="$CFLAGS -Wno-pointer-sign"
172     fi
173
174 fi
175
176 # Setup some stuff depending on host.
177 have_w32_system=no
178 have_w32ce_system=no
179 case "${host}" in
180     *-*-mingw32ce*)
181       have_w32_system=yes
182       have_w32ce_system=yes
183       ;;
184     *-*-mingw32*)
185       have_w32_system=yes
186       ;;
187     *)
188       ;;
189 esac
190 if test "$have_w32_system" = yes; then
191    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
192    if test "$have_w32ce_system" = yes; then
193      AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
194    fi
195 fi
196 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
197 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
198
199
200 # For some systems we know that we have ld_version scripts.  
201 # Use it then as default.
202 have_ld_version_script=no
203 case "${host}" in
204     *-*-linux*)
205         have_ld_version_script=yes
206         ;;
207     *-*-gnu*)
208         have_ld_version_script=yes
209         ;;
210 esac
211 AC_ARG_ENABLE([ld-version-script],
212               AC_HELP_STRING([--enable-ld-version-script],
213                              [enable/disable use of linker version script.
214                               (default is system dependent)]),
215               [have_ld_version_script=$enableval],
216               [ : ] )
217 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
218
219
220 #            
221 # Check for ELF visibility support.
222 #
223 AC_CACHE_CHECK(whether the visibility attribute is supported,
224        ksba_cv_visibility_attribute,
225        [ksba_cv_visibility_attribute=no
226         AC_LANG_CONFTEST([AC_LANG_SOURCE(
227           [[int foo __attribute__ ((visibility ("hidden"))) = 1;
228             int bar __attribute__ ((visibility ("protected"))) = 1;
229           ]])])
230         
231         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
232                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
233             if grep '\.hidden.*foo' conftest.s >/dev/null 2>&1 ; then
234                 if grep '\.protected.*bar' conftest.s >/dev/null 2>&1; then
235                     ksba_cv_visibility_attribute=yes
236                 fi
237             fi  
238         fi  
239        ])
240 if test "$ksba_cv_visibility_attribute" = "yes"; then
241     AC_CACHE_CHECK(for broken visibility attribute,
242        ksba_cv_broken_visibility_attribute,
243        [ksba_cv_broken_visibility_attribute=yes
244         AC_LANG_CONFTEST([AC_LANG_SOURCE(
245           [[int foo (int x);
246             int bar (int x) __asm__ ("foo")
247                             __attribute__ ((visibility ("hidden")));
248             int bar (int x) { return x; }
249           ]])])
250                   
251         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
252                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
253            if grep '\.hidden@<:@        _@:>@foo' conftest.s >/dev/null 2>&1;
254             then
255                ksba_cv_broken_visibility_attribute=no
256            fi
257         fi
258        ])
259 fi
260 if test "$ksba_cv_visibility_attribute" = "yes"; then
261     AC_CACHE_CHECK(for broken alias attribute,
262        ksba_cv_broken_alias_attribute,
263        [ksba_cv_broken_alias_attribute=yes
264         AC_LANG_CONFTEST([AC_LANG_SOURCE(
265           [[extern int foo (int x) __asm ("xyzzy");
266             int bar (int x) { return x; }
267             extern __typeof (bar) foo __attribute ((weak, alias ("bar")));
268             extern int dfoo;
269             extern __typeof (dfoo) dfoo __asm ("abccb");
270             int dfoo = 1;
271           ]])])
272
273         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
274                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
275            if grep 'xyzzy' conftest.s >/dev/null 2>&1 && \
276               grep 'abccb' conftest.s >/dev/null 2>&1; then
277               ksba_cv_broken_alias_attribute=no
278            fi
279         fi
280         ])
281 fi
282 if test "$ksba_cv_visibility_attribute" = "yes"; then
283     AC_CACHE_CHECK(if gcc supports -fvisibility=hidden,
284        ksba_cv_gcc_has_f_visibility,
285        [ksba_cv_gcc_has_f_visibility=no
286         _gcc_cflags_save=$CFLAGS
287         CFLAGS="-fvisibility=hidden"
288         AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),
289                           ksba_cv_gcc_has_f_visibility=yes)
290         CFLAGS=$_gcc_cflags_save;
291        ])
292 fi
293 if test "$ksba_cv_visibility_attribute" = "yes" \
294    && test "$ksba_cv_broken_visibility_attribute" != "yes" \
295    && test "$ksba_cv_broken_alias_attribute" != "yes" \
296    && test "$ksba_cv_gcc_has_f_visibility" = "yes"  
297  then
298    AC_DEFINE(KSBA_USE_VISIBILITY, 1,
299                [Define to use the GNU C visibility attribute.])
300    CFLAGS="$CFLAGS -fvisibility=hidden"
301 fi
302
303
304 #
305 # Checks for libraries.
306 #
307 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION")
308 if test "x$GPG_ERROR_LIBS" = "x"; then
309   AC_MSG_ERROR([libgpg-error is needed.
310                 See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .])
311 fi
312
313 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_KSBA,
314           [The default error source for libksba.])
315
316
317 # Checks for header files.
318 AC_HEADER_STDC
319 AC_CHECK_HEADERS([string.h])
320
321 # Checks for typedefs, structures, and compiler characteristics.
322 AC_C_CONST
323
324 AC_C_BIGENDIAN
325
326 AC_CHECK_SIZEOF(unsigned int)
327 AC_CHECK_SIZEOF(unsigned long)
328 GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF)
329
330
331 # Checks for library functions.
332 AC_CHECK_FUNCS([memmove strchr strtol strtoul stpcpy gmtime_r getenv])
333
334
335 # GNUlib checks
336 gl_SOURCE_BASE(gl)
337 gl_M4_BASE(gl/m4)
338 gl_MODULES(alloca)
339 gl_INIT
340
341 # To be used in ksba-config
342 KSBA_CONFIG_LIBS="-lksba"
343 KSBA_CONFIG_CFLAGS=""
344 AC_SUBST(KSBA_CONFIG_LIBS)
345 AC_SUBST(KSBA_CONFIG_CFLAGS)
346 AC_SUBST(KSBA_CONFIG_API_VERSION)
347
348 # The Makefiles need to know about cross compiling
349 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling != xno)
350
351
352 # Generate extended version information for W32.
353 if test "$have_w32_system" = yes; then
354    BUILD_TIMESTAMP=`date --iso-8601=minutes`
355    changequote(,)dnl 
356    BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
357    changequote([,])dnl
358    BUILD_FILEVERSION="${BUILD_FILEVERSION}${BUILD_REVISION}"
359 fi
360 AC_SUBST(BUILD_REVISION)
361 AC_SUBST(BUILD_TIMESTAMP)
362 AC_SUBST(BUILD_FILEVERSION)
363 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION", 
364                    [Subversion revision used to build this package])
365
366
367 AC_CONFIG_FILES([
368 Makefile
369 m4/Makefile
370 gl/Makefile
371 src/Makefile
372 src/ksba-config
373 src/versioninfo.rc
374 tests/Makefile
375 doc/Makefile
376 ])
377 AC_OUTPUT
378
379
380 echo "
381         Libksba v${VERSION} has been configured as follows:
382         
383         Platform:  $host
384
385 "