Fix issue: Engine_pkcs11 reports all object ID:s as zero
[keystone-linux/engine-pkcs11.git] / configure.ac
2 AC_PREREQ(2.60)
4 define([PACKAGE_VERSION_MAJOR], [0])
5 define([PACKAGE_VERSION_MINOR], [1])
6 define([PACKAGE_VERSION_FIX], [9])
7 define([PACKAGE_SUFFIX], [-svn-r129])
9 AC_INIT([engine_pkcs11],[PACKAGE_VERSION_MAJOR.PACKAGE_VERSION_MINOR.PACKAGE_VERSION_FIX[]PACKAGE_SUFFIX])
10 AC_CONFIG_AUX_DIR([.])
11 AM_CONFIG_HEADER([config.h])
12 AC_CONFIG_MACRO_DIR([m4])
13 AM_INIT_AUTOMAKE([${PACKAGE_NAME}], [${PACKAGE_VERSION}])
15 ENGINE_PKCS11_VERSION_MAJOR="PACKAGE_VERSION_MAJOR"
16 ENGINE_PKCS11_VERSION_MINOR="PACKAGE_VERSION_MINOR"
17 ENGINE_PKCS11_VERSION_FIX="PACKAGE_VERSION_FIX"
19 AC_CONFIG_SRCDIR([src/engine_pkcs11.c])
21 AC_CANONICAL_HOST
22 AC_PROG_CC
23 PKG_PROG_PKG_CONFIG
24 AC_C_BIGENDIAN
25 AM_PROG_CC_C_O
27 AC_MSG_CHECKING([svn checkout])
28 if test -e "${srcdir}/packaged"; then
29         svn_checkout="no"
30 else
31         svn_checkout="yes"
32 fi
33 AC_MSG_RESULT([${svn_checkout}])
35 AC_ARG_WITH(
36         [cygwin-native],
37         [AS_HELP_STRING([--with-cygwin-native],[compile native win32])],
38         ,
39         [with_cygwin_native="no"]
40 )
42 dnl Check for some target-specific stuff
43 test -z "${WIN32}" && WIN32="no"
44 test -z "${CYGWIN}" && CYGWIN="no"
45 case "${host}" in
46         *-mingw*|*-winnt*)
47                 WIN32="yes"
48                 CPPFLAGS="${CPPFLAGS} -DWIN32_LEAN_AND_MEAN"
49                 WIN_LIBPREFIX="lib"
50         ;;
51         *-cygwin*)
52                 AC_MSG_CHECKING([cygwin mode to use])
53                 CYGWIN="yes"
54                 if test "${with_cygwin_native}" = "yes"; then
55                         AC_MSG_RESULT([Using native win32])
56                         CPPFLAGS="${CPPFLAGS} -DWIN32_LEAN_AND_MEAN"
57                         CFLAGS="${CFLAGS} -mno-cygwin"
58                         WIN32="yes"
59                 else
60                         AC_MSG_RESULT([Using cygwin])
61                         CPPFLAGS="${CPPFLAGS} -DCRYPTOKI_FORCE_WIN32"
62                         WIN_LIBPREFIX="cyg"
63                         AC_DEFINE([USE_CYGWIN], [1], [Define if you are on Cygwin])
64                 fi
65         ;;
66 esac
68 AC_ARG_ENABLE(
69         [strict],
70         [AS_HELP_STRING([--enable-strict],[enable strict compile mode @<:@disabled@:>@])],
71         ,
72         [enable_strict="no"]
73 )
75 AC_ARG_ENABLE(
76         [pedantic],
77         [AS_HELP_STRING([--enable-pedantic],[enable pedantic compile mode @<:@disabled@:>@])],
78         ,
79         [enable_pedantic="no"]
80 )
82 AC_ARG_ENABLE(
83         [doc],
84         [AS_HELP_STRING([--enable-doc],[enable installation of documents @<:@disabled@:>@])],
85         ,
86         [enable_doc="no"]
87 )
89 AC_ARG_WITH(
90         [enginesdir],
91         [AS_HELP_STRING([--with-enginesdir],[OpenSSL engines directory @<:@LIBDIR/engines@:>@])],
92         [enginesdir="${withval}"],
93         [enginesdir="\$(libdir)/engines"]
94 )
96 dnl Checks for programs.
97 AC_PROG_CPP
98 AC_PROG_INSTALL
99 AC_PROG_LN_S
100 AC_PROG_MKDIR_P
101 AC_PROG_SED
102 AC_PROG_MAKE_SET
104 dnl Add libtool support.
105 ifdef(
106         [LT_INIT],
107         [
108                 LT_INIT([win32-dll])
109                 LT_LANG([Windows Resource])
110         ],
111         [
112                 AC_LIBTOOL_WIN32_DLL
113                 AC_LIBTOOL_RC
114                 AC_PROG_LIBTOOL
115         ]
118 dnl Checks for header files.
119 AC_HEADER_STDC
120 AC_HEADER_SYS_WAIT
121 AC_CHECK_HEADERS([ \
122         errno.h fcntl.h malloc.h stdlib.h inttypes.h \
123         string.h strings.h sys/time.h unistd.h \
124         locale.h getopt.h dlfcn.h utmp.h \
125 ])
127 PKG_CHECK_MODULES([LIBP11], [libp11 >= 0.2.5],, [AC_MSG_ERROR([libp11 >= 0.2.5 is required])])
129 dnl These required for svn checkout
130 AC_ARG_VAR([XSLTPROC], [xsltproc utility])
131 AC_ARG_VAR([SVN], [subversion utility])
132 AC_ARG_VAR([WGET], [wget utility])
133 AC_ARG_VAR([WGET_OPTS], [wget options])
134 AC_ARG_VAR([TR], [tr utility])
135 AC_CHECK_PROGS([XSLTPROC],[xsltproc])
136 AC_CHECK_PROGS([SVN],[svn])
137 AC_CHECK_PROGS([WGET],[wget])
138 AC_CHECK_PROGS([TR],[tr])
139 test -z "${WGET_OPTS}" && WGET_OPTS="-nv"
141 dnl svn checkout dependencies
142 if test "${svn_checkout}" = "yes"; then
143         AC_MSG_CHECKING([XSLTPROC requirement])
144         if test -n "${XSLTPROC}"; then
145                 AC_MSG_RESULT([ok])
146         else
147                 if test "${enable_doc}" = "yes"; then
148                         AC_MSG_ERROR([Missing XSLTPROC svn build with doc])
149                 else
150                         AC_MSG_WARN(["make dist" will not work])
151                 fi
152         fi
154         AC_MSG_CHECKING([svn doc build dependencies])
155         if test -n "${SVN}" -a -n "${TR}" -a -n "${WGET}"; then
156                 AC_MSG_RESULT([ok])
157         else
158                 if test "${enable_doc}" = "yes"; then
159                         AC_MSG_ERROR([Missing SVN, TR or WGET for svn doc build])
160                 else
161                         AC_MSG_WARN(["make dist" will not work])
162                 fi
163         fi
164 fi
166 PKG_CHECK_MODULES(
167         [OPENSSL],
168         [libcrypto >= 0.9.7],
169         ,
170         [PKG_CHECK_MODULES(
171                 [OPENSSL],
172                 [openssl >= 0.9.7],
173                 ,
174                 [AC_CHECK_LIB(
175                         [crypto],
176                         [RSA_version],
177                         [OPENSSL_LIBS="-lcrypto"],
178                         [AC_MSG_ERROR([Cannot find OpenSSL])]
179                 )]
180         )]
183 # ok, now we might (or not) have ssl and an engine.
184 # still room for "improvements", i.e. hacks to work
185 # with old engines.
187 AC_MSG_CHECKING([for openssl version])
188 saved_CPPFLAGS="${CPPFLAGS}"
189 CPPFLAGS="${CPPFLAGS} ${OPENSSL_CFLAGS}"
190 AC_EGREP_CPP(
191         [new],
192         [
193 #include <openssl/opensslv.h>
194 #if OPENSSL_VERSION_NUMBER >= 0x0090704fL
195 new
196 #else
197 old
198 #endif
199         ],
200         [
201                 AC_MSG_RESULT([good, 0.9.7d or later])
202                 old_openssl="no"
203         ],
204         [
205                 AC_MSG_RESULT([not so good, 0.9.7d or later would be better])
206                 old_openssl="yes"
207         ]
209 CPPFLAGS="${saved_CPPFLAGS}"
211 if test "x$old_openssl" = "xyes"; then
212         # openssl found, but version less than 0.9.7d
213         # linking libcrypto.a statically possible?
215         saved_CFLAGS="${CFLAGS}"
216         saved_LIBS="${LIBS}"
217         CFLAGS="${CFLAGS} ${OPENSSL_CFLAGS}"
218         if echo "${OPENSSL_LIBS}" | grep -- "-L" > /dev/null; then
219                 OPENSSL_DIR="$(echo "${OPENSSL_LIBS}" | ${SED} 's/.*-L\([^ ]*\).*/\1/')"
220         else
221                 OPENSSL_DIR="${usrlibdir}"
222         fi
223         LIBS="${LIBS} ${OPENSSL_DIR}/libcrypto.a"
224         AC_CHECK_LIB(
225                 [dl],
226                 [dlopen]
227         )
228         AC_MSG_CHECKING([should link static openssl])
229         AC_LINK_IFELSE(
230                 [AC_LANG_PROGRAM([[
231 #include <string.h>
232 #include <openssl/opensslv.h>
233 #include <openssl/engine.h>
234 #include <openssl/rand.h>
235 int test(void)
237         char a[2048];
238         ENGINE *e;
240         e = ENGINE_new();
241         ENGINE_load_dynamic();
242         if (!e) return 1;
243         memset(a, 0, sizeof(a));
244         RAND_add(a, sizeof(a), sizeof(a));
245         return(RAND_status() <= 0);
247                 ]])],
248                 [
249                         AC_MSG_RESULT([yes])
250                         ENGINE_LINK="${OPENSSL_DIR}/libcrypto.a"
251                 ],
252                 [AC_MSG_ERROR([OpenSSL is old and cannot link with its static library])]
253         )
254         CFLAGS="${saved_CFLAGS}"
255         LIBS="${saved_LIBS}"
256 fi
258 #@alonbl: This was never actually used.
260 # now - last part to do: check if we gain anything from
261 # funny parameters to link openssl with.
262 #saved_LDFLAGS="${LDFLAGS}"
263 #for test_flags in "-Wl,-Bsymbolic" "-G -Wl,-Bsymbolic" "-Wl,-all_load"; do
264 #       AC_MSG_CHECKING([whether we can use ${test_flags}])
265 #       LDFLAGS="${saved_LDFLAGS} ${test_flags}"
266 #       AC_LINK_IFELSE(
267 #               [AC_LANG_PROGRAM([[
268 #int test()
269 #{
270 #       return 1;
271 #}
272 #               ]])],
273 #               [result="yes"],
274 #               [result="no"]
275 #       )
276 #       AC_MSG_RESULT([${result}])
277 #       if test "${result}" = "yes"; then
278 #               OPENSSL_EXTRA_LDFLAGS="${test_flags}"
279 #               break;
280 #       fi
281 #done
282 #LDFLAGS="${saved_LDFLAGS}"
285 AC_SUBST([enginesdir])
286 AC_SUBST([ENGINE_LINK])
287 AC_SUBST([ENGINE_PKCS11_VERSION_MAJOR])
288 AC_SUBST([ENGINE_PKCS11_VERSION_MINOR])
289 AC_SUBST([ENGINE_PKCS11_VERSION_FIX])
290 AC_SUBST([WIN_LIBPREFIX])
291 AC_SUBST([OPENSSL_EXTRA_LDFLAGS])
293 AM_CONDITIONAL([SVN_CHECKOUT], [test "${svn_checkout}" = "yes"])
294 AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
295 AM_CONDITIONAL([CYGWIN], [test "${CYGWIN}" = "yes"])
296 AM_CONDITIONAL([ENABLE_DOC], [test "${enable_doc}" = "yes"])
298 if test "${enable_pedantic}" = "yes"; then
299         enable_strict="yes";
300         CFLAGS="${CFLAGS} -pedantic"
301 fi
302 if test "${enable_strict}" = "yes"; then
303         CFLAGS="${CFLAGS} -Wall -Wextra"
304 fi
306 AC_CONFIG_FILES([
307         Makefile
308         doc/Makefile
309         doc/nonpersistent/Makefile
310         src/Makefile
311         src/versioninfo.rc
312         example/Makefile
313 ])
314 AC_OUTPUT
316 cat <<EOF
318 engine_pkcs11 has been configured with the following options:
321 Version:                 ${PACKAGE_VERSION}
322 Libraries:               $(eval eval eval echo "${libdir}")
324 doc support:             ${enable_doc}
326 Host:                    ${host}
327 Compiler:                ${CC}
328 Preprocessor flags:      ${CPPFLAGS}
329 Compiler flags:          ${CFLAGS}
330 Linker flags:            ${LDFLAGS}
331 Libraries:               ${LIBS}
333 enginesdir               ${enginesdir}
335 LIBP11_CFLAGS:           ${LIBP11_CFLAGS}
336 LIBP11_LIBS:             ${LIBP11_LIBS}
337 OPENSSL_CFLAGS:          ${OPENSSL_CFLAGS}
338 OPENSSL_LIBS:            ${OPENSSL_LIBS}
339 OPENSSL_EXTRA_LDFLAGS:   ${OPENSSL_EXTRA_LDFLAGS}
340 ENGINE_LINK:             ${ENGINE_LINK}
342 EOF