{% set version = "2.1.12" %}

package:
  name: libevent
  version: {{ version }}

source:
  fn: libevent-{{ version }}.tar.gz
  url: https://github.com/libevent/libevent/archive/release-{{ version }}-stable.tar.gz
  sha256: 7180a979aaa7000e1264da484f712d403fcf7679b1e9212c4e3d09f5c93efc24
  patches:
    - 0001-Fix-destination-for-DLLs-lib-bin.patch
    - patches/0002-openssl3.patch

build:
  number: 1
  run_exports:
    # https://abi-laboratory.pro/tracker/timeline/libevent/
    - {{ pin_subpackage('libevent', max_pin='x.x.x') }}

requirements:
  build:
    - pkg-config  # [unix]
    - autoconf    # [unix]
    - automake    # [unix]
    - libtool     # [unix]
    - patch       # [unix]
    - make        # [unix]
    - libtool     # [unix]
    - cmake
    - m2-patch    # [win]
    - {{ compiler('c') }}
  host:
    - openssl {{ openssl }}
  run:
    - openssl 3.*

test:
  requires:
    - python 2.7  # [win and vc<14]
    - python 3.8  # [not (win and vc<14)]

  source_files:
    - event_rpcgen.py
    - test/

  commands:
    # Check for headers.
    - test -d "${PREFIX}/include/event2"  # [unix]
    - if not exist %LIBRARY_INC%\event2 exit 1  # [win]

    # Check for libraries.
    {% set libs = [
        "libevent",
        "libevent_core",
        "libevent_extra",
        "libevent_openssl",
        "libevent_pthreads"
    ] %}
    {% set libs_win = [
        "event",
        "event_core",
        "event_extra",
    ] %}

    {% for each_lib in libs %}
    - test ! -f "${PREFIX}/lib/{{ each_lib }}.a"             # [unix]
    - test -f "${PREFIX}/lib/{{ each_lib }}.dylib"         # [osx]
    - test -f "${PREFIX}/lib/{{ each_lib }}.so"            # [linux]
    {% endfor %}

    {% for each_lib in libs_win %}
    - if not exist "%LIBRARY_PREFIX%/lib/{{ each_lib }}.lib" exit 1  # [win]
    - if not exist "%LIBRARY_PREFIX%/bin/{{ each_lib }}.dll" exit 1  # [win]
    {% endfor %}

    {% set pkgconfigs = [
        "libevent",
        "libevent_openssl",
        "libevent_pthreads"
    ] %}

    # Check for pkg-config files.
    {% for each_pkgconfig in pkgconfigs %}
    - test -f "${PREFIX}/lib/pkgconfig/{{ each_pkgconfig }}.pc"  # [unix]
    {% endfor %}

    # Run included Python script.
    - python event_rpcgen.py test/regress.rpc test/regress.gen.h test/regress.gen.c

about:
  home: https://libevent.org/
  license: BSD-3-Clause
  license_family: BSD
  license_file: LICENSE
  description: |
    The libevent API provides a mechanism to execute a callback function when
    a specific event occurs on a file descriptor or after a timeout has been
    reached. Furthermore, libevent also supports callbacks due to signals or
    regular timeouts.
  summary: An event notification library.
  doc_url: http://www.wangafu.net/~nickm/libevent-2.1/doxygen/html/
  dev_url: https://github.com/libevent/libevent

extra:
  recipe-maintainers:
    - jakirkham

  skip-lints:
    - http_url
