distributable:
  url: https://mesa.freedesktop.org/archive/mesa-{{version}}.tar.xz
  strip-components: 1
versions:
  url: https://mesa.freedesktop.org/archive
  match: /mesa-\d+\.\d+\.\d+\.tar\.xz/
  strip:
    - /^mesa-/
    - /\.tar\.xz/
dependencies:
  libexpat.github.io: '*'
  x.org/x11: '*'
  x.org/xcb: '*'
  x.org/xdamage: '*'
  x.org/exts: '*'
  invisible-island.net/ncurses: '*'
  zlib.net: '*'
  x.org/xrandr: '*'
  darwin:
    gnu.org/gettext: '*'
  linux:
    elfutils.org: '*'
    khronos.org/glslang: '*'
    info-zip.org/zip: '*'
    dri.freedesktop.org: ^2.4.110
    intel.com/libva: '*'
    freedesktop.org/vdpau: '*'
    x.org/xfixes: '*'
    x.org/xshmfence: '*'
    x.org/xv: '*'
    x.org/xxf86vm: '*'
    llvm.org: '*'
    github.com/lm-sensors/lm-sensors: '*'
    wayland.freedesktop.org: '*'
    wayland.freedesktop.org/protocols: '*'
build:
  dependencies:
    gnu.org/bison: '*'
    mesonbuild.com: '*'
    ninja-build.org: '*'
    freedesktop.org/pkg-config: '*'
    pygments.org: '*'
    python.org: ~3.11
    x.org/protocol: '*'
    github.com/westes/flex: '*'
    linux:
      curl.se: '*'
  script:
    - curl -L "$Mako" | tar zxf -
    - curl -L "$MarkupSafe" | tar zxf -
    - run: |
        python -m venv venv
        source venv/bin/activate
        python setup.py install
        deactivate
        export PYTHONPATH=$PWD/venv/lib/python3.11/site-packages/Mako-1.2.4-py3.11.egg:$PYTHONPATH
        export PATH=$PWD/venv/bin/mako-render:$PATH
      working-directory: Mako-1.2.4
    - run: |
        python -m venv venv
        source venv/bin/activate
        python setup.py install
        deactivate
        cd venv/lib/python3.11/site-packages
        EGG="$(echo MarkupSafe*)"
        export PYTHONPATH=$PWD/$EGG:$PYTHONPATH
      working-directory: MarkupSafe-2.1.2
    - meson setup build $MESON_ARGS
    - meson compile -C build --verbose
    - meson install -C build
  env:
    Mako: https://files.pythonhosted.org/packages/05/5f/2ba6e026d33a0e6ddc1dddf9958677f76f5f80c236bd65309d280b166d3e/Mako-1.2.4.tar.gz
    MarkupSafe: https://files.pythonhosted.org/packages/95/7e/68018b70268fb4a2a605e2be44ab7b4dd7ce7808adae6c5ef32e34f4b55a/MarkupSafe-2.1.2.tar.gz
    PYTHONPATH: '{{deps.pygments.org.prefix}}/venv/lib/python3.11/site-packages:$PYTHONPATH'
    MESON_ARGS:
      - --libdir=lib
      - --prefix={{prefix}}
      - --buildtype=release
      - --wrap-mode=nofallback
    darwin:
      MESON_ARGS:
        - -Dosmesa=true
        - -Dglx=xlib
    linux:
      MESON_ARGS:
        - -Dplatforms=x11,wayland
        - -Dglx=auto
        - -Ddri3=enabled
        - -Dgallium-drivers=lima
        - -Dgallium-omx=disabled
        - -Dvulkan-drivers=
        - -Degl=enabled
        - -Dgbm=enabled
        - -Dopengl=true
        - -Dgles1=enabled
        - -Dgles2=enabled
        - -Dvalgrind=disabled
        - -Dtools=drm-shim,etnaviv,freedreno,glsl,nir,nouveau,lima
      # https://gitlab.freedesktop.org/mesa/mesa/-/issues/8003#note_1781344
      LDFLAGS: $LDFLAGS -Wl,--undefined-version
test:
  dependencies:
    freedesktop.org/pkg-config: '*'
    linux:
      gnu.org/gcc: '*' # archlinux doesn't provide libgcc
      llvm.org: '*'
  env:
    FLAGS:
      - -lX11
      - -lXext
      - -lm
    darwin:
      FLAGS:
        - -lGl
    linux:
      FLAGS:
        - '{{prefix}}/lib/libGL.so.1'
  script:
    - clang glxgears.c -o gears $FLAGS
    - pkg-config --modversion gl | grep {{version}}
