{% set version = "12.2" %}
{% set sha256 = "ad1dcc4c4fc500786b745635a9e1eba950195ce20b8913f50345bb7d5369b5de" %}
{% set libpqver = '.'.join(("5", version.split('.')[0])) %}

package:
  name: postgresql-split
  version: {{ version }}

source:
  url: https://ftp.postgresql.org/pub/source/v{{ version }}/postgresql-{{ version }}.tar.bz2
  sha256: {{ sha256 }}
  patches:
    - 0001-fix-win-zlib-name.patch
    - 0002-disable-new-dtags.patch
    - 0003-Parameterize-krb5-files-location-as-per-ARCH.patch
    - 0004-fix-windows-openssl-links-for-openssl-1.1.1.patch

build:
  number: 0

requirements:
  build:
    - {{ compiler('c') }}
    - m2-bison         # [win]
    - m2-diffutils     # [win]
    - m2-flex          # [win]
    - perl             # [win]
    - posix            # [win]
    - make             # [unix]
  host:
    - krb5
    - openssl
    - readline         # [not win]
    - zlib
    - msinttypes       # [win and vc<14]

outputs:
  - name: postgresql
    build:
      run_exports:
        - {{ pin_subpackage('libpq') }}
    requirements:
      build:
        # solely for sake of lining up vc versions and other runtimes
        - {{ compiler('c') }}
        - perl                 # [win]
        - make             # [unix]
      host:
        # these are here for sake of run_exports taking effect
        - krb5
        - openssl
        - readline         # [not win]
        - zlib
        - msinttypes       # [win and vc<14]
        - {{ pin_subpackage('libpq', exact=True) }}
      run:
        - {{ pin_subpackage('libpq', exact=True) }}
    test:
      commands:
        - postgres --help
        - conda inspect linkages postgresql  # [not win]
        - conda inspect objects postgresql  # [osx]
    script: install_db.sh   # [unix
    script: install_db.bat  # [win]
    about:
      summary: PostgreSQL is a powerful, open source object-relational database system.

  - name: libpq
    build:
      run_exports:
        - {{ pin_subpackage('libpq') }}
    requirements:
      build:
        # solely for sake of lining up vc versions and other runtimes
        - {{ compiler('c') }}
        - perl                 # [win]
        - make             # [unix]
      host:
        # these are here for sake of run_exports taking effect
        - krb5
        - openssl
        - readline         # [not win]
        - zlib
        - msinttypes       # [win and vc<14]
    script: install_runtime.sh   # [unix]
    script: install_runtime.bat  # [win]
    test:
      commands:
        - pg_config
        - test -f $PREFIX/lib/libpq.so.{{ libpqver }}      # [linux]
        - test -f $PREFIX/lib/libpq.so.5                   # [linux]
        - test -f $PREFIX/lib/libpq.so                     # [linux]
        - test -f $PREFIX/lib/libpq.{{ libpqver }}.dylib   # [osx]
        - test -f $PREFIX/lib/libpq.5.dylib                # [osx]
        - test -f $PREFIX/lib/libpq.dylib                  # [osx]
        - IF NOT EXIST %LIBRARY_BIN%\libpq.dll EXIT 1      # [win]
        - IF NOT EXIST %LIBRARY_BIN%\pg_config.exe EXIT 1  # [win]
    about:
      summary: The postgres runtime libraries and utilities (not the server itself)

about:
  home: http://www.postgresql.org/
  license: PostgreSQL
  license_file: COPYRIGHT

extra:
  recipe-maintainers:
    - gillins
    - msarahan
    - ocefpaf
    - mariusvniekerk
