1dnl $Id: ssl-check.m4,v 1.14 2008-11-22 12:07:26 didg Exp $
2dnl Autoconf macro to check for SSL or OpenSSL
3
4AC_DEFUN([AC_CRYPT], [
5
6	saveLIBS=$LIBS
7	LIBS=""
8	CRYPT_LIBS=""
9
10	AC_CHECK_HEADERS(crypt.h)
11	AC_CHECK_LIB(crypt, main)
12
13	CRYPT_LIBS=$LIBS
14	LIBS=$saveLIBS
15
16	AC_SUBST(CRYPT_LIBS)
17])
18
19
20AC_DEFUN([AC_PATH_SSL], [
21	AC_ARG_WITH(ssl-dir, [  --with-ssl-dir=PATH     specify path to OpenSSL installation (must contain
22                          lib and include dirs)],
23		[
24			if test "x$withval" = "xno"; then
25				tryssl=no
26			elif test "x$withval" = "xyes"; then
27				tryssl=yes
28				tryssldir=
29			else
30				dnl FIXME: should only try in $withval
31				tryssl=yes
32				tryssldir="$withval"
33			fi
34		], [tryssl=yes]
35	)
36
37	SSL_CFLAGS=""
38	SSL_LIBS=""
39	saved_LIBS=$LIBS
40	saved_CFLAGS=$CFLAGS
41	neta_cv_have_openssl=no
42dnl	compile_ssl=no
43
44	dnl make sure atalk_libname is defined beforehand
45	[[ -n "$atalk_libname" ]] || AC_MSG_ERROR([internal error, atalk_libname undefined])
46
47	if test "$tryssl" = "yes"; then
48		AC_MSG_CHECKING([for SSL])
49		for ssldir in "" $tryssldir /usr /usr/local/openssl /usr/$atalk_libname/openssl /usr/local/ssl /usr/$atalk_libname/ssl /usr/local /usr/pkg /opt /opt/openssl /usr/local/ssl ; do
50			if test -f "$ssldir/include/openssl/cast.h" ; then
51				SSL_CFLAGS="$SSL_CFLAGS -I$ssldir/include -I$ssldir/include/openssl"
52				SSL_LIBS="$SSL_LIBS -L$ssldir/$atalk_libname -L$ssldir -lcrypto"
53				if test "x$need_dash_r" = "xyes"; then
54					SSL_LIBS="$SSL_LIBS -R$ssldir/$atalk_libname -R$ssldir"
55				fi
56				AC_MSG_RESULT([$ssldir (enabling RANDNUM and DHX support)])
57				CFLAGS="$CFLAGS $SSL_CFLAGS"
58				LIBS="$LIBS $SSL_LIBS"
59
60dnl FIXME: The following looks crude and probably doesn't work properly.
61				dnl Check for the crypto library:
62				AC_CHECK_LIB(crypto, main)
63				dnl Check for "DES" library (for SSLeay, not openssl):
64				AC_CHECK_LIB(des, main)
65
66		 		AC_DEFINE(OPENSSL_DHX,	1, [Define if the OpenSSL DHX modules should be built])
67				AC_DEFINE(UAM_DHX,	1, [Define if the DHX UAM modules should be compiled])
68				neta_cv_have_openssl=yes
69				neta_cv_compile_dhx=yes
70				CFLAGS=$saved_CFLAGS
71				LIBS=$saved_LIBS
72				break
73			fi
74		done
75		if test "x$neta_cv_have_openssl" = "xno"; then
76			AC_MSG_RESULT([no])
77		fi
78	fi
79	CFLAGS_REMOVE_USR_INCLUDE(SSL_CFLAGS)
80	LIB_REMOVE_USR_LIB(SSL_LIBS)
81	AC_SUBST(SSL_CFLAGS)
82	AC_SUBST(SSL_LIBS)
83	LIBS=$saved_LIBS
84])
85