{% set pkg_name = "lz4-c" %}
{% set name = "lz4" %}
{% set version = "1.10.0" %}

package:
  name: {{ pkg_name }}
  version: {{ version }}

source:
  url: https://github.com/{{ name }}/{{ name }}/archive/v{{ version }}.tar.gz
  sha256: 537512904744b35e232912055ccf8ec66d768639ff3abe5788d90d792ec5f48b

build:
  number: 1

requirements:
  build:
    - {{ compiler('c') }}
    - {{ stdlib("c") }}
    - {{ compiler('cxx') }}  # [not win]
    - make  # [not win]
    - cmake  # [win]
    - ninja  # [win]
    - patch  # [unix]
  host:
  run:

outputs:
  - name: lz4-c
    build:
      # https://abi-laboratory.pro/index.php?view=timeline&l=lz4
      run_exports:
        - {{ pin_subpackage(pkg_name, max_pin='x.x') }}
    test:
      requires:
        - pkg-config
        - cmake  # [win]
        - ninja  # [win]
      files:
        - test_shared_cmake
      commands:
        - lz4 -h
        - lz4c -h    # [unix]
        - lz4cat -h  # [unix]
        - unlz4 -h   # [unix]

        - test -f ${PREFIX}/include/lz4.h       # [unix]
        - test -f ${PREFIX}/include/lz4hc.h     # [unix]
        - test -f ${PREFIX}/include/lz4frame.h  # [unix]

        - if not exist %LIBRARY_INC%\\lz4.h exit 1       # [win]
        - if not exist %LIBRARY_INC%\\lz4hc.h exit 1     # [win]
        - if not exist %LIBRARY_INC%\\lz4frame.h exit 1  # [win]

        - test ! -f ${PREFIX}/lib/liblz4.a      # [unix]
        - test -f ${PREFIX}/lib/liblz4.dylib  # [osx]
        - test -f ${PREFIX}/lib/liblz4.so     # [linux]

        - if not exist %LIBRARY_BIN%\\liblz4.dll exit 1         # [win]
        - if not exist %LIBRARY_LIB%\\liblz4.lib exit 1         # [win]
        - if exist %LIBRARY_LIB%\\liblz4_static.lib exit 1  # [win]

        - test -f ${PREFIX}/lib/pkgconfig/liblz4.pc  # [unix]
        - pkg-config --cflags --libs liblz4

        - pushd test_shared_cmake  # [win]
        - cmake -GNinja .          # [win]
        - popd                     # [win]


  - name: lz4-c-static
    build:
      activate_in_script: true
      always_include_files:
        - Library/lib/cmake/lz4  # [win]
    script: build_static.sh      # [unix]
    script: bld_static.bat       # [win]
    requirements:
      build:
        - {{ compiler('c') }}  # [win]
        - {{ stdlib("c") }}    # [win]
        - cmake                # [win]
        - ninja                # [win]
      host:
        - {{ pin_subpackage('lz4-c', exact=True) }}
      run:
        - {{ pin_subpackage('lz4-c', exact=True) }}
    test:
      files:
        - test_static_cmake
      requires:
        - cmake  # [win]
        - ninja  # [win]
      commands:
        - test -f ${PREFIX}/lib/liblz4.a      # [unix]
        - if not exist %LIBRARY_LIB%\lz4_static.lib exit 1  # [win]

        - pushd test_static_cmake  # [win]
        - cmake -GNinja .          # [win]
        - popd                     # [win]

about:
  home: https://www.lz4.org
  dev_url: https://github.com/lz4/lz4
  license: BSD-2-Clause
  license_file: lib/LICENSE
  summary: Extremely Fast Compression algorithm
  description: |
    LZ4 is lossless compression algorithm, providing compression speed at 400
    MB/s per core (0.16 Bytes/cycle). It features an extremely fast decoder,
    with speed in multiple GB/s per core (0.71 Bytes/cycle). A high compression
    derivative, called LZ4_HC, is available, trading customizable CPU time for
    compression ratio. LZ4 library is provided as open source software using a
    BSD license.

extra:
  recipe-maintainers:
    - mingwandroid
    - rmax
    - wesm
    - xhochy
