sdk-extensions:
  #- org.freedesktop.Sdk.Extension.dotnet6   # Needed for Ryujinx - Removed, check if it's not breaking something else
  finish-args:
  #- --env=QT_QPA_PLATFORM=xcb #not sure if this will break something
  
  # pcsx2-qt needs QT6, maybe others, here until every qt emulator will support qt6 (not yuzu atm)
  # from: https://github.com/flathub/org.profex_xrd.Profex

  # - name: qt6-core5compat
  #   buildsystem: cmake-ninja
  #   builddir: true
  #   sources:
  #     - type: archive
  #       url: https://download.qt.io/official_releases/qt/6.2/6.2.4/submodules/qt5compat-everywhere-src-6.2.4.tar.xz
  #       sha256: 5de2b9e25bf7de161fbb88ecdd468ed1788bc899392fc05ed80aa590ebb352fa
  #       x-checker-data:
  #         type: html
  #         url: https://download.qt.io/official_releases/qt/6.2/
  #         version-pattern: '>([\d\.-]*)/<'
  #         url-template: https://download.qt.io/official_releases/qt/6.2/$version/submodules/qt5compat-everywhere-src-$version.tar.xz
  #   post-install:
  #     - mkdir -p /app/lib/mkspecs
  #     - cp -R /app/mkspecs/* /app/lib/mkspecs/
  #     - ln -fsr ${FLATPAK_DEST}/lib/${FLATPAK_ARCH}-linux-gnu/libQt*.so* -t ${FLATPAK_DEST}/lib/
  #     - sed -i 's/\\([0-9]\\+\\.[0-9]\\+\\)\\.[0-9]\\+ ${_Qt6.*_FIND_VERSION_EXACT}/\\1/'
  #       ${FLATPAK_DEST}/lib/${FLATPAK_ARCH}-linux-gnu/cmake/Qt6*/Qt6*Config.cmake
  #     - sed -e 's@PATHS \"${CMAKE_CURRENT_LIST_DIR}/..\" NO_DEFAULT_PATH@PATHS \"${CMAKE_CURRENT_LIST_DIR}/..\"
  #       \"/usr/lib/${CMAKE_CXX_LIBRARY_ARCHITECTURE}/cmake/\" NO_DEFAULT_PATH@' -i
  #       ${FLATPAK_DEST}/lib/${FLATPAK_ARCH}-linux-gnu/cmake/Qt6*/Qt6*Config.cmake
  #     - sed -e 's@\\($$QT_MODULE_BIN_BASE\\)@\\1 '${FLATPAK_DEST}'/bin @' -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #     - sed -e 's@\\($$QT_MODULE_INCLUDE_BASE \\)@\\1'${FLATPAK_DEST}'/include @'
  #       -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #     - sed -e 's@$$QT_MODULE_INCLUDE_BASE/@'${FLATPAK_DEST}'/include/@g' -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #     - sed -e 's@$$QT_MODULE_LIB_BASE@'${FLATPAK_DEST}'/lib@g' -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #   cleanup:
  #     - /app/mkspecs

  # XEMU: libglu removed due to a certificate issue, check libglu module for more info
  # - name: libglu
  #   buildsystem: meson
  #   cleanup:
  #     - /include
  #     - /lib/debug
  #     - /lib/pkgconfig
  #     - /lib/*.a
  #   sources:
  #     - type: archive
  #       url: http://mesa.freedesktop.org/archive/glu/glu-9.0.2.tar.xz
  #       sha256: 6e7280ff585c6a1d9dfcdf2fca489251634b3377bfc33c29e4002466a38d02d4
  #       x-checker-data:
  #         type: anitya
  #         project-id: 13518
  #         stable-only: true
  #         url-template: http://mesa.freedesktop.org/archive/glu/glu-$version.tar.xz

    # Duckstation - START
  # https://github.com/flathub/org.duckstation.DuckStation
  # Disabled until we completely switch to QT6

  # - name: duckstation
  #   buildsystem: cmake-ninja
  #   no-make-install: true
  #   builddir: true
  #   config-opts:
  #     - -DCMAKE_BUILD_TYPE=RelWithDebInfo
  #     - -DUSE_EGL=ON
  #     - -DUSE_SDL2=ON
  #     - -DUSE_WAYLAND=ON
  #     - -DUSE_X11=ON
  #     - -DUSE_DRMKMS=ON
  #     - -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
  #   post-install:
  #     - install -m755 bin/duckstation-qt /app/bin
  #     - cp -r ../data/* bin/translations /app/bin
  #   sources:
  #     - type: git
  #       url: https://github.com/stenzek/duckstation.git
  #       commit: 6f709468601183083b8581d4952aaba7baf77084
  #       # Cloning dep/msvc/qt is only necessary for Windows
  #       disable-submodules: true

  # Duckstation - END

  # Duckstation-DontUpdate - START
  # Old version moved to QT6 so it's either this or AppImage
  # But AppImage is a single one that keep getting updated at the same link so the sha (that's mandatory) will break the build
  # So yeah we're stuck with this for a while

  # - name: duckstation-DontUpdate
  #   buildsystem: cmake-ninja
  #   no-make-install: true
  #   builddir: true
  #   config-opts:
  #     - -DCMAKE_BUILD_TYPE=Release
  #     - -DUSE_EGL=ON
  #     - -DUSE_SDL2=ON
  #     - -DUSE_WAYLAND=ON
  #     - -DUSE_X11=ON
  #     - -DUSE_DRMKMS=ON
  #     - -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
  #   post-install:
  #     - install -m 755 -t /app/bin/ bin/duckstation-nogui bin/duckstation-qt
  #     - |-
  #       for px in 16 32 48 64 128 256; do
  #         install -Dm644 ../extras/icons/icon-${px}px.png /app/share/icons/hicolor/${px}x${px}/apps/org.duckstation.DuckStation.png
  #       done
  #     - cp -r ../data/* bin/translations /app/bin
  #   sources:
  #     - type: git
  #       url: https://github.com/stenzek/duckstation.git
  #       commit: 3fb61865e505ba639609fbf16cb8bdf5c66e020c

  # Duckstation-DontUpdate - END

  # Ryujinx - START
  # https://github.com/flathub/org.ryujinx.Ryujinx

  - name: Ryujinx
    buildsystem: simple
    build-options:
      no-debuginfo: true
      no-debuginfo-compression: true
      strip: false
      arch:
        x86_64:
          env:
            RUNTIME: linux-x64
      env:
        PKG_CONFIG_PATH: /app/lib/pkgconfig:/app/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
        DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
        DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 'true'
        RYUJINX_VERSION: 1.1.1014
        RYUJINX_TARGET_RELEASE_CHANNEL_OWNER: flathub
        RYUJINX_TARGET_RELEASE_CHANNEL_REPO: org.ryujinx.Ryujinx
        RYUJINX_TARGET_RELEASE_CHANNEL_NAME: master
    build-commands:
    - |
      export PATH=$PATH:/run/build/Ryujinx/dotnet-sdk
      export RYUJINX_GIT_SHORT_HASH=$(git rev-parse --short HEAD)
      export RUNTIME_FRAMEWORK_VERSION=$(find nuget-sources -name 'microsoft.netcore.app.host.linux-x64.*' | grep -oP '(\d.\d.\d+.nupkg)' | grep -oP '(\d.\d.\d+)')
      sed -r --in-place "s/\%\%RYUJINX_BUILD_VERSION\%\%/$RYUJINX_VERSION/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_BUILD_GIT_HASH\%\%/$RYUJINX_GIT_SHORT_HASH/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_NAME\%\%/$RYUJINX_TARGET_RELEASE_CHANNEL_NAME/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_OWNER\%\%/$RYUJINX_TARGET_RELEASE_CHANNEL_OWNER/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_REPO\%\%/$RYUJINX_TARGET_RELEASE_CHANNEL_REPO/g;" src/Ryujinx.Common/ReleaseInformation.cs
      mkdir -p /app/bin
      dotnet publish -c Release -r $RUNTIME /p:DebugType=embedded src/Ryujinx /p:Version=$RYUJINX_VERSION /p:SourceRevisionId=$RYUJINX_GIT_SHORT_HASH /p:ExtraDefineConstants="DISABLE_UPDATER%2CFORCE_EXTERNAL_BASE_DIR" /p:RuntimeFrameworkVersion=$RUNTIME_FRAMEWORK_VERSION --self-contained --source nuget-sources
      if [ $? -ne 0 ]; then
          exit 1;
      fi;
      cp -r --remove-destination /run/build/Ryujinx/src/Ryujinx/bin/Release/net7.0/$RUNTIME/publish/* /app/bin/
      chmod +x /app/bin/Ryujinx.sh
      mkdir -p /app/lib/ffmpeg
      ln -s /usr/lib/x86_64-linux-gnu/libX11.so.6 /app/lib/libX11.so
      install -Dm755 ryujinx-wrapper /app/bin/ryujinx-wrapper
      install -Dm644 distribution/misc/Logo.svg /app/share/icons/hicolor/scalable/apps/ryujinx.svg
    sources:
    - type: archive
      only-arches:
      - x86_64
      dest: dotnet-sdk
      url: https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.401/dotnet-sdk-7.0.401-linux-x64.tar.gz
      sha256: 4634fa4da7ae4e3dadb83e320a87fb26f0cb12a7ca02bf9f10e6c3c1c91d645c
      x-checker-data:
        type: rotating-url
        url: https://aka.ms/dotnet/7.0/dotnet-sdk-linux-x64.tar.gz
        pattern: https://dotnetcli.azureedge.net/dotnet/Sdk/^([\d\.a-z-]+)$/dotnet-sdk-^([\d\.a-z-]+)$-linux-x64.tar.gz
    - rd-submodules/ryujinx/nuget_sources.json
    - type: git
      url: https://github.com/Ryujinx/Ryujinx.git
      commit: 7ccff037e87f82f3461f3e1422235e29800eaa2f
    - type: file
      path: rd-submodules/ryujinx/ryujinx-wrapper

  # Ryujinx - END

  # Needed from ES-DE 2.1.0+
  - name: libpoppler-glib
    buildsystem: cmake-ninja
    config-opts:
      - -DENABLE_BOOST=OFF
    sources:
      - type: archive
        # original link not working, found a mirror
        url: https://poppler.freedesktop.org/poppler-22.11.0.tar.xz
        #url: https://gitlab.freedesktop.org/poppler/poppler/-/archive/poppler-22.11.0/poppler-poppler-22.11.0.tar.bz2
        sha256: 093ba9844ed774285517361c15e21a31ba4df278a499263d4403cca74f2da828
    cleanup:
      - /lib/pkgconfig
      - /include
      - '*.a'
      - '*.la'


  # dependency of: XEMU, MelonDS (4.7.0)
  - name: libslirp
    buildsystem: meson
    cleanup:
      - /include
    sources:
      - type: archive
        url: https://gitlab.freedesktop.org/slirp/libslirp/-/archive/v4.8.0/libslirp-v4.8.0.tar.gz
        sha256: 2a98852e65666db313481943e7a1997abff0183bd9bea80caec1b5da89fda28c
        x-checker-data:
          type: anitya
          project-id: 96796
          stable-only: true
          url-template: https://gitlab.freedesktop.org/slirp/libslirp/-/archive/v$version/libslirp-v$version.tar.gz

  # dependency of: CEMU (1.0.26), DOLPHIN (1.0.27)
  - name: libusb
    config-opts:
      - --disable-static
    cleanup:
      - /include
      - /lib/*.la
      - /lib/pkgconfig
    sources:
      - type: archive
        url: https://github.com/libusb/libusb/releases/download/v1.0.27/libusb-1.0.27.tar.bz2
        sha256: ffaa41d741a8a3bee244ac8e54a72ea05bf2879663c098c82fc5757853441575
        x-checker-data:
          type: anitya
          project-id: 1749
          stable-only: true
          url-template: https://github.com/libusb/libusb/releases/download/v$version/libusb-$version.tar.bz2

    # Dolphin - START
  # why from source: AppImage not provided, only Flatpak
  # https://github.com/flathub/org.DolphinEmu.dolphin-emu
  # WHEN UPADTING: remember to update rd-submodules/dolphin contents

  - name: xdg-screensaver-shim
    buildsystem: meson
    sources:
      - type: archive
        url: https://github.com/Unrud/xdg-screensaver-shim/archive/0.0.2.tar.gz
        sha256: 0ed2a69fe6ee6cbffd2fe16f85116db737f17fb1e79bfb812d893cf15c728399

  - name: dolphin-emu
    buildsystem: cmake-ninja
    config-opts:
      - -DCMAKE_BUILD_TYPE=Release
      - -DENABLE_ALSA=OFF
      - -DENABLE_SDL=ON
      - -DENABLE_EVDEV=ON
      - -DDISTRIBUTOR=Flathub
    cleanup:
      - /share/man
    post-install:
      - install -D -t ${FLATPAK_DEST}/bin/ dolphin-emu-wrapper
      - sed -i -e 's/viewBox="0 0 1024.02 571.29"/viewBox="0 -285.645 1024 1024" width="2048"
        height="2048"/g' /app/share/icons/hicolor/scalable/apps/dolphin-emu.svg
    sources:
      - type: git
        # Sometimes Dolphin or its submodules clone are failing in https so it must done in ssh
        # fatal: remote transport reported error
        # url: ssh://git@github.com/dolphin-emu/dolphin.git
        url: https://github.com/dolphin-emu/dolphin.git
        commit: cc3ff347b437fd80f3a2880d1bbc7ba2d5f191f4
        # x-checker-data:
        #   type: json
        #   url: https://dolphin-emu.org/update/latest/beta
        #   commit-query: .hash
        #   version-query: .shortrev
        #   timestamp-query: .date
        #   is-main-source: true
      # detects whether dolphin is running in a flatpak sandbox
      # and makes it use xdg directories if it is.
      # prevents dolphin from attempting to write conf files
      # in non-writable paths, typically happens when a user
      # has leftover files from a previous non-flatpak install
      - type: patch
        path: rd-submodules/dolphin/detectflatpak.patch
      # version strings must match exactly for online multiplayer
      - type: patch
        path: rd-submodules/dolphin/nodirtyversion.patch
      - type: script
        commands:
          - |
            for i in {0..9}; do
              test -S $XDG_RUNTIME_DIR/discord-ipc-$i ||
                ln -sf {app/com.discordapp.Discord,$XDG_RUNTIME_DIR}/discord-ipc-$i;
            done
            dolphin-emu "$@"
        dest-filename: dolphin-emu-wrapper

  - name: universal_dynamic_input
    buildsystem: simple
    build-commands:
      - mkdir -p ${FLATPAK_DEST}/retrodeck/extras/DynamicInputTextures
      - cp -rf * ${FLATPAK_DEST}/retrodeck/extras/DynamicInputTextures/
    sources:
      - type: git
        url: https://github.com/Venomalia/UniversalDynamicInput.git
        commit: UNIVERSALDYNAMICINPUTCOMMITPLACEHOLDER

  # Dolphin - END

  # SOLARUS - START
  # why from source: they only provide a snap
  # https://github.com/flathub/org.solarus_games.solarus.Launcher

  - name: luajit
    no-autogen: true
    cleanup:
      - /bin
      - /lib/*.a
      - /include
      - /lib/pkgconfig
      - /share/man
    sources:
      - type: archive
        url: https://luajit.org/download/LuaJIT-2.0.5.tar.gz
        sha256: 874b1f8297c697821f561f9b73b57ffd419ed8f4278c82e05b48806d30c1e979
      - type: shell
        commands:
          - sed -i 's|/usr/local|/app|' ./Makefile

  - name: libmodplug
    cleanup:
      - /include
    sources:
      - type: archive
        url: https://download.sourceforge.net/project/modplug-xmms/libmodplug/0.8.9.0/libmodplug-0.8.9.0.tar.gz
        sha512: 880e10154fd367ee24ace53ca7e32a5c1fee7dfff1f934e6499944c12779427da63e2f55f8d6ce25db0a42a5b4424053bf64305b31dbfc4ef6a8909924d655fd

  - name: physfs
    buildsystem: cmake-ninja
    config-opts:
      - -DPHYSFS_BUILD_TEST=OFF
    sources:
      - type: archive
        url: https://icculus.org/physfs/downloads/physfs-3.0.2.tar.bz2
        sha256: 304df76206d633df5360e738b138c94e82ccf086e50ba84f456d3f8432f9f863
        size: 194888
        x-checker-data:
          type: anitya
          project-id: 3631
          url-template: https://icculus.org/physfs/downloads/physfs-$version.tar.bz2

  - name: solarus
    buildsystem: cmake-ninja
    builddir: true
    config-opts:
      - -DSOLARUS_GUI=OFF
    sources:
      - type: git
        url: https://gitlab.com/solarus-games/solarus.git
        tag: v1.6.5
        commit: 3aec70b0556a8d7aed7903d1a3e4d9a18c5d1649

  # SOLARUS - END