{% set apr_ver = "1.7.0" %}
{% set apu_ver = "1.6.1" %}
{% set api_ver = "1.2.2" %}
{% set mirror = "http://www-us.apache.org/dist/" %}

package:
  name: apr
  version: {{ apr_ver }}

source:
  - url: {{ mirror }}/apr/apr-{{ apr_ver }}.tar.gz
    folder: apr
    sha256: 48e9dbf45ae3fdc7b491259ffb6ccf7d63049ffacbc1c0977cced095e4c2d5a2
    patches:
      - patches/osx-libapr-darwin20-hints.patch
      # backport of commit 866e1df from upstream
      - patches/cross-compile-apr-866e1df.patch
      - patches/cross-compile-osx-arm64-strerror.patch  # [osx and build_platform != target_platform]
  - url: {{ mirror }}/apr/apr-util-{{ apu_ver }}.tar.gz
    folder: apr-util
    sha256: b65e40713da57d004123b6319828be7f1273fbc6490e145874ee1177e112c459
  - url: {{ mirror }}/apr/apr-iconv-{{ api_ver }}.tar.gz
    folder: apr-iconv
    sha256: ce94c7722ede927ce1e5a368675ace17d96d60ff9b8918df216ee5c1298c6a5e
  - path: cmake/  # [win]

build:
  number: 5
  ignore_run_exports:                                           # [win]
    - expat                                                     # [win]
  skip: true  # [win and vc<14]

requirements:
  build:
    - {{ compiler('c') }}
    - cmake                                                     # [win]
    - ninja                                                     # [win]
    - libtool  # [not win]
    - make  # [unix]
  host:
    - expat                                                     # [win]
    - {{ compiler('c') }}  # [build_platform != target_platform]
  run:
    - libapr
    - libaprutil
    - libapriconv

outputs:
  - name: libapr
    version: {{ apr_ver }}
    build:
      run_exports:
        # https://abi-laboratory.pro/tracker/timeline/apr/
        # This is only on the basis of libapr.so
        - {{ pin_subpackage('libapr', max_pin='x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - make                                                  # [unix]
        - cmake                                                 # [win]
        - ninja                                                 # [win]
        - libtool  # [not win]
        - autoconf  # [unix]
        - automake  # [unix]
        - gettext  # [unix]
      host:
    script: install_libapr.sh                                   # [unix]
    script: install_libapr.bat                                  # [win]
    test:
      commands:
        - apr-1-config --help                                   # [unix]

        - if not exist %LIBRARY_INC%\\apr.h             exit 1  # [win]
        - if not exist %LIBRARY_BIN%\\libapr-1.dll      exit 1  # [win]
        - if not exist %LIBRARY_LIB%\\libapr-1.lib      exit 1  # [win]

        - test -f ${PREFIX}/include/apr-1/apr.h                 # [unix]
        - test -f ${PREFIX}/lib/libapr-1${SHLIB_EXT}            # [unix]

  - name: libaprutil
    version: {{ apu_ver }}
    build:
      run_exports:
        - {{ pin_subpackage('libaprutil', max_pin='x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - make                                                  # [unix]
        - cmake                                                 # [win]
        - ninja                                                 # [win]
        - libtool  # [not win]
      host:
        - expat
        - libapr
        - libapriconv
    script: install_libaprutil.sh                               # [unix]
    script: install_libaprutil.bat                              # [win]
    test:
      commands:
        - apu-1-config --help                                   # [unix]

        - if not exist %LIBRARY_INC%\\apu.h             exit 1  # [win]
        - if not exist %LIBRARY_BIN%\\libaprutil-1.dll  exit 1  # [win]
        - if not exist %LIBRARY_LIB%\\libaprutil-1.lib  exit 1  # [win]

        - test -f ${PREFIX}/include/apr-1/apu.h                 # [unix]
        - test -f ${PREFIX}/lib/libaprutil-1${SHLIB_EXT}        # [unix]

  - name: libapriconv
    version: {{ api_ver }}
    build:
      run_exports:
        - {{ pin_subpackage('libapriconv', max_pin='x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - make                                                  # [unix]
        - cmake                                                 # [win]
        - ninja                                                 # [win]
        - libtool  # [not win]
      host:
        - libapr
    script: install_libapriconv.sh                              # [unix]
    script: install_libapriconv.bat                             # [win]
    test:
      commands:
        - if not exist %LIBRARY_INC%\\apr_iconv.h       exit 1  # [win]
        - if not exist %LIBRARY_BIN%\\libapriconv-1.dll exit 1  # [win]
        - if not exist %LIBRARY_LIB%\\libapriconv-1.lib exit 1  # [win]
        - if not exist %LIBRARY_BIN%\\iconv\\utf-8.so   exit 1  # [win]
        - test -f ${PREFIX}/lib/libapriconv-1${SHLIB_EXT}       # [unix]

about:
  home: http://apr.apache.org/
  license: Apache-2.0
  license_family: Apache
  license_file: apr/LICENSE
  summary: Maintains a consistent API with predictable behaviour
  description: |
    Apache Portable Run-time libraries have been designed to provide a common
    interface to low level routines across any platform.The original goal of APR
    was to combine all code in Apache to one common code base.
  doc_url: https://apr.apache.org/docs/apr/1.6/index.html
  dev_url: https://svn.apache.org/viewvc/apr
  doc_source_url: https://github.com/apache/apr/tree/trunk/docs

extra:
  recipe-maintainers:
    - jakirkham
    - mingwandroid
    - nehaljwani
    - seanyen
