Skip to content

Commit

Permalink
Separate path source files for macOS, relocatable build option added
Browse files Browse the repository at this point in the history
  • Loading branch information
darealshinji committed Dec 29, 2024
1 parent d185d07 commit bd99505
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 38 deletions.
6 changes: 5 additions & 1 deletion libaegisub/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
Expand All @@ -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']
Expand Down
29 changes: 29 additions & 0 deletions libaegisub/osx/path.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2013, Thomas Goyne <[email protected]>
//
// 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 <libaegisub/path.h>
#include <libaegisub/util_osx.h>

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());
}
}
52 changes: 15 additions & 37 deletions libaegisub/unix/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@
// Aegisub Project http://www.aegisub.org/

#include <libaegisub/path.h>

#include <libaegisub/exception.h>
#include <libaegisub/util_osx.h>

#include <pwd.h>

#ifndef __APPLE__
#include <fstream>
#include <stdlib.h>
#include <libgen.h>
#endif

namespace sfs = std::filesystem;

namespace {
#ifndef __APPLE__
std::string home_dir() {
const char *env = getenv("HOME");
if (env) return env;
Expand All @@ -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"));
Expand All @@ -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());
}

}
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit bd99505

Please sign in to comment.