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