{% set version = "1.5.7" %}

package:
  name: zstd-split
  version: {{ version }}

source:
  url: https://github.com/facebook/zstd/archive/v{{ version }}.tar.gz
  sha256: 37d7284556b20954e56e1ca85b80226768902e2edabd3b649e9e72c0c9012ee3

build:
  number: 2

outputs:
  - name: zstd
    script: install.sh  # [unix]
    script: install.bat  # [win]
    build:
      run_exports:
        # pretty bad removal of symbols in every other micro release:
        #   https://abi-laboratory.pro/tracker/timeline/zstd/
        #  Working smoothly since 1.4.x
        - {{ pin_subpackage('zstd', max_pin='x.x') }}
    requirements:
      build:
        - {{ stdlib('c') }}
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - make  # [unix]
        - cmake-no-system
      host:
        - zlib
    test:
      requires:
        # cmake needs compiler to be able to run package detection, see
        # https://discourse.cmake.org/t/questions-about-find-package-cli-msvc/6194
        - {{ compiler('c') }}
        - cmake
        - make  # [unix]
        - pkg-config
      files:
        - cf_test/
      commands:
        # shared libraries
        - test -f ${PREFIX}/lib/libzstd.so                  # [linux]
        - test -f ${PREFIX}/lib/libzstd.dylib               # [osx]
        - if not exist %LIBRARY_BIN%\zstd.dll exit 1        # [win]
        - if not exist %LIBRARY_LIB%\zstd.lib exit 1        # [win]
        # duplicated for packages depending on lib-prefixed files
        - if not exist %LIBRARY_BIN%\libzstd.dll exit 1     # [win]
        - if not exist %LIBRARY_LIB%\libzstd.lib exit 1     # [win]

        # absence of static libraries
        - test ! -f ${PREFIX}/lib/libzstd.a                 # [unix]
        - if exist %LIBRARY_LIB%\zstd_static.lib exit 1     # [win]
        - if exist %LIBRARY_LIB%\libzstd_static.lib exit 1  # [win]

        # headers
        - test -f ${PREFIX}/include/zstd.h                  # [unix]
        - if not exist %LIBRARY_INC%\zstd.h exit 1          # [win]

        # CLI
        - zstd -be -i5

        # pkgconfig
        - test -f ${PREFIX}/lib/pkgconfig/libzstd.pc              # [unix]
        - if not exist %LIBRARY_LIB%\pkgconfig\libzstd.pc exit 1  # [win]
        - export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig            # [unix]
        - set "PKG_CONFIG_PATH=%LIBRARY_LIB%\pkgconfig"           # [win]
        - pkg-config --cflags libzstd

        # cmake
        - cd cf_test
        - cmake $CMAKE_ARGS .   # [unix and (build_platform == target_platform)]
        - cmake %CMAKE_ARGS% .  # [win]

  - name: zstd-static
    script: install.sh  # [unix]
    script: install.bat  # [win]
    requirements:
      build:
        - {{ stdlib('c') }}
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - make  # [unix]
        - cmake-no-system
      host:
        - {{ pin_subpackage('zstd', exact=True) }}
      run:
        - {{ pin_subpackage('zstd', exact=True) }}
    test:
      requires:
        - {{ compiler('c') }}
        - {{ stdlib('c') }}
        - cmake
        - make   # [unix]
        - pkg-config
      files:
        - cf_test/
      commands:
        # static libraries
        - test -f ${PREFIX}/lib/libzstd.a                   # [unix]
        - if not exist %LIBRARY_LIB%\zstd_static.lib exit 1  # [win]

        # headers
        - test -f ${PREFIX}/include/zstd.h                  # [unix]
        - if not exist %LIBRARY_INC%\zstd.h exit 1          # [win]

        # CLI
        - zstd -be -i5

        # pkgconfig
        - test -f ${PREFIX}/lib/pkgconfig/libzstd.pc              # [unix]
        - if not exist %LIBRARY_LIB%\pkgconfig\libzstd.pc exit 1  # [win]
        - export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig            # [unix]
        - set "PKG_CONFIG_PATH=%LIBRARY_LIB%\pkgconfig"           # [win]
        - pkg-config --cflags libzstd

        # cmake
        - cd cf_test
        - cmake $CMAKE_ARGS .   # [build_platform == target_platform and unix]
        - cmake %CMAKE_ARGS% .  # [win]

about:
  home: http://www.zstd.net
  license: BSD-3-Clause
  license_file: LICENSE
  summary: Zstandard - Fast real-time compression algorithm
  description: |
    Zstandard is a real-time compression algorithm, providing high compression
    ratios. It offers a very wide range of compression / speed trade-off, while
    being backed by a very fast decoder. It also offers a special mode for
    small data, called dictionary compression, and can create dictionaries from
    any sample set. Zstandard library is provided as open source software using
    a BSD license.
  doc_url: https://facebook.github.io/zstd/zstd_manual.html
  dev_url: https://github.com/facebook/zstd

extra:
  feedstock-name: zstd
  recipe-maintainers:
    - JohanMabille
    - rmax
    - msarahan
    - xhochy
    - hmaarrfk
