distributable:
  url: https://github.com/postgres/postgres/archive/refs/tags/REL_{{version.major}}_{{version.minor}}.tar.gz
  strip-components: 1

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

dependencies:
  openssl.org: ^1.0.1
  gnu.org/readline: '*'
  zlib.net: '*'
  lz4.org: '*'
  gnome.org/libxml2: '*'
  gnome.org/libxslt: '*'
  unicode.org: ^73

build:
  dependencies:
    freedesktop.org/pkg-config: '*'
    #gnu.org/gcc: '*'
    gnu.org/bison: '*'
    gnu.org/sed: '*'
    github.com/westes/flex: ^2.5.31
    perl.org: '*'
  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' ' ')"

    # disable sgml doc generation, since that seems to fail.
    # sorry all you sgml-heads out there
    sed -i 's|\([^\t]*sgml.*\)$|#\1|' GNUmakefile.in doc/src/Makefile

    ./configure $ARGS
    make --jobs {{ hw.concurrency }}
    make install-world
  env:
    CC: clang
    CXX: clang++
    LD: clang
    ARGS:
      - --prefix={{prefix}}
      - --with-ssl=openssl
      - --with-lz4
      - --with-libxml
      - --with-libxslt
    darwin:
      LDFLAGS:
        - -headerpad_max_install_names $LDFLAGS
    linux:
      CFLAGS:
        - -Wno-incompatible-function-pointer-types $CFLAGS

provides:
  - bin/clusterdb
  - bin/createdb
  - bin/dropdb
  - bin/dropuser
  - bin/ecpg
  - bin/initdb
  - bin/pg_archivecleanup
  - bin/pg_basebackup
  - bin/pg_config
  - bin/pg_controldata
  - bin/pg_ctl
  - bin/pg_dump
  - bin/pg_dumpall
  - bin/pg_isready
  - bin/pg_receivewal
  - bin/pg_recvlogical
  - bin/pg_resetwal
  - bin/pg_restore
  - bin/pg_rewind
  - bin/pg_test_fsync
  - bin/pg_test_timing
  - bin/pg_upgrade
  - bin/pg_waldump
  - bin/pgbench
  - bin/postgres
  - bin/psql
  - bin/reindexdb
  - bin/vacuumdb

test:
  script: |
    # While we'd love a good test like this, `initdb` doesn't run as root, and managing
    # all the environment passthrough with `sudo` is a nightmare.

    if test "{{ hw.platform }}" = "linux"; then
      pg_config --sharedir
      pg_config --libdir
      pg_config --pkglibdir
      pg_config --pkgincludedir
      pg_config --includedir-server
    else
      mkdir -p ./data

      initdb -D ./data
      pg_ctl -D ./data -l logfile start
      createdb test
      psql -c 'create table test (id int);' test
      dropdb test
      pg_ctl -D ./data stop

      rm -rf ./data
    fi
