{% set version = "1.3.2" %}
{% set major,minor,patch = version.split('.') %}

package:
  name: libwebp-base
  version: {{ version }}

source:
  url: https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-{{ version }}.tar.gz
  sha256: 2a499607df669e40258e53d0ade8035ba4ec0175244869d1025d460562aa09b4

build:
  number: 0
  run_exports:
    # https://abi-laboratory.pro/?view=timeline&l=libwebp
    - {{ pin_subpackage('libwebp-base') }}

requirements:
  build:
    - {{ compiler('c') }}
    - cmake     # [win]
    - libtool   # [not win]
    - m2-patch  # [win]
    - make      # [not win]
    - ninja     # [win]
  run_constrained:
    # 1.1 is when libwebp-base was split from libwebp
    - libwebp {{ version }}

{% set libraries = ["libwebp", "libwebpdemux", "libwebpmux", "libwebpdecoder", "libsharpyuv"] %}
{% set headers = ["decode.h", "demux.h", "encode.h", "mux_types.h", "mux.h", "types.h"] %}
{% set binaries = ["cwebp", "dwebp", "gif2webp", "img2webp", "webpinfo", "webpmux"] %}

test:
  commands:
    {% for each_lib in libraries %}
      # shared libraries
      - test -f $PREFIX/lib/{{ each_lib }}.so                   # [linux]
      - test -f $PREFIX/lib/{{ each_lib }}.dylib                # [osx]
      - if not exist %LIBRARY_LIB%\{{ each_lib }}.lib exit 1    # [win]
      - if not exist %LIBRARY_BIN%\{{ each_lib }}.dll exit 1    # [win]

      # absence of static libraries; removed in v1.2.3
      # should not be packaged in conda-forge, see also CFEP-18
      - test ! -f $PREFIX/lib/{{ each_lib }}.a                  # [unix]

      # config files; unix currently doesn't have CMake, only pkgconfig
      - test $PREFIX/pkgconfig/{{ each_lib }}.pc                # [unix]
      - if not exist %LIBRARY_PREFIX%\WebP\cmake\WebPConfig.cmake exit 1    # [win]
    {% endfor %}

    # headers
    {% for each_header in headers %}
      - test -f $PREFIX/include/webp/{{ each_header }} || (echo "{{ each_header }} not found" && exit 1)    # [unix]
      - if not exist %LIBRARY_INC%\webp\{{ each_header }} exit 1                                            # [win]
    {% endfor %}

    # All binaries should be excluded from libwebp-base. Various binaries
    # link against libtiff, libpng, libgif, so they must be separated to prevent
    # circular imports https://github.com/conda-forge/staged-recipes/pull/11101
    {% for each_bin in binaries %}
      - test ! -f $PREFIX/bin/{{ each_bin }}                 # [unix]
      - if exist %LIBRARY_BIN%\{{ each_bin }}.exe exit 1     # [win]
    {% endfor %}

about:
  home: https://developers.google.com/speed/webp
  license: BSD-3-Clause
  license_family: BSD
  license_file: COPYING
  summary: WebP image library
  description: |
    WebP is a method of lossy and lossless compression that can be used on a
    large variety of photographic, translucent and graphical images found on the
    web. The degree of lossy compression is adjustable so a user can choose the
    trade-off between file size and image quality.
    libwebp-base provides the headers and shared libraries. For cwebp and dwep,
    binaries install libwebp.
  doc_url: https://developers.google.com/speed/webp/docs/using
  dev_url: https://chromium.googlesource.com/webm/libwebp

extra:
  recipe-maintainers:
    - carterbox
    - dschreij
    - ocefpaf
