From bd99505d17a74fd230b7870a7c65bbfb9b2e9782 Mon Sep 17 00:00:00 2001 From: darealshinji Date: Sun, 29 Dec 2024 19:42:43 +0100 Subject: [PATCH] Separate path source files for macOS, relocatable build option added --- libaegisub/meson.build | 6 ++++- libaegisub/osx/path.mm | 29 ++++++++++++++++++++++ libaegisub/unix/path.cpp | 52 ++++++++++++---------------------------- meson.build | 3 +++ meson_options.txt | 2 ++ 5 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 libaegisub/osx/path.mm diff --git a/libaegisub/meson.build b/libaegisub/meson.build index 7689d31aeb..3b0e4964fc 100644 --- a/libaegisub/meson.build +++ b/libaegisub/meson.build @@ -55,6 +55,7 @@ libaegisub_src = [ if host_machine.system() == 'darwin' libaegisub_src += [ 'osx/dispatch.mm', + 'osx/path.mm', 'osx/spellchecker.mm', 'osx/util.mm', ] @@ -76,9 +77,12 @@ else 'unix/access.cpp', 'unix/fs.cpp', 'unix/log.cpp', - 'unix/path.cpp', 'unix/util.cpp', ] + + if host_machine.system() != 'darwin' + libaegisub_src += 'unix/path.cpp' + endif endif libaegisub_cpp_pch = ['include/lagi_pre.h'] diff --git a/libaegisub/osx/path.mm b/libaegisub/osx/path.mm new file mode 100644 index 0000000000..27d4e70604 --- /dev/null +++ b/libaegisub/osx/path.mm @@ -0,0 +1,29 @@ +// Copyright (c) 2013, Thomas Goyne +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// Aegisub Project http://www.aegisub.org/ + +#include +#include + +namespace agi { +void Path::FillPlatformSpecificPaths() { + std::filesystem::path app_support = agi::util::GetApplicationSupportDirectory(); + SetToken("?user", app_support/"Aegisub"); + SetToken("?local", app_support/"Aegisub"); + SetToken("?data", agi::util::GetBundleSharedSupportDirectory()); + SetToken("?dictionary", Decode("?data/dictionaries")); + SetToken("?temp", std::filesystem::temp_directory_path()); +} +} diff --git a/libaegisub/unix/path.cpp b/libaegisub/unix/path.cpp index a171bc2a43..41d4066d2e 100644 --- a/libaegisub/unix/path.cpp +++ b/libaegisub/unix/path.cpp @@ -15,20 +15,14 @@ // Aegisub Project http://www.aegisub.org/ #include - #include -#include #include - -#ifndef __APPLE__ -#include #include -#include -#endif + +namespace sfs = std::filesystem; namespace { -#ifndef __APPLE__ std::string home_dir() { const char *env = getenv("HOME"); if (env) return env; @@ -42,39 +36,31 @@ std::string home_dir() { } #ifdef APPIMAGE_BUILD -std::string exe_dir() { - char *exe, *dir; - std::string data = ""; - -#ifdef __FreeBSD__ - exe = realpath("/proc/self/file", NULL); -#else - exe = realpath("/proc/self/exe", NULL); -#endif - +sfs::path data_dir() { + char *exe = realpath("/proc/self/exe", NULL); if (!exe) return ""; - if ((dir = dirname(exe)) && strlen(dir) > 0) { - data = dir; - } - + sfs::path p = sfs::path(exe).parent_path(); free(exe); - return data; + if (p.filename() == "bin") { + // assume unix prefix layout + return p.parent_path()/"share"; + } + + return p; } -#endif /* APPIMAGE_BUILD */ -#endif /* !__APPLE__ */ +#endif } namespace agi { void Path::FillPlatformSpecificPaths() { -#ifndef __APPLE__ - std::filesystem::path home = home_dir(); + sfs::path home = home_dir(); SetToken("?user", home/".aegisub"); SetToken("?local", home/".aegisub"); #ifdef APPIMAGE_BUILD - std::filesystem::path data = exe_dir(); + sfs::path data = data_dir(); if (data == "") data = home/".aegisub"; SetToken("?data", data); SetToken("?dictionary", Decode("?data/dictionaries")); @@ -83,14 +69,6 @@ void Path::FillPlatformSpecificPaths() { SetToken("?dictionary", "/usr/share/hunspell"); #endif -#else - std::filesystem::path app_support = agi::util::GetApplicationSupportDirectory(); - SetToken("?user", app_support/"Aegisub"); - SetToken("?local", app_support/"Aegisub"); - SetToken("?data", agi::util::GetBundleSharedSupportDirectory()); - SetToken("?dictionary", Decode("?data/dictionaries")); -#endif - SetToken("?temp", std::filesystem::temp_directory_path()); + SetToken("?temp", sfs::temp_directory_path()); } - } diff --git a/meson.build b/meson.build index d58c9e3899..d2ae691333 100644 --- a/meson.build +++ b/meson.build @@ -73,6 +73,9 @@ if get_option('enable_update_checker') conf.set_quoted('UPDATE_CHECKER_SERVER', get_option('update_server')) conf.set_quoted('UPDATE_CHECKER_BASE_URL', get_option('update_url')) endif +if get_option('relocatable') and host_machine.system() == 'linux' + conf.set('APPIMAGE_BUILD', 1) +endif deps = [] deps_inc = [] diff --git a/meson_options.txt b/meson_options.txt index 1c29cd3b33..6b5d796457 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -26,3 +26,5 @@ option('update_server', type: 'string', value: 'https://aegisub-updates.redvice. option('update_url', type: 'string', value: '/trunk', description: 'Base path to use for the update checker') option('build_osx_bundle', type: 'boolean', value: false, description: 'Package Aegisub.app on OSX') + +option('relocatable', type: 'boolean', value: false, description: 'Enable relocatable build')