{% set version = "13.3" %}
{% 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: 3cd9454fa8c7a6255b6743b767700925ead1b9ab0d7a0f9dcb1151010f8eb4a1
  patches:
    - patches/0001-fix-win-zlib-name.patch
    - patches/0002-disable-new-dtags.patch
    - patches/fix_gss_win64.patch  # [win64]
    - patches/0004-fix-windows-openssl-links-for-openssl-1.1.1.patch
    - patches/fix_gssapi_setenv_win.patch  # [win]
    - patches/fix_auth_setenv_win.patch  # [win]

build:
  number: 0
  skip: true  # [win and float(vc) < 14]

requirements:
  build:
    - gnuconfig  # [unix]
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - {{ compiler('fortran') }}  # [not win]
    - make                       # [unix]
  host:
    - m2-bison         # [win]
    - m2-diffutils     # [win]
    - m2-flex          # [win]
    # perl pinned to older version due to issues with @INC not being recursive or something like that.
    - perl             # [win]
    - posix            # [win]
    - libxml2
    - libxslt 1.1.*
    - krb5
    - openssl
    - msinttypes  # [win and float(vc) < 14]
    - openssl
    - readline         # [not win]
    - zlib
    - vc  # [win]
    - libuuid         # [not win]
    - tzcode          # [not win]
    - tzdata          # [not win]
  run:
    - krb5
    - openssl
    - readline        # [not win]
    - tzcode          # [not win]
    - tzdata          # [not win]

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]
        - tzcode          # [not win]
        - tzdata          # [not win]
        - zlib
        - libxml2
        - msinttypes       # [win and float(vc) < 14]
        - {{ pin_subpackage('libpq', exact=True) }}
      run:
        - {{ pin_subpackage('libpq', exact=True) }}
        - krb5
        - openssl
        - readline         # [not win]
        - tzcode          # [not win]
        - tzdata          # [not win]
        - zlib
    test:
      commands:
        - postgres --help
    script: install_db.sh  # [unix]
    script: install_db.bat  # [win]
    about:
      summary: PostgreSQL is a powerful, open source object-relational database system.

  - name: postgresql-plpython
    build:
      run_exports:
        - {{ pin_subpackage('postgresql-plpython') }}
    requirements:
      build:
        - python                                 # [build_platform != target_platform]
        - cross-python_{{ target_platform }}     # [build_platform != target_platform]
        # 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     # [not osx]
        - openssl
        - readline         # [not win]
        - zlib
        - {{ pin_subpackage('postgresql', exact=True) }}
        - python
        - libxml2
        - libxslt 1.1.*
        - msinttypes  # [win and py27]
        - vc  # [win]
        - libuuid         # [not win]
      run:
        - {{ pin_subpackage('postgresql', exact=True) }}
        - python
        - krb5
        - openssl
        - readline         # [not win]
        - zlib
    script: install_plpython.sh  # [unix]
    test:
      commands:
    about:
      summary: The plpythonu postgresql extension

  - 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]
        - tzcode          # [not win]
        - tzdata          # [not win]
        - zlib
        - msinttypes       # [win and float(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
  summary: multi-ouput recipe for postgresql

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