{% set version = "3.3" %}
{% set am_version = "1.15" %} # keep synchronized with build.sh
{% set posix = 'm2-' if win else '' %}
{% set native = 'm2w64-' if win else '' %}

package:
  name: libffi
  version: {{ version }}

source:
  url: https://github.com/libffi/libffi/archive/v{{ version }}.tar.gz
  sha256: 3f2f86094f5cf4c36cfe850d2fe029d01f5c2c2296619407c8ba0d8207da9a6b
  patches:  # [win]
    # Windows-specific:
    - 0001-x86-MSVC-does-not-support-Complex-type.patch                # [win]
    - 0002-Don-t-define-FFI_COMPLEX_TYPEDEF-ifndef-FFI_TARGET_H.patch  # [win]

build:
  number: 2
  run_exports:
    # good history: https://abi-laboratory.pro/tracker/timeline/libffi/
    - {{ pin_subpackage('libffi', "x.x") }}

requirements:
  build:
    - autotools_clang_conda              # [win]
    - make                               # [unix]
    - autoconf                           # [unix]
    - libtool                            # [unix]
    - patch                              # [unix]
    - automake                           # [unix]
    - {{ posix }}texinfo
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
  host:
  run:

test:
  requires:
    - llvm-tools  # [win]
    - m2-grep     # [win]
  commands:
    - test -e $PREFIX/lib/libffi${SHLIB_EXT}                       # [not win]
    - test -e $PREFIX/lib/libffi.a                                 # [not win]
    - test -e $PREFIX/include/ffi.h                                # [not win]
    - test -e $PREFIX/include/ffitarget.h                          # [not win]
    - if not exist %LIBRARY_PREFIX%/bin/ffi-7.dll exit /b 1        # [win]
    - if not exist %LIBRARY_PREFIX%/lib/libffi.lib exit /b 1       # [win]
    - if not exist %LIBRARY_PREFIX%/lib/ffi.lib exit /b 1       # [win]
    - if not exist %LIBRARY_PREFIX%/include/ffi.h exit /b 1        # [win]
    - if not exist %LIBRARY_PREFIX%/include/ffitarget.h exit /b 1  # [win]
    - llvm-nm %LIBRARY_PREFIX%/lib/libffi.lib | grep "__imp_ffi_type_void"        # [win]

about:
  home: https://sourceware.org/libffi/
  license: MIT
  license_file: LICENSE
  summary: A Portable Foreign Function Interface Library.

  description: |
    The libffi library provides a portable, high level programming interface
    to various calling conventions. This allows a programmer to call any
    function specified by a call interface description at run-time.
  doc_url: https://sourceware.org/libffi/
  dev_url: https://github.com/libffi/libffi

extra:
  recipe-maintainers:
    - stefan-balke
    - scopatz
    - isuruf
