2 # This file is part of the aMule Project.
4 # Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 # Any parts of this program derived from the xMule, lMule or eMule project,
7 # or contributed by third-party developers are copyrighted by their
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 dnl --------------------------------------------------------------------------
26 dnl MULE_CHECK_CRYPTOPP([VERSION = 5.1], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
28 dnl Check for cryptopp library
29 dnl --------------------------------------------------------------------------
31 dnl This macro sets these variables:
33 dnl This is the directory where crypto++ is located, if found. The format
34 dnl is suitable to be passed to --with-crypto-prefix.
35 dnl - CRYPTOPP_VERSION_STRING
36 dnl Something like "5.5.2"
37 dnl - CRYPTOPP_VERSION_NUMBER
38 dnl Something like 5005002
39 dnl - CRYPTOPP_LIB_NAME
40 dnl "cryptopp" or "crypto++"
42 dnl Exported variables (to amule-config.h, to be used in C++ source files):
43 dnl - CRYPTOPP_INCLUDE_PREFIX
44 dnl The string that goes here: #include <CRYPTOPP_INCLUDE_PREFIX/rsa.h>
46 dnl Substituted variables (to be used in Makefiles):
47 dnl - CRYPTOPP_CPPFLAGS
48 dnl Flags to be added to CPPFLAGS
49 dnl - CRYPTOPP_LDFLAGS
50 dnl Flags to be added to LDFLAGS
52 dnl Library to be added to LIBS
54 AC_DEFUN([MULE_CHECK_CRYPTOPP],
56 AC_REQUIRE([AC_PROG_EGREP])dnl
57 AC_LANG_ASSERT([C++])dnl
58 m4_define([MIN_CRYPTO_VERSION], [m4_ifval([$1], [$1], [5.1])])dnl
59 m4_define([cryptopp_file_with_version], [cryptlib.h])dnl
61 AC_ARG_WITH([crypto-prefix],
62 [AS_HELP_STRING([--with-crypto-prefix=PREFIX], [prefix where crypto++ is installed])])
64 AC_MSG_CHECKING([for crypto++ version >= MIN_CRYPTO_VERSION])
68 AS_IF([test -n "$with_crypto_prefix"], [
69 CRYPTOPP_PREFIX="$with_crypto_prefix"
70 # Find the Cryptopp header in the user-provided location
71 MULE_IF([test -f $CRYPTOPP_PREFIX/cryptopp_file_with_version], [
73 CRYPTOPP_LIB_NAME="cryptopp"
74 CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_PREFIX"
77 CRYPTOPP_LIBS="${CRYPTOPP_PREFIX}/lib${CRYPTOPP_LIB_NAME}.a"
79 for CRYPTOPP_LIB_NAME in "cryptopp" "crypto++"; do
80 AS_IF([test -f $CRYPTOPP_PREFIX/include/$CRYPTOPP_LIB_NAME/cryptopp_file_with_version], [
82 CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
83 CRYPTOPP_CPPFLAGS="-I$CRYPTOPP_PREFIX/include"
84 CRYPTOPP_LDFLAGS="-L$CRYPTOPP_PREFIX/lib"
85 CRYPTOPP_LIBS="-l$CRYPTOPP_LIB_NAME"
91 # Check whether the compiler can find it
92 for CRYPTOPP_LIB_NAME in "cryptopp" "crypto++"; do
93 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
94 #include <$CRYPTOPP_LIB_NAME/]cryptopp_file_with_version[>
98 CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
101 CRYPTOPP_LIBS="-l$CRYPTOPP_LIB_NAME"
107 AS_IF([$cryptopp_found], [
108 # Find out the crypto++ version and check against the minimum required
109 # Ask the compiler where are the crypto++ files
110 MULE_BACKUP([CPPFLAGS])
111 MULE_APPEND([CPPFLAGS], [$CRYPTOPP_CPPFLAGS])
113 dnl To be able to preprocess the file but scan the preprocessed results
114 dnl ourselves, we need to use undocumented features of autoconf.
115 AC_LANG_CONFTEST([AC_LANG_SOURCE([
116 #include <$CRYPTOPP_INCLUDE_PREFIX/]cryptopp_file_with_version[>
118 [cryptopp_header_path=`(eval "$ac_cpp conftest.$ac_ext") 2>&]AS_MESSAGE_LOG_FD[ | sed -e '/^#.*]cryptopp_file_with_version[/{s/.*"\(.*\)".*/\1/;q;};d'`]
121 MULE_RESTORE([CPPFLAGS])
122 # Set a prefix suitable for --with-crypto-prefix
123 CRYPTOPP_PREFIX="${cryptopp_header_path%/*}"
124 CRYPTOPP_PREFIX="${CRYPTOPP_PREFIX%/include/${CRYPTOPP_LIB_NAME}}"
125 # Now check the version
126 CRYPTOPP_VERSION_STRING=`$EGREP "Reference Manual|API Reference" $cryptopp_header_path | sed -e ['s/[^0-9]*\([0-9.]*\).*/\1/']`
127 CRYPTOPP_VERSION_NUMBER=`echo $CRYPTOPP_VERSION_STRING | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
128 minvers=`echo MIN_CRYPTO_VERSION | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
130 AS_IF([test -n "$CRYPTOPP_VERSION_NUMBER" && test "$CRYPTOPP_VERSION_NUMBER" -ge $minvers], [
132 resultstr=" (version $CRYPTOPP_VERSION_STRING)"
133 AH_TEMPLATE([CRYPTOPP_INCLUDE_PREFIX], [Define this to the include prefix of crypto++])
134 AC_DEFINE_UNQUOTED([CRYPTOPP_INCLUDE_PREFIX], $CRYPTOPP_INCLUDE_PREFIX)
137 resultstr=" (version $CRYPTOPP_VERSION_STRING is not new enough)"
142 ], [result="no"; resultstr=])
144 AC_MSG_RESULT([$result$resultstr])
146 AS_IF([test ${result:-no} = yes], [$2], [$3])
149 AC_SUBST([CRYPTOPP_CPPFLAGS])dnl
150 AC_SUBST([CRYPTOPP_LDFLAGS])dnl
151 AC_SUBST([CRYPTOPP_LIBS])dnl
152 m4_undefine([cryptopp_file_with_version])dnl
153 m4_undefine([MIN_CRYPTO_VERSION])dnl