1dnl Check for CURL Libraries
2dnl CHECK_CURL(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
3dnl Sets:
4dnl  CURL_CFLAGS
5dnl  CURL_LDADD
6dnl  CURL_LIBS
7
8CURL_CONFIG=""
9CURL_VERSION=""
10CURL_CPPFLAGS=""
11CURL_CFLAGS=""
12CURL_LDFLAGS=""
13CURL_LDADD=""
14CURL_MIN_VERSION="7.15.1"
15
16AC_DEFUN([CHECK_CURL],
17[dnl
18
19AC_ARG_WITH(
20    curl,
21    [AC_HELP_STRING([--with-curl=PATH],[Path to curl prefix or config script])],
22    [test_paths="${with_curl}"],
23    [test_paths="/usr/local/libcurl /usr/local/curl /usr/local /opt/libcurl /opt/curl /opt /usr"])
24
25AC_MSG_CHECKING([for libcurl config script])
26
27for x in ${test_paths}; do
28    dnl # Determine if the script was specified and use it directly
29    if test ! -d "$x" -a -e "$x"; then
30        CURL_CONFIG=$x
31        curl_path="no"
32        break
33    fi
34
35    dnl # Try known config script names/locations
36    for CURL_CONFIG in curl-config; do
37        if test -e "${x}/bin/${CURL_CONFIG}"; then
38            curl_path="${x}/bin"
39            break
40        elif test -e "${x}/${CURL_CONFIG}"; then
41            curl_path="${x}"
42            break
43        else
44            curl_path=""
45        fi
46    done
47    if test -n "$curl_path"; then
48        break
49    fi
50done
51
52if test -n "${curl_path}"; then
53    if test "${curl_path}" != "no"; then
54        CURL_CONFIG="${curl_path}/${CURL_CONFIG}"
55    fi
56    AC_MSG_RESULT([${CURL_CONFIG}])
57    CURL_VERSION=`${CURL_CONFIG} --version | sed 's/^[[^0-9]][[^[:space:]]][[^[:space:]]]*[[[:space:]]]*//' | tr '\r\n' ' '`
58    if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(curl VERSION: $CURL_VERSION); fi
59    CURL_CFLAGS="`${CURL_CONFIG} --cflags`"
60    if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(curl CFLAGS: $CURL_CFLAGS); fi
61    CURL_LIBS="`${CURL_CONFIG} --libs`"
62    CURL_LDADD="${CURL_LIBS}"
63    if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(curl LDADD: $CURL_LIBS); fi
64
65    dnl # Check version is ok
66    AC_MSG_CHECKING([if libcurl is at least v${CURL_MIN_VERSION}])
67    curl_min_ver=`echo ${CURL_MIN_VERSION} | awk -F. '{print (\$ 1 * 1000000) + (\$ 2 * 1000) + \$ 3}'`
68    curl_ver=`echo ${CURL_VERSION} | awk -F. '{print (\$ 1 * 1000000) + (\$ 2 * 1000) + \$ 3}'`
69    if test "$curl_min_ver" -le "$curl_ver"; then
70        AC_MSG_RESULT([yes, $CURL_VERSION])
71	curl_tlsv2_ver=`echo 7.34.0 | awk -F. '{print (\$ 1 * 1000000) + (\$ 2 * 1000) + \$ 3}'`
72	if test "$curl_tlsv2_ver" -le "$curl_ver"; then
73	    CURL_CFLAGS="${CURL_CFLAGS} -DWITH_CURL_SSLVERSION_TLSv1_2"
74	fi
75	CURL_CFLAGS="${CURL_CFLAGS} -DWITH_CURL"
76    else
77        AC_MSG_RESULT([no, $CURL_VERSION])
78        AC_MSG_NOTICE([NOTE: curl library may be too old])
79    fi
80
81    dnl # Check/warn if GnuTLS is used
82    AC_MSG_CHECKING([if libcurl is linked with gnutls])
83    curl_uses_gnutls=`echo ${CURL_LIBS} | grep gnutls | wc -l`
84    if test "$curl_uses_gnutls" -ne 0; then
85        AC_MSG_RESULT([yes])
86        AC_MSG_NOTICE([NOTE: curl linked with gnutls may be buggy, openssl recommended])
87        CURL_USES_GNUTLS=yes
88    else
89        AC_MSG_RESULT([no])
90        CURL_USES_GNUTLS=no
91    fi
92
93else
94    AC_MSG_RESULT([no])
95fi
96
97AC_SUBST(CURL_CONFIG)
98AC_SUBST(CURL_VERSION)
99AC_SUBST(CURL_CPPFLAGS)
100AC_SUBST(CURL_CFLAGS)
101AC_SUBST(CURL_LDFLAGS)
102AC_SUBST(CURL_LDADD)
103AC_SUBST(CURL_USES_GNUTLS)
104
105if test -z "${CURL_VERSION}"; then
106  AC_MSG_NOTICE([*** curl library not found.])
107  ifelse([$2], , AC_MSG_NOTICE([NOTE: curl library is only required for building mlogc]), $2)
108else
109  AC_MSG_NOTICE([using curl v${CURL_VERSION}])
110  ifelse([$1], , , $1)
111fi
112])
113