Upstream tarball 9745
[amule.git] / m4 / cryptopp.m4
blob28f6beaa4b241fb020c15f93311580d98da553be
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 AC_REQUIRE([AC_PROG_EGREP])dnl
64 m4_define([MIN_CRYPTO_VERSION], [m4_ifval([$1], [$1], [5.1])])dnl
66         AC_ARG_WITH([crypto-prefix],
67                 [AS_HELP_STRING([--with-crypto-prefix=PREFIX], [prefix where crypto++ is installed])])
69         AC_MSG_CHECKING([for crypto++ version >= MIN_CRYPTO_VERSION])
71         cryptopp_file_with_version="cryptlib.h"
73         CRYPTOPP_STYLE="unknown"
74         CRYPTOPP_LIB_NAME="unknown"
75         cryptopp_includedir="unknown"
76         CRYPTOPP_INCLUDE_PREFIX="unknown"
77         cryptopp_libdir="unknown"
79         for CRYPTOPP_PREFIX in "$with_crypto_prefix" /usr /usr/local /opt /opt/local /usr/pkg /mingw ; do
80                 AS_IF([test -z "$CRYPTOPP_PREFIX"], [continue])
82                 # Find the Cryptopp header
83                 MULE_IF([test -f $CRYPTOPP_PREFIX/$cryptopp_file_with_version], [
84                         CRYPTOPP_STYLE="sources"
85                         CRYPTOPP_LIB_NAME="cryptopp"
86                         cryptopp_includedir=
87                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_PREFIX"
88                         cryptopp_libdir=
89                         break
90                 ], [test -f $CRYPTOPP_PREFIX/include/cryptopp/$cryptopp_file_with_version], [
91                         CRYPTOPP_STYLE="installed"
92                         CRYPTOPP_LIB_NAME="cryptopp"
93                         cryptopp_includedir="$CRYPTOPP_PREFIX/include"
94                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
95                         cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
96                         break
97                 ], [test -f $CRYPTOPP_PREFIX/include/crypto++/$cryptopp_file_with_version], [
98                         # Debian uses libcrypto++5.1 - it's not my fault, please soda patch the package
99                         CRYPTOPP_STYLE="gentoo_debian"
100                         CRYPTOPP_LIB_NAME="crypto++"
101                         cryptopp_includedir="$CRYPTOPP_PREFIX/include"
102                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
103                         cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
104                         break
105                 ])
106         done
108         AS_IF([test $CRYPTOPP_STYLE = "unknown"], [result=no; resultstr=""], [
109                 # Find out the crypto++ version and check against the minimum required
110                 cryptopp_header_path="${cryptopp_includedir+$cryptopp_includedir/}$CRYPTOPP_INCLUDE_PREFIX/$cryptopp_file_with_version"
111                 CRYPTOPP_VERSION_STRING=`$EGREP "Reference Manual|API Reference" $cryptopp_header_path | sed -e ['s/[^0-9]*\([0-9.]*\).*/\1/']`
112                 CRYPTOPP_VERSION_NUMBER=`echo $CRYPTOPP_VERSION_STRING | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
113                 minvers=`echo MIN_CRYPTO_VERSION | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
115                 AS_IF([test -n "$CRYPTOPP_VERSION_NUMBER" && test "$CRYPTOPP_VERSION_NUMBER" -ge $minvers], [
116                         result=yes
117                         resultstr=" (version $CRYPTOPP_VERSION_STRING, $CRYPTOPP_STYLE)"
118                         AS_IF([test -n "$cryptopp_includedir"], [CRYPTOPP_CPPFLAGS="-I$cryptopp_includedir"], [CRYPTOPP_CPPFLAGS=])
119                         AS_IF([test -n "$cryptopp_libdir"], [
120                                 CRYPTOPP_LDFLAGS="-L$cryptopp_libdir"
121                                 CRYPTOPP_LIBS="-l$CRYPTOPP_LIB_NAME"
122                         ], [
123                                 CRYPTOPP_LDFLAGS=
124                                 CRYPTOPP_LIBS="${CRYPTOPP_INCLUDE_PREFIX}/lib${CRYPTOPP_LIB_NAME}.a"
125                         ])
126                         AH_TEMPLATE([CRYPTOPP_INCLUDE_PREFIX], [Define this to the include prefix of crypto++])
127                         AC_DEFINE_UNQUOTED([CRYPTOPP_INCLUDE_PREFIX], $CRYPTOPP_INCLUDE_PREFIX)
128                 ], [
129                         result=no
130                         resultstr=" (version $CRYPTOPP_VERSION_STRING is not new enough)"
131                 ])
132         ])
134         AC_MSG_RESULT([$result$resultstr])
136         AS_IF([test ${result:-no} = yes], [$2], [$3])
138 dnl Exported symbols
139 AC_SUBST([CRYPTOPP_CPPFLAGS])dnl
140 AC_SUBST([CRYPTOPP_LDFLAGS])dnl
141 AC_SUBST([CRYPTOPP_LIBS])dnl
142 m4_undefine([MIN_CRYPTO_VERSION])dnl