{% set version = "3.6.3" %}

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

source:
  url: https://github.com/openssl/openssl/releases/download/openssl-{{ version }}/openssl-{{ version }}.tar.gz
  sha256: 243a86649cf6f23eeb6a2ff2456e09e5d77dd9018a54d3d96b0c6bdd6ba6c7f1

build:
  number: 0

requirements:
  build:
    - {{ compiler('c') }}
    - {{ stdlib('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:
      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') }}
        - {{ stdlib('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
    test:
      requires:
        - pkg-config
        - ripgrep
      commands:
        - copy NUL checksum.txt        # [win]
        - touch checksum.txt           # [unix]
        - $PREFIX/bin/openssl sha256 checksum.txt       # [unix]
        - '%LIBRARY_BIN%\openssl sha256 checksum.txt'   # [win]
        - if not exist "%SSL_CERT_FILE%" exit 1         # [win]
        - if not exist "%LIBRARY_INC%"\\openssl\\applink.c exit 1    # [win]

        # test pkgconfig metadata
        - pkg-config --print-errors --exact-version "{{ version }}" openssl
        # test prefix is set as well (see #155)
        - if [[ "$(pkg-config --variable=prefix openssl)" == "" ]]; then exit 1; fi     # [unix]

        # ensure (de)activation scripts for bash-on-win do not contain crlf line endings;
        # ripgrep will return exit code 1 if no match is found, which is what we want after
        # filtering to the carriage-return character that shouldn't be there.
        {% for task in ["activate", "deactivate"] %}
        - type %CONDA_PREFIX%\etc\conda\{{ task }}.d\openssl_{{ task }}-win.sh | rg \r & if ERRORLEVEL ==1 (exit 0) else (exit 1)  # [win]
        # do not use %ERRORLEVEL% or !ERRORLEVEL!, but ERRORLEVEL, c.f.
        # https://devblogs.microsoft.com/oldnewthing/20080926-00/?p=20743;
        # while `if ... NEQ 1 exit 1` would be nicer, NEQ is incompatible with
        # using bare ERRORLEVEL, see https://stackoverflow.com/a/74148543
        {% endfor %}

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

about:
  home: https://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://docs.openssl.org/master/

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