from waflib import Errors
from waftools.plugin import plugin

source = """
curl_http.c
""".split()

def plugin_configure(conf):
    try:
        conf.check_cfg(package="libcurl", uselib_store="curl",
                args="--cflags --libs")
    except Errors.ConfigurationError:
        conf.check_cfg(path="curl-config", package="", uselib_store="curl",
                args="--cflags --libs")

    # This is a function this plugin uses and that was added to curl in
    # version 7.12.0. We cannot check for the curl version as curl-config
    # did not support version tests before version 7.15.0
    fragment = """
    #include <curl/curl.h>
    int main(void) {
        return curl_multi_strerror(0) != 0;
    }
    """

    conf.check_cc(fragment=fragment,
            header_name="curl/curl.h", uselib="curl")

configure, build = plugin('curl', configure=plugin_configure,
                          source=source, libs=["socket", "curl"])
