{% set version = "4.3.0" %}

package:
  name: libtiff
  version: {{ version }}

source:
  url: https://download.osgeo.org/libtiff/tiff-{{ version }}.tar.gz
  sha256: 0e46e5acb087ce7d1ac53cf4f56a09b221537fc86dfc5daaad1c2e89e1b37ac8
  patches:
    # It seems that a recent patch in tifffile 4.1 may have broken
    # binary compatibility on windows.
    # https://gitlab.com/libtiff/libtiff/issues/173
    # https://github.com/python-pillow/Pillow/issues/4237
    - patches/use_unix_io.patch
    # This patch is included in >4.3.0
    # remove automake and autoconf when removing this patch
    # also remember to remove the `autoreconf` command in the `build.sh`
    # script
    - patches/243_osx_buidl_failing_patch.patch

build:
  number: 0
  skip: true  # [win and vc<14]
  # Does a very good job of maintaining compatibility.
  #    https://abi-laboratory.pro/tracker/timeline/libtiff/
  run_exports:
    - {{ pin_subpackage('libtiff', max_pin='x') }}
  missing_dso_whitelist:
    # Only used by libtiff,bin/tiffgt (a viewer), which is ok.
    - /opt/X11/lib/libGL.1.dylib
    - /opt/X11/lib/libglut.3.dylib

requirements:
  build:
    - libtool  # [unix]
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - cmake  # [win]
    - ninja  # [win]
    - make      # [unix]
    # automake and autoconf are only necessary for patch 243
    - automake  # [unix]
    - autoconf  # [unix]
  host:
    - zlib
    - jpeg
    - xz
    - zstd
    - libwebp-base  # [linux or osx]
  run:
    - zlib
    - jpeg
    - xz
    - zstd
    - libwebp-base  # [linux or osx]

test:
  downstreams:
    - pillow >=8
    # Without the version specifyer, then it tries to download opencv2???
    - opencv >=4
    - tifffile
  commands:
    - test -f ${PREFIX}/lib/libtiff.a  # [not win]
    - test -f ${PREFIX}/lib/libtiffxx.a  # [not win]
    - test -f ${PREFIX}/lib/libtiff{{ SHLIB_EXT }}  # [not win]
    - test -f ${PREFIX}/lib/libtiffxx{{ SHLIB_EXT }}  # [not win]
    - if not exist %PREFIX%\\Library\\bin\\tiff.dll exit 1  # [win]
    - if not exist %PREFIX%\\Library\\bin\\tiffxx.dll exit 1  # [win]
    - if not exist %PREFIX%\\Library\\bin\\libtiff.dll exit 1  # [win]
    - if not exist %PREFIX%\\Library\\bin\\libtiffxx.dll exit 1  # [win]

about:
  home: http://www.libtiff.org/
  license: HPND
  license_file: COPYRIGHT
  summary: Support for the Tag Image File Format (TIFF).
  description: |
    This software provides support for the Tag Image File Format (TIFF), a
    widely used format for storing image data.
  doc_url: http://www.libtiff.org/document.html

extra:
  recipe-maintainers:
    - jakirkham
    - mingwandroid
    - msarahan
    - ocefpaf
    - stuarteberg
    - hmaarrfk
