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

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

source:
  fn: {{ name }}-{{ version }}.tar.gz
  url: https://github.com/{{ name }}/{{ name }}/archive/v{{ version }}.tar.gz
  sha256: 030644df4611007ff7dc962d981f390361e6c97a34e5cbc393ddfbe019ffe2c1
  patches:
    # https://github.com/lz4/lz4/pull/962
    - patches/0002-include-local-header-directory.patch  # [win]
    - patches/CVE-2021-3520.patch

build:
  number: 1

requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}  # [not win]
    - make  # [not win]
    - patch  # [unix]
    - m2-patch  # [win]
    - m2-gcc-libs  # [win]
  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  # [unix]

      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          # [unix]

  - name: lz4-c-static
    build:
      activate_in_script: true
    script: build_static.sh  # [unix]
    script: bld_static.bat  # [win]
    test:
      commands:
        - test -f ${PREFIX}/lib/liblz4.a      # [unix]
        - if not exist %LIBRARY_LIB%\\liblz4_static.lib exit 1  # [win]


about:
  home: https://www.lz4.org
  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
