# vim: sts=2 ts=8 sw=2 tw=99 et ft=python:
import os, platform

builder.SetBuildFolder('libcurl')

rvalue = {}
for cxx in builder.targets:
  binary = Extension.StaticLibrary(builder, cxx, 'curl')
  binary.compiler.includes += [
    os.path.join(builder.sourcePath, 'curl', 'include'),
    os.path.join(builder.sourcePath, 'curl', 'lib'),
    os.path.join(builder.sourcePath, 'mbedtls', 'include'),
    os.path.join(builder.sourcePath, 'nghttp2', 'lib', 'includes'),
    os.path.join(builder.sourcePath, 'zlib'),
  ]
  binary.compiler.defines += [
    'BUILDING_LIBCURL',
    'CURL_STATICLIB',
    'HAVE_CONFIG_H',
    'HTTP_ONLY',
    'NGHTTP2_STATICLIB',
  ]

  if binary.compiler.target.platform == 'linux':
    binary.compiler.defines += ['_GNU_SOURCE']
  elif binary.compiler.target.platform == 'mac':
    mac_version, ignore, ignore = platform.mac_ver()
    mac_tuple = mac_version.split('.')
    if int(mac_tuple[0]) >= 10 and int(mac_tuple[1]) >= 9:
      binary.compiler.defines += ['BUILTIN_STRLCAT']

  if binary.compiler.family == 'clang':
    # https://llvm.org/bugs/show_bug.cgi?id=16428
    binary.compiler.cflags += ['-Wno-attributes']

  # Defined in curl/lib/Makefile.inc
  binary.sources += [
    # LIB_CFILES
    'altsvc.c',
    'amigaos.c',
    'asyn-ares.c',
    'asyn-thread.c',
    'base64.c',
    'c-hyper.c',
    'conncache.c',
    'connect.c',
    'content_encoding.c',
    'cookie.c',
    'curl_addrinfo.c',
    'curl_ctype.c',
    'curl_des.c',
    'curl_endian.c',
    'curl_fnmatch.c',
    'curl_get_line.c',
    'curl_gethostname.c',
    'curl_gssapi.c',
    'curl_memrchr.c',
    'curl_multibyte.c',
    'curl_ntlm_core.c',
    'curl_ntlm_wb.c',
    'curl_path.c',
    'curl_range.c',
    'curl_rtmp.c',
    'curl_sasl.c',
    'curl_sspi.c',
    'curl_threads.c',
    'dict.c',
    'doh.c',
    'dotdot.c',
    'dynbuf.c',
    'easy.c',
    'easygetopt.c',
    'easyoptions.c',
    'escape.c',
    'file.c',
    'fileinfo.c',
    'formdata.c',
    'ftp.c',
    'ftplistparser.c',
    'getenv.c',
    'getinfo.c',
    'gopher.c',
    'hash.c',
    'hmac.c',
    'hostasyn.c',
    'hostcheck.c',
    'hostip.c',
    'hostip4.c',
    'hostip6.c',
    'hostsyn.c',
    'hsts.c',
    'http.c',
    'http2.c',
    'http_chunks.c',
    'http_digest.c',
    'http_negotiate.c',
    'http_ntlm.c',
    'http_proxy.c',
    'http_aws_sigv4.c',
    'idn_win32.c',
    'if2ip.c',
    'imap.c',
    'inet_ntop.c',
    'inet_pton.c',
    'krb5.c',
    'ldap.c',
    'llist.c',
    'md4.c',
    'md5.c',
    'memdebug.c',
    'mime.c',
    'mprintf.c',
    'mqtt.c',
    'multi.c',
    'netrc.c',
    'non-ascii.c',
    'nonblock.c',
    'openldap.c',
    'parsedate.c',
    'pingpong.c',
    'pop3.c',
    'progress.c',
    'psl.c',
    'rand.c',
    'rename.c',
    'rtsp.c',
    'select.c',
    'sendf.c',
    'setopt.c',
    'sha256.c',
    'share.c',
    'slist.c',
    'smb.c',
    'smtp.c',
    'socketpair.c',
    'socks.c',
    'socks_gssapi.c',
    'socks_sspi.c',
    'speedcheck.c',
    'splay.c',
    'strcase.c',
    'strdup.c',
    'strerror.c',
    'strtok.c',
    'strtoofft.c',
    'system_win32.c',
    'telnet.c',
    'tftp.c',
    'timeval.c',
    'transfer.c',
    'url.c',
    'urlapi.c',
    'version.c',
    'version_win32.c',
    'warnless.c',
    'wildcard.c',
    'x509asn1.c',

    # LIB_VAUTH_CFILES
    'vauth/cleartext.c',
    'vauth/cram.c',
    'vauth/digest.c',
    'vauth/digest_sspi.c',
    'vauth/krb5_gssapi.c',
    'vauth/krb5_sspi.c',
    'vauth/ntlm.c',
    'vauth/ntlm_sspi.c',
    'vauth/oauth2.c',
    'vauth/spnego_gssapi.c',
    'vauth/spnego_sspi.c',
    'vauth/vauth.c',

    # LIB_VQUIC_CFILES
    'vquic/ngtcp2.c',
    'vquic/quiche.c',
    'vquic/vquic.c',

    # LIB_VSSH_CFILES
    'vssh/libssh.c',
    'vssh/libssh2.c',
    'vssh/wolfssh.c',

    # LIB_VTLS_CFILES
    'vtls/bearssl.c',
    'vtls/gskit.c',
    'vtls/gtls.c',
    'vtls/keylog.c',
    'vtls/mbedtls.c',
    'vtls/mbedtls_threadlock.c',
    'vtls/mesalink.c',
    'vtls/nss.c',
    'vtls/openssl.c',
    'vtls/schannel.c',
    'vtls/schannel_verify.c',
    'vtls/sectransp.c',
    'vtls/vtls.c',
    'vtls/wolfssl.c',
  ]

  rvalue[binary.compiler.target.arch] = builder.Add(binary)
