Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable optional relocatable builds on Linux #160

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.inc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 31 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
###############
Expand Down Expand Up @@ -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
Expand Down
46 changes: 38 additions & 8 deletions libaegisub/unix/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <boost/filesystem/operations.hpp>
#include <pwd.h>

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

namespace {
#ifndef __APPLE__
std::string home_dir() {
Expand All @@ -35,24 +40,49 @@ std::string home_dir() {

throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set.");
}
#endif

#ifdef APPIMAGE_BUILD
std::string exe_dir() {
char *exe, *dir;
std::string data = "";

if ((exe = realpath("/proc/self/exe", NULL)) == NULL)
return "";

if ((dir = dirname(exe)) && strlen(dir) > 0)
data = dir;

free(exe);

return data;
}
#endif // APPIMAGE_BUILD
#endif // __APPLE__
}

namespace agi {
void Path::FillPlatformSpecificPaths() {
#ifndef __APPLE__
agi::fs::path home = home_dir();
SetToken("?user", home/".aegisub");
SetToken("?local", home/".aegisub");
SetToken("?data", P_DATA);
SetToken("?dictionary", "/usr/share/hunspell");
#else
#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.empty()) data = home/".aegisub";
SetToken("?data", data);
#else
SetToken("?data", P_DATA);
#endif
#endif // __APPLE__

SetToken("?temp", boost::filesystem::temp_directory_path());
}

Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/aegisublocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down