dnl CF_SSL version: 22 updated: 2010/06/20 09:24:28
dnl ------
dnl Check for ssl library
dnl $1 = [optional] directory in which the library may be found, set by AC_ARG_WITH
AC_DEFUN([CF_SSL],[
	AC_REQUIRE([CF_PKG_CONFIG])
	cf_cv_have_ssl=no
	cf_cv_pkg_config_ssl=no

	# command-line option, etc., override default behavior
	CF_ADD_OPTIONAL_PATH($1, [ssl library])

	if test "x$PKG_CONFIG" != xnone; then
		case $1 in #(vi
		no) #(vi
			;;
		yes) # if no explicit directory given, try pkg-config
			if "$PKG_CONFIG" --exists openssl ; then
				cf_cv_have_ssl=yes
				cf_cv_pkg_config_ssl=yes

				cf_cflags_ssl=`$PKG_CONFIG --cflags openssl`
				cf_libs_ssl=`$PKG_CONFIG --libs openssl`

				if test -n "$cf_cflags_ssl" ; then
					case "$cf_cflags_ssl" in #(vi
					*-I*) #(vi
						cf_cv_header_path_ssl=`echo "$cf_cflags_ssl" | sed -e 's/^.*-I//' -e 's/ .*//'`
						;;
					*)
						cf_cv_header_path_ssl=/usr/include
						;;
					esac
					if test -d $cf_cv_header_path_ssl/openssl ; then
						cf_cv_header_path_ssl=$cf_cv_header_path_ssl/openssl
					fi
					CF_ADD_CFLAGS($cf_cflags_ssl)

					# workaround for broken openssl package using kerberos
					case "$cf_cflags_ssl" in #(vi
					*kerberos*)
						cf_cv_have_ssl=maybe
						;;
					esac
				fi

				if test -n "$cf_libs_ssl" ; then
					case "x$cf_libs_ssl" in #(vi
					*-L*) #(vi
						cf_cv_library_path_ssl=`echo "$cf_libs_ssl" | sed -e 's/^.*-L//' -e 's/ .*//'`
						;;
					*)
						cf_cv_library_path_ssl=/usr/lib
						;;
					esac
					CF_VERBOSE(adding $cf_libs_ssl to LIBS)
					CF_ADD_LIBS($cf_libs_ssl)
				fi
			fi
			;;
		esac
	fi

	if test "$cf_cv_have_ssl" != yes; then
		case $host_os in #(vi
		mingw*) #(vi
			cf_extra_ssl_libs="-lcrypto -lgdi32"
			;;
		*)
			# openssl 0.9.6 and up use dynamic loading for engines.
			cf_extra_ssl_libs="-lcrypto"
			case "x$LIBS" in #(vi
			*-ldl) #(vi
				;;
			*)
				AC_CHECK_LIB(dl,dlsym,
					[cf_extra_ssl_libs="$cf_extra_ssl_libs -ldl"])
				;;
			esac
			;;
		esac

		CF_FIND_LINKAGE(CF__SSL_HEAD,
			CF__SSL_BODY,
			ssl,
			cf_cv_have_ssl=yes,
			cf_cv_have_ssl=no,
			openssl,
			$cf_extra_ssl_libs)

		if test "$cf_cv_pkg_config_ssl" != yes ; then
			if test "$cf_cv_have_ssl" = yes ; then
				if test -n "$cf_cv_library_path_ssl" ; then
					CF_ADD_LIBDIR($cf_cv_library_path_ssl)
				fi
				CF_ADD_LIBS(-lssl $cf_extra_ssl_libs)
				if test -n "$cf_cv_header_path_ssl" ; then
					case $cf_cv_header_path_ssl in #(vi
					/usr/include/openssl) #(vi
						;;
					*)
						CF_ADD_INCDIR($cf_cv_header_path_ssl)
						;;
					esac
				fi
			fi
		fi
	fi

	if test "$cf_cv_have_ssl" = yes ; then
		AC_DEFINE(USE_SSL)
		if test -n "$cf_cv_header_path_ssl" ; then
			case $cf_cv_header_path_ssl in #(vi
			*/openssl)
				AC_DEFINE(USE_OPENSSL_INCL)
				;;
			esac
		fi
		CF_CHECK_SSL_X509
	fi
])dnl
