distributable:
  url: https://github.com/facebook/zstd/archive/v{{version}}.tar.gz
  strip-components: 1

versions:
  github: facebook/zstd/releases/tags

dependencies:
  lz4.org: ^1
  tukaani.org/xz: ^5
  zlib.net: ^1

provides:
  - bin/pzstd
  - bin/unzstd
  - bin/zstd
  - bin/zstdcat
  - bin/zstdgrep
  - bin/zstdless
  - bin/zstdmt

build:
  dependencies:
    cmake.org: ^3
    ninja-build.org: ^1
  working-directory: build/out
  script:
    - cmake ../cmake $ARGS
    - cmake --build .
    - cmake --install .
    - run: |
        install_name_tool -add_rpath @loader_path/../lib pzstd
        install_name_tool -add_rpath @loader_path/../lib zstd
      if: darwin
      working-directory: ${{prefix}}/bin
  env:
    ARGS:
      - -GNinja
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PREFIX="{{prefix}}"
      - -DZSTD_PROGRAMS_LINK_SHARED=ON # link `zstd` to `libzstd`
      - -DZSTD_BUILD_CONTRIB=ON
      - -DZSTD_LEGACY_SUPPORT=ON
      - -DZSTD_ZLIB_SUPPORT=ON
      - -DZSTD_LZMA_SUPPORT=ON
      - -DZSTD_LZ4_SUPPORT=ON
    darwin:
      ARGS:
        # Otherwise we get errors from clang
        - -DCMAKE_CXX_FLAGS="-std=c++11"

test:
  env:
    STRING: asdf123%!*
  script:
    - test $(echo "$STRING" | zstd  | zstd -d) = "$STRING"
    - test $(echo "$STRING" | pzstd | zstd -d) = "$STRING"
    - test $(echo "$STRING" | xz    | zstd -d) = "$STRING"
    - test $(echo "$STRING" | lz4   | zstd -d) = "$STRING"
    - test $(echo "$STRING" | gzip  | zstd -d) = "$STRING"
