distributable:
  url: https://github.com/OSGeo/PROJ/releases/download/{{version}}/proj-{{version}}.tar.gz
  strip-components: 1

versions:
  github: OSGeo/PROJ

provides:
  - bin/proj

dependencies:
  simplesystems.org/libtiff: '*'
  sqlite.org: '*'
  curl.se: '*'

build:
  dependencies:
    cmake.org: '*'
    freedesktop.org/pkg-config: '*'
    gnu.org/libtool: '*'
    gnu.org/wget: '*'
    gnu.org/coreutils: '*'
    sqlite.org: '*'
  script: |
    cmake -S . -B build $ARGS $SHARED_LIB_ARGS
    cmake --build build
    cmake --install build

    cmake -S . -B static $ARGS $STATIC_LIB_ARGS
    cmake --build static
    mv static/lib/libproj.a "{{prefix}}/lib/"

    # The datum grid files are required to support datum shifting
    wget https://download.osgeo.org/proj/proj-data-1.13.tar.gz

    expected_checksum='f1e5e42ba15426d01d1970be727af77ac9b88c472215497a5a433d0a16dd105b  proj-data-1.13.tar.gz'
    actual_checksum="$(sha256sum proj-data-1.13.tar.gz)"
    test "$expected_checksum" = "$actual_checksum"
    mkdir proj-data
    tar -xzf proj-data-1.13.tar.gz -C proj-data
    mkdir -p "{{prefix}}/share/proj"
    mv proj-data/* "{{prefix}}/share/proj/"
  env:
    ARGS:
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PREFIX={{prefix}}
    SHARED_LIB_ARGS:
      - -DCMAKE_INSTALL_RPATH={{prefix}}
    STATIC_LIB_ARGS:
      - -DBUILD_SHARED_LIBS=OFF

test:
  script: |
    output="$(proj +proj=poly +ellps=clrk66 -r test.txt)"
    test "$(cat match.txt)" = "$output"
