Use proper error reporting with Asio sockets
[amule.git] / m4 / cryptopp.m4
blobdb62f58a50fe96c916d63c206c0810479ad61a45
1 #                                                       -*- Autoconf -*-
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
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.
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         AS_IF([test -n "$with_crypto_prefix"], [
80                 CRYPTOPP_PREFIX="$with_crypto_prefix"
81                 # Find the Cryptopp header in the user-provided location
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                 ], [test -f $CRYPTOPP_PREFIX/include/cryptopp/$cryptopp_file_with_version], [
89                         CRYPTOPP_STYLE="installed"
90                         CRYPTOPP_LIB_NAME="cryptopp"
91                         cryptopp_includedir="$CRYPTOPP_PREFIX/include"
92                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
93                         cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
94                 ], [test -f $CRYPTOPP_PREFIX/include/crypto++/$cryptopp_file_with_version], [
95                         # Debian uses libcrypto++5.1 - it's not my fault, please soda patch the package
96                         CRYPTOPP_STYLE="gentoo_debian"
97                         CRYPTOPP_LIB_NAME="crypto++"
98                         cryptopp_includedir="$CRYPTOPP_PREFIX/include"
99                         CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
100                         cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
101                 ])
102         ], [
103                 for CRYPTOPP_PREFIX in /usr /usr/local /opt /opt/local /usr/pkg /mingw ; do
104                         # Find the Cryptopp header in system locations
105                         MULE_IF([test -f $CRYPTOPP_PREFIX/$cryptopp_file_with_version], [
106                                 CRYPTOPP_STYLE="sources"
107                                 CRYPTOPP_LIB_NAME="cryptopp"
108                                 cryptopp_includedir=
109                                 CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_PREFIX"
110                                 cryptopp_libdir=
111                                 break
112                         ], [test -f $CRYPTOPP_PREFIX/include/cryptopp/$cryptopp_file_with_version], [
113                                 CRYPTOPP_STYLE="installed"
114                                 CRYPTOPP_LIB_NAME="cryptopp"
115                                 cryptopp_includedir="$CRYPTOPP_PREFIX/include"
116                                 CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
117                                 cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
118                                 break
119                         ], [test -f $CRYPTOPP_PREFIX/include/crypto++/$cryptopp_file_with_version], [
120                                 # Debian uses libcrypto++5.1 - it's not my fault, please soda patch the package
121                                 CRYPTOPP_STYLE="gentoo_debian"
122                                 CRYPTOPP_LIB_NAME="crypto++"
123                                 cryptopp_includedir="$CRYPTOPP_PREFIX/include"
124                                 CRYPTOPP_INCLUDE_PREFIX="$CRYPTOPP_LIB_NAME"
125                                 cryptopp_libdir="$CRYPTOPP_PREFIX/lib"
126                                 break
127                         ])
128                 done
129         ])
131         AS_IF([test $CRYPTOPP_STYLE = "unknown"], [result=no; resultstr=""], [
132                 # Find out the crypto++ version and check against the minimum required
133                 cryptopp_header_path="${cryptopp_includedir+$cryptopp_includedir/}$CRYPTOPP_INCLUDE_PREFIX/$cryptopp_file_with_version"
134                 CRYPTOPP_VERSION_STRING=`$EGREP "Reference Manual|API Reference" $cryptopp_header_path | sed -e ['s/[^0-9]*\([0-9.]*\).*/\1/']`
135                 CRYPTOPP_VERSION_NUMBER=`echo $CRYPTOPP_VERSION_STRING | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
136                 minvers=`echo MIN_CRYPTO_VERSION | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
138                 AS_IF([test -n "$CRYPTOPP_VERSION_NUMBER" && test "$CRYPTOPP_VERSION_NUMBER" -ge $minvers], [
139                         result=yes
140                         resultstr=" (version $CRYPTOPP_VERSION_STRING, $CRYPTOPP_STYLE)"
141                         AS_IF([test -n "$cryptopp_includedir"], [CRYPTOPP_CPPFLAGS="-I$cryptopp_includedir"], [CRYPTOPP_CPPFLAGS=])
142                         AS_IF([test -n "$cryptopp_libdir"], [
143                                 CRYPTOPP_LDFLAGS="-L$cryptopp_libdir"
144                                 CRYPTOPP_LIBS="-l$CRYPTOPP_LIB_NAME"
145                         ], [
146                                 CRYPTOPP_LDFLAGS=
147                                 CRYPTOPP_LIBS="${CRYPTOPP_INCLUDE_PREFIX}/lib${CRYPTOPP_LIB_NAME}.a"
148                         ])
149                         AH_TEMPLATE([CRYPTOPP_INCLUDE_PREFIX], [Define this to the include prefix of crypto++])
150                         AC_DEFINE_UNQUOTED([CRYPTOPP_INCLUDE_PREFIX], $CRYPTOPP_INCLUDE_PREFIX)
151                 ], [
152                         result=no
153                         resultstr=" (version $CRYPTOPP_VERSION_STRING is not new enough)"
154                 ])
155         ])
157         AC_MSG_RESULT([$result$resultstr])
159         AS_IF([test ${result:-no} = yes], [$2], [$3])
161 dnl Exported symbols
162 AC_SUBST([CRYPTOPP_CPPFLAGS])dnl
163 AC_SUBST([CRYPTOPP_LDFLAGS])dnl
164 AC_SUBST([CRYPTOPP_LIBS])dnl
165 m4_undefine([MIN_CRYPTO_VERSION])dnl