From e8812b1d66344fa26bbeda95c32aeedefbc0b3a0 Mon Sep 17 00:00:00 2001
From: TheEvilSkeleton <theevilskeleton@riseup.net>
Date: Fri, 27 Aug 2021 20:16:41 -0400
Subject: [PATCH] Initial Tenacity Flatpak

Closes https://github.com/tenacityteam/tenacity/issues/493

Signed-off-by: TheEvilSkeleton <theevilskeleton@riseup.net>
---
 .github/workflows/flatpak.yml                 |  25 ++
 .gitignore                                    |   3 +
 .gitmodules                                   |   3 +
 packaging/flatpak/deps/lame-3.100.json        |  38 +++
 packaging/flatpak/deps/suil.json              |  29 +++
 packaging/flatpak/org.tenacity.Tenacity.json  | 218 ++++++++++++++++++
 .../flatpak/patches/audacity-suil-fix.patch   |  13 ++
 packaging/flatpak/shared-modules              |   1 +
 8 files changed, 330 insertions(+)
 create mode 100644 .github/workflows/flatpak.yml
 create mode 100644 packaging/flatpak/deps/lame-3.100.json
 create mode 100644 packaging/flatpak/deps/suil.json
 create mode 100644 packaging/flatpak/org.tenacity.Tenacity.json
 create mode 100644 packaging/flatpak/patches/audacity-suil-fix.patch
 create mode 160000 packaging/flatpak/shared-modules

diff --git a/.github/workflows/flatpak.yml b/.github/workflows/flatpak.yml
new file mode 100644
index 000000000..a7c117e40
--- /dev/null
+++ b/.github/workflows/flatpak.yml
@@ -0,0 +1,25 @@
+name: Packaging
+on:
+  push:
+    branches: [master]
+  pull_request:
+jobs:
+  flatpak:
+    name: "Flatpak"
+    runs-on: ubuntu-latest
+    container:
+      image: bilelmoussaoui/flatpak-github-actions:gnome-40
+      options: --privileged
+    strategy:
+      matrix:
+        arch: [x86_64, aarch64]
+      fail-fast: false
+    steps:
+    - uses: actions/checkout@v2
+      with:
+        submodules: true
+    - uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v3
+      with:
+        bundle: tenacity.flatpak
+        manifest-path: packaging/flatpak/org.tenacity.Tenacity.json
+        cache-key: flatpak-builder-${{ github.sha }}
diff --git a/.gitignore b/.gitignore
index 639ee51d1..ca58ea661 100644
--- a/.gitignore
+++ b/.gitignore
@@ -216,3 +216,6 @@ win/xaudacity.ico
 .vscode/
 
 vcpkg_installed
+
+# Flatpak
+!packaging/**
diff --git a/.gitmodules b/.gitmodules
index a71b1a47c..4b85e334c 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -2,3 +2,6 @@
 	path = vcpkg
 	url = https://github.com/tenacityteam/vcpkg.git
 	branch = tenacity
+[submodule "packaging/flatpak/shared-modules"]
+	path = packaging/flatpak/shared-modules
+	url = https://github.com/flathub/shared-modules.git
diff --git a/packaging/flatpak/deps/lame-3.100.json b/packaging/flatpak/deps/lame-3.100.json
new file mode 100644
index 000000000..4c132866f
--- /dev/null
+++ b/packaging/flatpak/deps/lame-3.100.json
@@ -0,0 +1,38 @@
+{
+  "name": "lame",
+  "rm-configure": true,
+  "config-opts": [
+    "--disable-static"
+  ],
+  "sources": [
+    {
+      "type": "archive",
+      "url": "https://downloads.sourceforge.net/lame/lame-3.100.tar.gz",
+      "sha256": "ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e"
+    },
+    {
+      "type": "patch",
+      "path": "../shared-modules/lame/lame-msse.patch"
+    },
+    {
+      "type": "patch",
+      "path": "../shared-modules/lame/lame-tinfo.patch",
+      "strip-components": 0
+    },
+    {
+      "type": "script",
+      "dest-filename": "autogen.sh",
+      "commands": [
+        "autoreconf -vfi"
+      ]
+    }
+  ],
+  "cleanup": [
+    "/bin",
+    "/include",
+    "/lib/pkgconfig",
+    "/share/doc",
+    "/share/man",
+    "*.la"
+  ]
+}
diff --git a/packaging/flatpak/deps/suil.json b/packaging/flatpak/deps/suil.json
new file mode 100644
index 000000000..9b4f16527
--- /dev/null
+++ b/packaging/flatpak/deps/suil.json
@@ -0,0 +1,29 @@
+{
+      "name": "suil",
+      "buildsystem": "simple",
+      "build-commands": [
+        "python3 ./waf configure --prefix=/app",
+        "python3 ./waf build -j $FLATPAK_BUILDER_N_JOBS",
+        "python3 ./waf install"
+      ],
+      "cleanup": [
+        "/include",
+        "/lib/pkgconfig"
+      ],
+      "sources": [
+        {
+          "type": "archive",
+          "url": "http://download.drobilla.net/suil-0.10.10.tar.bz2",
+          "sha256": "750f08e6b7dc941a5e694c484aab02f69af5aa90edcc9fb2ffb4fb45f1574bfb"
+        }
+      ],
+      "post-install": [
+        "install -Dm644 -t /app/share/licenses/suil COPYING"
+      ],
+      "cleanup": [
+        "/bin",
+        "/etc",
+        "/include",
+        "/share/man"
+      ]
+}
diff --git a/packaging/flatpak/org.tenacity.Tenacity.json b/packaging/flatpak/org.tenacity.Tenacity.json
new file mode 100644
index 000000000..910a222e1
--- /dev/null
+++ b/packaging/flatpak/org.tenacity.Tenacity.json
@@ -0,0 +1,218 @@
+{
+  "app-id": "org.tenacityaudio.Tenacity",
+  "runtime": "org.gnome.Platform",
+  "runtime-version": "40",
+  "sdk": "org.gnome.Sdk",
+  "command": "tenacity",
+  "rename-desktop-file": "tenacity.desktop",
+  "rename-icon": "tenacity",
+  "rename-appdata-file": "tenacity.metainfo.xml",
+  "finish-args": [
+    "--share=ipc",
+    "--socket=x11",
+    "--socket=pulseaudio",
+    "--filesystem=xdg-run/pipewire-0",
+    "--system-talk-name=org.freedesktop.RealtimeKit1",
+    "--device=all",
+    "--filesystem=host",
+    "--env=ALSA_CONFIG_PATH=",
+    "--env=LADSPA_PATH=/app/extensions/Plugins/ladspa",
+    "--env=LV2_PATH=/app/extensions/Plugins/lv2",
+    "--env=VST_PATH=/app/extensions/Plugins/lxvst"
+  ],
+  "add-extensions": {
+    "org.freedesktop.LinuxAudio.Plugins": {
+      "directory": "extensions/Plugins",
+      "version": "20.08",
+      "add-ld-path": "lib",
+      "merge-dirs": "ladspa;lv2;lxvst",
+      "subdirectories": true,
+      "no-autodownload": true
+    }
+  },
+  "cleanup": [
+    "/include",
+    "/lib/pkgconfig",
+    "/share/aclocal",
+    "/share/man",
+    "*.la",
+    "*.a"
+  ],
+  "modules": [
+    {
+      "name": "wxwidgets",
+      "rm-configure": true,
+      "config-opts": [
+        "--with-libpng",
+        "--with-zlib",
+        "--with-cxx=17",
+        "--disable-sdltest",
+        "--disable-webview",
+        "--disable-webviewwebkit",
+        "--disable-ribbon",
+        "--disable-propgrid",
+        "--disable-richtext",
+        "--with-expat=builtin",
+        "--with-libiconv=/usr"
+      ],
+      "cleanup": [
+        "/share/bakefile"
+      ],
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/wxWidgets/wxWidgets",
+          "tag": "v3.1.5",
+          "commit": "9c0a8be1dc32063d91ed1901fd5fcd54f4f955a1"
+        }
+      ]
+    },
+    "deps/lame-3.100.json",
+    {
+      "name": "libid3tag",
+      "buildsystem": "cmake-ninja",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/tenacityteam/libid3tag.git",
+          "tag": "0.16.1",
+          "commit": "1cc101e90dda1fb6e8cc57a0c707a3305bf674f9"
+        }
+      ]
+    },
+    "shared-modules/libmad/libmad.json",
+    "shared-modules/linux-audio/jack2.json",
+    "shared-modules/linux-audio/lv2.json",
+    "shared-modules/linux-audio/lilv.json",
+    "deps/suil.json",
+    {
+      "name": "portaudio",
+      "buildsystem": "cmake-ninja",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/PortAudio/portaudio.git",
+          "tag": "v19.7.0",
+          "commit": "147dd722548358763a8b649b3e4b41dfffbcfbb6"
+        }
+      ]
+    },
+    {
+      "name": "portsmf",
+      "buildsystem": "cmake-ninja",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/tenacityteam/portsmf.git",
+          "tag": "239",
+          "commit": "951b636f7d0cba370d483a91f1897c71f3d98530"
+        }
+      ]
+    },
+    {
+      "name": "portmidi-mixxxdj",
+      "buildsystem": "cmake-ninja",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/mixxxdj/portmidi.git",
+          "tag": "236",
+          "commit": "fda97c3be2baf10438574d10bb2a6b8b4f1140c4"
+        }
+      ]
+    },
+    {
+      "name": "soxr",
+      "buildsystem": "cmake-ninja",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/chirlu/soxr.git",
+          "tag": "0.1.3",
+          "commit": "945b592b70470e29f917f4de89b4281fbbd540c0"
+        }
+      ]
+    },
+    {
+      "name": "libsbsms",
+      "buildsystem": "cmake-ninja",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/claytonotey/libsbsms.git",
+          "tag": "2.3.0",
+          "commit": "e99cd7e6c6367e476577be34d2fdbe2023904d7e"
+        }
+      ]
+    },
+    {
+      "name": "vamp-plugin-sdk",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://github.com/c4dm/vamp-plugin-sdk.git",
+          "tag": "vamp-plugin-sdk-v2.10",
+          "commit": "67adfc2bf9486912a0fce5123cf54360ea2678bc"
+        }
+      ],
+      "cleanup": [
+        "/bin"
+      ]
+    },
+    {
+      "name": "soundtouch",
+      "sources": [
+        {
+          "type": "git",
+          "url": "https://gitlab.com/soundtouch/soundtouch.git",
+          "tag": "2.3.0",
+          "commit": "c65afe49f697fcea87d9a134870c8d115d7700cc"
+        }
+      ]
+    },
+    {
+      "name": "twolame",
+      "sources": [
+        {
+          "type": "archive",
+          "url": "https://downloads.sourceforge.net/twolame/twolame-0.4.0.tar.gz",
+          "sha256": "cc35424f6019a88c6f52570b63e1baf50f62963a3eac52a03a800bb070d7c87d"
+        }
+      ]
+    },
+    {
+      "name": "tenacity",
+      "buildsystem": "cmake-ninja",
+      "builddir": true,
+      "config-opts": [
+        "-DCMAKE_BUILD_TYPE=RelWithDebInfo",
+        "-DWX_CONFIG=/app/bin/wx-config"
+      ],
+      "post-install": [
+        "install -Dm644 ../help/tenacity.metainfo.xml -t /app/share/metainfo",
+        "install -d /app/extensions/Plugins"
+      ],
+      "cleanup": [
+        "/share/tenacity/include",
+        "/share/audacity/include",
+        "/share/pixmaps"
+      ],
+      "sources": [
+        {
+          "type": "dir",
+          "path": "../../"
+        },
+        {
+          "type": "patch",
+          "path": "patches/audacity-suil-fix.patch"
+        },
+        {
+          "type": "shell",
+          "commands": [
+            "sed -e '42i <release version=\"master\" date=\"2021-08-12\"/>' -i help/tenacity.metainfo.xml"
+          ]
+        }
+      ]
+    }
+  ]
+}
diff --git a/packaging/flatpak/patches/audacity-suil-fix.patch b/packaging/flatpak/patches/audacity-suil-fix.patch
new file mode 100644
index 000000000..9dae54f0a
--- /dev/null
+++ b/packaging/flatpak/patches/audacity-suil-fix.patch
@@ -0,0 +1,13 @@
+ diff --git a/src/effects/lv2/LoadLV2.cpp b/src/effects/lv2/LoadLV2.cpp
+index b101ee734..be665c5a6 100755
+--- a/src/effects/lv2/LoadLV2.cpp
++++ b/src/effects/lv2/LoadLV2.cpp
+@@ -180,7 +180,7 @@ bool LV2EffectsModule::Initialize()
+    newVar += wxT(":") + libdir.GetPath();
+ 
+    // Tell SUIL where to find his GUI support modules
+-   wxSetEnv(wxT("SUIL_MODULE_DIR"), wxT(PKGLIBDIR));
++   wxSetEnv(wxT("SUIL_MODULE_DIR"), wxT("/app/lib/suil-0"));
+ #endif
+ 
+    // Start with the LV2_PATH environment variable (if any)
diff --git a/packaging/flatpak/shared-modules b/packaging/flatpak/shared-modules
new file mode 160000
index 000000000..716f64223
--- /dev/null
+++ b/packaging/flatpak/shared-modules
@@ -0,0 +1 @@
+Subproject commit 716f6422376daad30d8135617aa20d87531b31b6