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

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

source:
  url: http://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-{{ version }}.tar.gz
  sha256: 7bf5a8a28cc69bcfa8cb214f2c3095703c6b73ac5fba4d5480c205331d9494df
  patches:
    - patches/0001-match-naming-convention-used-by-nmake-also-for-windo.patch  # [win]
    - patches/0002-use-standard-location-for-cmake-config-files.patch          # [win]

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

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

{% set libraries = ["libwebp", "libwebpdemux", "libwebpmux", "libwebpdecoder"] %}
{% 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%\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_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
