distributable:
  url: https://ftp.postgresql.org/pub/source/v{{version.raw}}/postgresql-{{version.raw}}.tar.bz2
  strip-components: 1

versions:
  url: https://ftp.postgresql.org/pub/source
  match: /v\d+\.\d+(\.\d+)?\//
  strip:
    - /^v/
    - /\/$/

dependencies:
  kerberos.org: '*'
  openssl.org: ^1.1
  zlib.net: ^1
  unicode.org: ^71
  linux:
    gnu.org/readline: '*'

build:
  dependencies:
    freedesktop.org/pkg-config: ^0
  script: |
    # remove `-w`` from CFLAGS, because it causes build to fail, ironically.
    # `./configure` *specifically* checks that certain warnings are emitted.
    export CFLAGS="$(echo $CFLAGS | tr ' ' '\n' | sed -e '/^-w$/d' | tr '\n' ' ')"
    ./configure $ARGS

    make --jobs {{ hw.concurrency }}
    make -C src/bin install $DIRS
    make -C src/include install $DIRS
    make -C src/interfaces install $DIRS
    make -C src/common install $DIRS
    make -C src/port install $DIRS
    make -C doc install $DIRS
  env:
    ARGS:
      - --disable-debug
      - --prefix={{prefix}}
      - --with-gssapi
      - --with-openssl
      - --libdir={{prefix}}/lib
      - --includedir={{prefix}}/include
    DIRS:
      - libdir={{prefix}}/lib
      - includedir={{prefix}}/include
      - pkgincludedir={{prefix}}/include/postgresql
      - includedir_server={{prefix}}/include/postgresql/server
      - includedir_internal={{prefix}}/include/postgresql/internal

test:
  dependencies:
  script: |
    cc libpq.c -lpq -o libpqtest
    test "$(./libpqtest)" = 'Connection to database attempted and failed'
