distributable:
  url: https://github.com/google/re2/archive/refs/tags/{{version.tag}}.tar.gz
  strip-components: 1

versions:
  github: google/re2

dependencies:
  abseil.io: ^20240116

build:
  dependencies:
    cmake.org: '*'
  script:
    # escaping. sigh
    - sed -i
      -e 's/\$(includedir)#/$(subst +brewing,,$(includedir))#/'
      -e 's/\$(libdir)#/$(subst +brewing,,\$(libdir))#/'
      -e "s/sed -i ''/sed -i/g"
      Makefile

    # Run this for pkg-config files
    - make common-install prefix={{prefix}}

    # Build and install static library
    - cmake -B build-static $ARGS
    - make --jobs={{ hw.concurrency }} -C build-static
    - make -C build-static install

    # Build and install shared library
    - cmake -B build-shared -DBUILD_SHARED_LIBS=ON $ARGS
    - make --jobs={{ hw.concurrency }} -C build-shared
    - make -C build-shared install
  env:
    ARGS:
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PREFIX={{prefix}}
      - -DRE2_BUILD_TESTING=OFF

test:
  dependencies:
    linux:
      gnu.org/gcc: '*' # version.h
  script:
    - run: c++ -std=c++20 $FIXTURE -lre2 -o test
      fixture:
        extname: cpp
        content: |
          #include <re2/re2.h>
          #include <assert.h>
          int main() {
            assert(!RE2::FullMatch("hello", "e"));
            assert(RE2::PartialMatch("hello", "e"));
            return 0;
          }
    - ./test
