app-id: su.xash.Engine.Compat.i386
runtime: org.freedesktop.Platform
runtime-version: &runtime-version '23.08'
x-gl-version: &gl-version '1.4'
x-gl-versions: &gl-versions 23.08;1.4
sdk: org.freedesktop.Sdk
command: run.sh
separate-locales: false
sdk-extensions:
  - org.freedesktop.Sdk.Compat.i386
  - org.freedesktop.Sdk.Extension.toolchain-i386

finish-args:
  - --share=ipc
  - --socket=wayland
  - --socket=x11
  - --socket=pulseaudio
  - --share=network
  # Steam library path on Ubuntu
  - --filesystem=~/.steam/steam/steamapps/common:ro
  # ... on SteamOS 3
  - --filesystem=~/.local/share/Steam/steamapps/common:ro
  # ... on Steam Flatpak
  - --filesystem=~/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/common:ro
  # allow talking with Discord for mods
  # TODO: enable when somebody asks for it
  # - --filesystem=xdg-run/app/com.discordapp.Discord:create
  - --device=all
  - --allow=multiarch
  - --allow=devel
  - --allow=bluetooth

add-extensions:
  org.freedesktop.Platform.Compat.i386:
    directory: lib/i386-linux-gnu
    version: *runtime-version

  org.freedesktop.Platform.Compat.i386.Debug:
    directory: lib/debug/lib/i386-linux-gnu
    version: *runtime-version
    no-autodownload: true

  org.freedesktop.Platform.GL32:
    directory: lib/i386-linux-gnu/GL
    version: *gl-version
    versions: *gl-versions
    subdirectories: true
    autodelete: false
    add-ld-path: lib
    merge-dirs: vulkan/icd.d;glvnd/egl_vendor.d;OpenCL/vendors;lib/dri;lib/d3d;vulkan/explicit_layer.d;vulkan/implicit_layer.d
    download-if: active-gl-driver
    enable-if: active-gl-driver

x-compat-i386-opts: &compat-i386-opts
  prepend-pkg-config-path: /app/lib32/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig
  ldflags: -L/app/lib32
  prepend-path: /usr/lib/sdk/toolchain-i386/bin
  env:
    CC: i686-unknown-linux-gnu-gcc
    CXX: i686-unknown-linux-gnu-g++
  libdir: /app/lib32

modules:
  - name: bundle-setup
    buildsystem: simple
    build-commands:
      - |
        mkdir -p /app/lib/i386-linux-gnu
        mkdir -p /app/lib/debug/lib/i386-linux-gnu
        mkdir -p /app/lib/i386-linux-gnu/GL
        mkdir -p /app/etc
        echo "/app/lib32" > /app/etc/ld.so.conf
        echo "/app/lib/i386-linux-gnu" >> /app/etc/ld.so.conf
  - name: xash
    buildsystem: simple
    build-options: *compat-i386-opts
    build-commands:
# HACKHACK: removed --enable-lto because it causes linker errors in Flatpak build
      - |
        python waf configure -T release --enable-all-renderers --enable-packaging --prefix=/app --libdir=/app/lib32 --bindir=/app/lib32/xash3d
        python waf build
        python waf install --destdir=/
        mkdir -p /app/bin
        mkdir -p /app/share/icons/hicolor/256x256/apps/
        mkdir -p /app/share/applications
        install -m 0755 3rdparty/vgui_support/vgui-dev/lib/vgui.so /app/lib32/xash3d/vgui.so
        install -m 0755 scripts/flatpak/run.sh /app/bin/run.sh
        install -m 0644 game_launch/icon-xash-material.png /app/share/icons/hicolor/256x256/apps/su.xash.Engine.Compat.i386.png
        install -m 0644 scripts/flatpak/su.xash.Engine.Compat.i386.desktop /app/share/applications/su.xash.Engine.Compat.i386.desktop
    sources:
    - type: dir
      path: ../../
