File aegisub-PR160.patch of Package aegisub

From fd599001d001da4dccee4cf2b5ac6afe6e35c233 Mon Sep 17 00:00:00 2001
From: darealshinji <djcj@gmx.de>
Date: Sun, 1 Jan 2023 16:31:15 +0100
Subject: [PATCH 1/2] enable optional relocatable builds on Linux

---
 Makefile.inc.in          |  2 +-
 configure.ac             | 34 +++++++++++++++++++++++++++++++---
 libaegisub/unix/path.cpp | 33 +++++++++++++++++++++++++++++++++
 src/Makefile             |  1 +
 src/aegisublocale.cpp    |  3 +++
 5 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/Makefile.inc.in b/Makefile.inc.in
index 4e5471b124..642f882ef9 100644
--- a/Makefile.inc.in
+++ b/Makefile.inc.in
@@ -58,7 +58,7 @@ P_LOCALE      = @localedir@
 P_APPDATA     = @P_APPDATA@
 P_DESKTOP     = @P_DESKTOP@
 P_ICON        = @P_ICON@
-P_DATA        = $(P_DATAROOT)/aegisub/
+P_DATA        = @P_DATA@
 
 ###############
 # LIBRARY FLAGS
diff --git a/configure.ac b/configure.ac
index 856e38993a..1a09f1b9d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,9 +50,10 @@ AC_SUBST(AEGISUB_COMMAND)
 AC_DEFINE_UNQUOTED([AEGISUB_COMMAND], ["${AEGISUB_COMMAND}"], [Name of the Aegisub executable])
 
 # Name of gettext catalog.
-AEGISUB_CATALOG="aegisub"
-AC_SUBST(AEGISUB_CATALOG)
-AC_DEFINE_UNQUOTED([AEGISUB_CATALOG], ["${AEGISUB_CATALOG}"], [Name of the Aegisub gettext catalog])
+# See '--enable-appimage'
+#AEGISUB_CATALOG="aegisub"
+#AC_SUBST(AEGISUB_CATALOG)
+#AC_DEFINE_UNQUOTED([AEGISUB_CATALOG], ["${AEGISUB_CATALOG}"], [Name of the Aegisub gettext catalog])
 
 # Handle location of appdata files: https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#spec-component-location
 AC_ARG_WITH(appdata-dir,
@@ -568,6 +569,32 @@ AC_SUBST(DEFAULT_PLAYER_AUDIO)
 # Set some friendly strings if some of the above aren't detected.
 DEFAULT_PLAYER_AUDIO=${DEFAULT_PLAYER_AUDIO:-NONE}
 
+################
+# AppImage build
+################
+# If enabled, localization and automation data is obtained from the binary's
+# path and never from the system's root. It will also install files that
+# Aegisub will lookup next to the binary, so be careful with "make install".
+AC_ARG_ENABLE(appimage,
+              AS_HELP_STRING([--enable-appimage],
+                             [Enable certain relocation settings useful for building AppImages or generic portable builds [no]]))
+
+P_DATA="$datarootdir/aegisub"
+AEGISUB_CATALOG="aegisub"
+
+AS_IF([test x$enable_appimage = xyes], [
+  AC_DEFINE([APPIMAGE_BUILD], [], [Define to enable AppImage compatible relocations])
+  P_DATA="$bindir"
+  localedir="$bindir/locale"
+  # use a different catalog name
+  AEGISUB_CATALOG="aegisub-appimage"
+])
+
+enable_appimage=${enable_appimage:-no}
+AC_SUBST(P_DATA)
+AC_SUBST(AEGISUB_CATALOG)
+AC_DEFINE_UNQUOTED([AEGISUB_CATALOG], ["${AEGISUB_CATALOG}"], [Name of the Aegisub gettext catalog])
+
 ###############
 # Misc settings
 ###############
@@ -617,6 +644,7 @@ Configure settings
   Install prefix:        $prefix
   Revision:              $BUILD_GIT_VERSION_STRING
   Debug                  $enable_debug
+  AppImage               $enable_appimage
   CFLAGS                 $CFLAGS
   CXXFLAGS               $CXXFLAGS
   CPPFLAGS               $CPPFLAGS
diff --git a/libaegisub/unix/path.cpp b/libaegisub/unix/path.cpp
index 0541e0dbe4..d0eb76d68f 100644
--- a/libaegisub/unix/path.cpp
+++ b/libaegisub/unix/path.cpp
@@ -22,6 +22,12 @@
 #include <boost/filesystem/operations.hpp>
 #include <pwd.h>
 
+#ifndef __APPLE__
+#include <libgen.h>
+#include <stdlib.h>
+#include <string.h>
+#endif
+
 namespace {
 #ifndef __APPLE__
 std::string home_dir() {
@@ -35,6 +41,24 @@ std::string home_dir() {
 
 	throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set.");
 }
+
+#ifdef APPIMAGE_BUILD
+std::string exe_dir() {
+	char *exe, *dir;
+	std::string data = "";
+
+	exe = realpath("/proc/self/exe", NULL);
+	if (!exe) return "";
+
+	if ((dir = dirname(exe)) && strlen(dir) > 0) {
+		data = dir;
+	}
+
+	free(exe);
+
+	return data;
+}
+#endif
 #endif
 }
 
@@ -44,8 +68,17 @@ void Path::FillPlatformSpecificPaths() {
 	agi::fs::path home = home_dir();
 	SetToken("?user", home/".aegisub");
 	SetToken("?local", home/".aegisub");
+
+#ifdef APPIMAGE_BUILD
+	agi::fs::path data = exe_dir();
+	if (data == "") data = home/".aegisub";
+	SetToken("?data", data);
+	SetToken("?dictionary", data/"dictionaries");
+#else
 	SetToken("?data", P_DATA);
 	SetToken("?dictionary", "/usr/share/hunspell");
+#endif
+
 #else
 	agi::fs::path app_support = agi::util::GetApplicationSupportDirectory();
 	SetToken("?user", app_support/"Aegisub");
diff --git a/src/Makefile b/src/Makefile
index 77928e8178..80119d1994 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -209,6 +209,7 @@ $(d)auto4_lua.o_FLAGS                   := $(CFLAGS_LUA)
 $(d)auto4_lua_assfile.o_FLAGS           := $(CFLAGS_LUA)
 $(d)auto4_lua_dialog.o_FLAGS            := $(CFLAGS_LUA)
 $(d)auto4_lua_progresssink.o_FLAGS      := $(CFLAGS_LUA)
+$(d)aegisublocale.o_FLAGS               := -DP_LOCALE=\"$(P_LOCALE)\"
 
 $(src_OBJ): $(d)libresrc/bitmap.h $(d)libresrc/default_config.h
 
diff --git a/src/aegisublocale.cpp b/src/aegisublocale.cpp
index de8df7296d..b9e4184e94 100644
--- a/src/aegisublocale.cpp
+++ b/src/aegisublocale.cpp
@@ -55,6 +55,9 @@ wxTranslations *AegisubLocale::GetTranslations() {
 	if (!translations) {
 		wxTranslations::Set(translations = new wxTranslations);
 		wxFileTranslationsLoader::AddCatalogLookupPathPrefix(config::path->Decode("?data/locale/").wstring());
+#if defined(P_LOCALE) && !defined(_WIN32) && !defined(__APPLE__) && !defined(APPIMAGE_BUILD)
+		wxFileTranslationsLoader::AddCatalogLookupPathPrefix(P_LOCALE);
+#endif
 	}
 	return translations;
 }

From 48fb71827f31afa6e8dc54127d4937cda150629c Mon Sep 17 00:00:00 2001
From: darealshinji <djcj@gmx.de>
Date: Wed, 10 May 2023 23:32:12 +0200
Subject: [PATCH 2/2] use hunspell directory by default

---
 libaegisub/unix/path.cpp | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/libaegisub/unix/path.cpp b/libaegisub/unix/path.cpp
index d0eb76d68f..2215d7bec6 100644
--- a/libaegisub/unix/path.cpp
+++ b/libaegisub/unix/path.cpp
@@ -23,9 +23,8 @@
 #include <pwd.h>
 
 #ifndef __APPLE__
-#include <libgen.h>
 #include <stdlib.h>
-#include <string.h>
+#include <libgen.h>
 #endif
 
 namespace {
@@ -47,45 +46,43 @@ std::string exe_dir() {
 	char *exe, *dir;
 	std::string data = "";
 
-	exe = realpath("/proc/self/exe", NULL);
-	if (!exe) return "";
+	if ((exe = realpath("/proc/self/exe", NULL)) == NULL)
+		return "";
 
-	if ((dir = dirname(exe)) && strlen(dir) > 0) {
+	if ((dir = dirname(exe)) && strlen(dir) > 0)
 		data = dir;
-	}
 
 	free(exe);
 
 	return data;
 }
-#endif
-#endif
+#endif  // APPIMAGE_BUILD
+#endif  // __APPLE__
 }
 
 namespace agi {
 void Path::FillPlatformSpecificPaths() {
-#ifndef __APPLE__
+#ifdef __APPLE__
+	agi::fs::path app_support = agi::util::GetApplicationSupportDirectory();
+	SetToken("?user", app_support/"Aegisub");
+	SetToken("?local", app_support/"Aegisub");
+	SetToken("?data", agi::util::GetBundleSharedSupportDirectory());
+	SetToken("?dictionary", agi::util::GetBundleSharedSupportDirectory() + "/dictionaries");
+#else
 	agi::fs::path home = home_dir();
 	SetToken("?user", home/".aegisub");
 	SetToken("?local", home/".aegisub");
+	SetToken("?dictionary", "/usr/share/hunspell");
 
 #ifdef APPIMAGE_BUILD
 	agi::fs::path data = exe_dir();
-	if (data == "") data = home/".aegisub";
+	if (data.empty()) data = home/".aegisub";
 	SetToken("?data", data);
-	SetToken("?dictionary", data/"dictionaries");
 #else
 	SetToken("?data", P_DATA);
-	SetToken("?dictionary", "/usr/share/hunspell");
 #endif
+#endif  // __APPLE__
 
-#else
-	agi::fs::path app_support = agi::util::GetApplicationSupportDirectory();
-	SetToken("?user", app_support/"Aegisub");
-	SetToken("?local", app_support/"Aegisub");
-	SetToken("?data", agi::util::GetBundleSharedSupportDirectory());
-	SetToken("?dictionary", agi::util::GetBundleSharedSupportDirectory() + "/dictionaries");
-#endif
 	SetToken("?temp", boost::filesystem::temp_directory_path());
 }
 
openSUSE Build Service is sponsored by