distributable:
  - url: https://c-ares.org/download/c-ares-{{version}}.tar.gz
    strip-components: 1
  - url: https://github.com/c-ares/c-ares/releases/download/v{{ version }}/c-ares-{{ version }}.tar.gz
    strip-components: 1

versions:
  url: https://c-ares.org/download
  match: /c-ares-\d+\.\d+\.\d+\.tar\.gz/
  strip:
    - /c-ares-/
    - /.tar.gz/

build:
  dependencies:
    cmake.org: ^3
    curl.se: '*'
  working-directory: build
  script:
    # thirdparty header not packaged in tarball
    # https://github.com/c-ares/c-ares/pull/750
    - run: curl -O https://opensource.apple.com/source/configd/configd-1109.140.1/dnsinfo/dnsinfo.h
      working-directory: ../src/lib/thirdparty/apple
      if: '>=1.29.0'
    - cmake .. -DCMAKE_INSTALL_PREFIX="{{prefix}}" -DCMAKE_BUILD_TYPE=Release
    - make --jobs {{hw.concurrency}} install

test:
  fixture: |
    #include <stdio.h>
    #include <ares.h>
    int main() {
      ares_library_init(ARES_LIB_INIT_ALL);
      ares_library_cleanup();
      return 0;
    }
  script: |
    mv $FIXTURE b.c
    cc b.c -lcares
    ./a.out
