Upstream tarball 20080721
[amule.git] / m4 / cryptopp.m4
blobbf8abc2fcc5234d0999f4debba7340897ed03c07
1 #                                                       -*- Autoconf -*-
2 # This file is part of the aMule Project.
4 # Copyright (c) 2003-2008 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
8 # respective authors.
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.
19
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])
27 dnl
28 dnl Check for cryptopp library
29 dnl --------------------------------------------------------------------------
30 dnl
31 dnl This macro sets these variables:
32 dnl - CRYPTOPP_PREFIX
33 dnl     This is the user or system directory where crypto++ is installed or sources
34 dnl - CRYPTOPP_VERSION_STRING
35 dnl     Something like "5.5.2"
36 dnl - CRYPTOPP_VERSION_NUMBER
37 dnl     Something like 5005002
38 dnl - CRYPTOPP_STYLE
39 dnl     "sources", "installed" or "gentoo_debian"
40 dnl - CRYPTOPP_LIB_NAME
41 dnl     "cryptopp" or "crypto++"
42 dnl - CRYPTOPP_INCLUDE_PREFIX
43 dnl     The string that goes here: #include <@CRYPTOPP_INCLUDE_PREFIX@/rsa.h>
44 dnl - CRYPTOPP_CPPFLAGS
45 dnl     Flags to be added to CPPFLAGS
46 dnl - CRYPTOPP_LDFLAGS
47 dnl     Flags to be added to LDFLAGS
48 dnl - CRYPTOPP_LIBS
49 dnl     Library to be added to LIBS
50 dnl
51 dnl The CRYPTOPP_CPPFLAGS, CRYPTOPP_LDFLAGS and CRYPTOPP_LIBS variables are also substituted.
52 dnl
53 dnl Worth notice:
54 dnl - cryptopp_includedir
55 dnl     The string that goes in -I on CPPFLAGS
56 dnl - cryptopp_libdir
57 dnl     The string that goes in -L on LDFLAGS
58 dnl - cryptopp_header_path
59 dnl     The file we use to discover the version of cryptopp
60 dnl
61 AC_DEFUN([MULE_CHECK_CRYPTOPP],
62 [dnl
63 m4_define([MIN_CRYPTO_VERSION], [m4_ifval([$1], [$1], [5.1])])dnl
65         AC_ARG_WITH([crypto-prefix],
66                 [AS_HELP_STRING([--with-crypto-prefix=PREFIX], [prefix where crypto++ is installed])])
68         AC_MSG_CHECKING([for crypto++ version >= MIN_CRYPTO_VERSION])
70         cryptopp_file_with_version="cryptlib.h"
72         CRYPTOPP_STYLE="unknown"
73         CRYPTOPP_LIB_NAME="unknown"
74         cryptopp_includedir="unknown"
75         CRYPTOPP_INCLUDE_PREFIX="unknown"
76         cryptopp_libdir="unknown"
78         for CRYPTOPP_PREFIX in "$with_crypto_prefix" /usr /usr/local /opt /opt/local /usr/pkg /mingw ; do
79                 AS_IF([test -z "$CRYPTOPP_PREFIX"], [continue])
81                 # Find the Cryptopp header
82                 MULE_IF([test -f $CRYPTOPP_PREFIX/$cryptopp_file_with_version], [
83                         CRYPTOPP_STYLE="sources"
84                         CRYPTOPP_LIB_NAME="cryptopp"
85                         cryptopp_includedir=
86                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_PREFIX"
87                         cryptopp_libdir=
88                         break
89                 ], [test -f $CRYPTOPP_PREFIX/include/cryptopp/$cryptopp_file_with_version], [
90                         CRYPTOPP_STYLE="installed"
91                         CRYPTOPP_LIB_NAME="cryptopp"
92                         cryptopp_includedir="$CRYPTOPP_PREFIX/include"
93                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
94                         cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
95                         break
96                 ], [test -f $CRYPTOPP_PREFIX/include/crypto++/$cryptopp_file_with_version], [
97                         # Debian uses libcrypto++5.1 - it's not my fault, please soda patch the package
98                         CRYPTOPP_STYLE="gentoo_debian"
99                         CRYPTOPP_LIB_NAME="crypto++"
100                         cryptopp_includedir="$CRYPTOPP_PREFIX/include"
101                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
102                         cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
103                         break
104                 ])
105         done
107         AS_IF([test $CRYPTOPP_STYLE = "unknown"], [result=no; resultstr=""], [
108                 # Find out the crypto++ version and check against the minimum required
109                 cryptopp_header_path="${cryptopp_includedir+$cryptopp_includedir/}$CRYPTOPP_INCLUDE_PREFIX/$cryptopp_file_with_version"
110                 CRYPTOPP_VERSION_STRING=`grep "Reference Manual" $cryptopp_header_path | sed -e ['s/[^0-9]*\([0-9.]*\).*/\1/']`
111                 CRYPTOPP_VERSION_NUMBER=`echo $CRYPTOPP_VERSION_STRING | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
112                 minvers=`echo MIN_CRYPTO_VERSION | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
114                 AS_IF([test -n "$CRYPTOPP_VERSION_NUMBER" && test "$CRYPTOPP_VERSION_NUMBER" -ge $minvers], [
115                         result=yes
116                         resultstr=" (version $CRYPTOPP_VERSION_STRING, $CRYPTOPP_STYLE)"
117                         AS_IF([test -n "$cryptopp_includedir"], [CRYPTOPP_CPPFLAGS="-I$cryptopp_includedir"], [CRYPTOPP_CPPFLAGS=])
118                         AS_IF([test -n "$cryptopp_libdir"], [
119                                 CRYPTOPP_LDFLAGS="-L$cryptopp_libdir"
120                                 CRYPTOPP_LIBS="-l$CRYPTOPP_LIB_NAME"
121                         ], [
122                                 CRYPTOPP_LDFLAGS=
123                                 CRYPTOPP_LIBS="${CRYPTOPP_INCLUDE_PREFIX}/lib${CRYPTOPP_LIB_NAME}.a"
124                         ])
125                         AH_TEMPLATE([CRYPTOPP_INCLUDE_PREFIX], [Define this to the include prefix of crypto++])
126                         AC_DEFINE_UNQUOTED([CRYPTOPP_INCLUDE_PREFIX], $CRYPTOPP_INCLUDE_PREFIX)
127                 ], [
128                         result=no
129                         resultstr=" (version $CRYPTOPP_VERSION_STRING is not new enough)"
130                 ])
131         ])
133         AC_MSG_RESULT([$result$resultstr])
135         AS_IF([test ${result:-no} = yes], [$2], [$3])
137 dnl Exported symbols
138 AC_SUBST([CRYPTOPP_CPPFLAGS])dnl
139 AC_SUBST([CRYPTOPP_LDFLAGS])dnl
140 AC_SUBST([CRYPTOPP_LIBS])dnl
141 m4_undefine([MIN_CRYPTO_VERSION])dnl