app-id: com.blitterstudio.amiberry
runtime: org.freedesktop.Platform
runtime-version: "23.08"
sdk: org.freedesktop.Sdk
command: amiberry.sh
rename-icon: amiberry
copy-icon: true
finish-args:
  - --device=all
  # X11 + XShm access
  - --share=ipc
  # Wayland access
  - --socket=wayland
  - --socket=fallback-x11
  # Needs to talk to the network:
  - --share=network
  # Allow bluetooth (e.g. controllers)
  - --allow=bluetooth
  # Play sounds using PulseAudio
  - --socket=pulseaudio
  # Filesystem access
  - --filesystem=host

modules:
  - name: libmpeg2
    config-opts:
      - --disable-static
    rm-configure: true
    sources:
      - type: archive
        url: https://libmpeg2.sourceforge.net/files/libmpeg2-0.5.1.tar.gz
        sha256: dee22e893cb5fc2b2b6ebd60b88478ab8556cb3b93f9a0d7ce8f3b61851871d4
      - type: script
        dest-filename: autogen.sh
        commands:
          - autoreconf -vfi
    cleanup:
      - /bin
      - /include
      - /lib/pkgconfig
      - "*.la"
      - "*.a"

  - name: libserialport
    buildsystem: autotools
    sources:
      - type: git
        url: https://github.com/sigrokproject/libserialport
        tag: libserialport-0.1.1
        commit: 348a6d353af8ac142f68fbf9fe0f4d070448d945
    cleanup:
      - /include
      - "*.la"
      - "*.a"

  - name: portmidi
    buildsystem: cmake-ninja
    config-opts:
      - -DCMAKE_BUILD_TYPE=Release
    sources:
      - type: git
        url: https://github.com/PortMidi/PortMidi
        tag: v2.0.4
        commit: b808babecdc5d05205467dab5c1006c5ac0fdfd4
    cleanup:
      - /bin
      - /lib/pkgconfig
      - /include
      - '*.a'
      - '*.la'

  - name: amiberry
    buildsystem: cmake-ninja
    config-opts:
      - -DCMAKE_BUILD_TYPE=Release
    post-install:
      - install -Dp -m 755 amiberry /app/bin/amiberry
      - install -D -m644 -t /app/share/applications/ flatpak/${FLATPAK_ID}.desktop
      - install -D -m644 -t /app/share/metainfo/ flatpak/${FLATPAK_ID}.metainfo.xml
      - install -D -m755 -t /app/bin/ ./amiberry.sh
      - install -Dm644 flatpak/256x256.png /app/share/icons/hicolor/256x256/apps/amiberry.png
      - mkdir -p /app/data
      - cp -R abr /app/data
      - cp -R cdroms /app/data
      - cp -R conf /app/data
      - cp -R controllers /app/data
      - cp -R data /app/data
      - cp -R floppies /app/data
      - cp -R harddrives /app/data
      - cp -R inputrecordings /app/data
      - cp -R kickstarts /app/data
      - cp -R lha /app/data 
      - cp -R nvram /app/data
      - cp -R plugins /app/data
      - cp -R savestates /app/data
      - cp -R screenshots /app/data
      - cp -R whdboot /app/data

    sources:
      - type: git
        url: https://github.com/BlitterStudio/amiberry
        tag: flatpak-stable
        commit: db4e1210bcd4e89a462e2cd64896acf0546b4ee0

      - type: script
        dest-filename: amiberry.sh
        commands:
          - "if [ ! -e \"$XDG_DATA_HOME/data\" ]; then cp -R /app/data/* $XDG_DATA_HOME; fi; exec /app/bin/amiberry"
