{% set version = "3.1.0" %}

package:
  name: openssl_split
  version: {{ version }}

source:
  url: http://www.openssl.org/source/openssl-{{ version }}.tar.gz
  sha256: aaa925ad9828745c4cad9d9efeb273deca820f2cdcf2c3ac7d7c1212b7c497b4
  patches:
    # backport openssl/openssl#20556 as regression fix; can be dropped for v>3.1.0
    - 0001-OBJ_nid2obj-Return-UNDEF-object-instead-of-NULL.patch
    # backport openssl/openssl#20613 as regression fix; can be dropped for v>3.1.0
    - 0002-Fix-some-patches-related-to-error-exiting.patch

build:
  number: 2

requirements:
  build:
    - {{ compiler('c') }}
    - nasm               # [win]
    - make               # [unix]
    - perl *
  # Empty host section to ensure that this is identified as cb3
  host:

outputs:
  - name: openssl
    script: install_openssl.sh  # [unix]
    script: install_openssl.bat  # [win]
    build:
      no_link: lib/libcrypto.so.3.0  # [linux]
      no_link: lib/libcrypto.3.0.dylib  # [osx]
      run_exports:
        # openssl's versioning used to be X.Y.Z(rev), but is MAJOR.MINOR.PATCH since 3.0.0;
        # see https://www.openssl.org/policies/releasestrat.html
        - {{ pin_subpackage('openssl', max_pin='x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - make
        - perl *
      # Empty host section to ensure that this is identified as cb3
      # FIXME: this doesn't seem to be enough. We need a compiler in build
      # with `compiler` jinja used to not use legacy cb2 build==host
      host:
      run:
        - ca-certificates
        - ucrt             # [win]
    test:
      requires:
        - pkg-config
      commands:
        - copy NUL checksum.txt        # [win]
        - touch checksum.txt           # [unix]
        - $PREFIX/bin/openssl sha256 checksum.txt       # [unix]
        - '%LIBRARY_BIN%\openssl sha256 checksum.txt'   # [win]

        # test pkgconfig metadata
        - pkg-config --print-errors --exact-version "{{ version }}" openssl

  - name: libopenssl-static
    script: install_libopenssl-static.sh  # [unix]
    script: install_libopenssl-static.bat  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
      run:
        - {{ pin_subpackage('openssl', exact=True) }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libcrypto.a                   # [unix]
        - test -f ${PREFIX}/lib/libssl.a                      # [unix]
        - if exist %LIBRARY_PREFIX%\lib\libcrypto_static.lib (exit 0) else (exit 1)  # [win]
        - if exist %LIBRARY_PREFIX%\lib\libssl_static.lib (exit 0) else (exit 1)     # [win]

about:
  home: http://www.openssl.org/
  license_file: LICENSE.txt
  license: Apache-2.0
  license_family: Apache
  summary: OpenSSL is an open-source implementation of the SSL and TLS protocols
  dev_url: https://github.com/openssl/openssl
  doc_url: https://www.openssl.org/docs/man3.0/

extra:
  recipe-maintainers:
    - jakirkham
    - msarahan
    - ocefpaf
    - pelson
    - h-vetinari
  feedstock-name: openssl
