Add configure option to enable portable builds on Linux

This commit is contained in:
darealshinji 2019-02-18 17:18:18 +01:00 committed by Thomas Goyne
parent 565b7cb86e
commit 7094bd1e20
5 changed files with 81 additions and 11 deletions

View file

@ -57,7 +57,7 @@ P_LOCALE = @localedir@
P_APPDATA = @P_APPDATA@ P_APPDATA = @P_APPDATA@
P_DESKTOP = @P_DESKTOP@ P_DESKTOP = @P_DESKTOP@
P_ICON = @P_ICON@ P_ICON = @P_ICON@
P_DATA = $(P_DATAROOT)/aegisub/ P_DATA = @P_DATA@
############### ###############
# LIBRARY FLAGS # LIBRARY FLAGS

View file

@ -50,9 +50,10 @@ AC_SUBST(AEGISUB_COMMAND)
AC_DEFINE_UNQUOTED([AEGISUB_COMMAND], ["${AEGISUB_COMMAND}"], [Name of the Aegisub executable]) AC_DEFINE_UNQUOTED([AEGISUB_COMMAND], ["${AEGISUB_COMMAND}"], [Name of the Aegisub executable])
# Name of gettext catalog. # Name of gettext catalog.
AEGISUB_CATALOG="aegisub" # See '--enable-appimage'
AC_SUBST(AEGISUB_CATALOG) #AEGISUB_CATALOG="aegisub"
AC_DEFINE_UNQUOTED([AEGISUB_CATALOG], ["${AEGISUB_CATALOG}"], [Name of the Aegisub gettext catalog]) #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 # Handle location of appdata files: https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#spec-component-location
AC_ARG_WITH(appdata-dir, AC_ARG_WITH(appdata-dir,
@ -566,6 +567,32 @@ AC_SUBST(DEFAULT_PLAYER_AUDIO)
# Set some friendly strings if some of the above aren't detected. # Set some friendly strings if some of the above aren't detected.
DEFAULT_PLAYER_AUDIO=${DEFAULT_PLAYER_AUDIO:-NONE} 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 # Misc settings
############### ###############
@ -614,12 +641,13 @@ AC_MSG_RESULT([
Configure settings Configure settings
Install prefix: $prefix Install prefix: $prefix
Revision: $BUILD_GIT_VERSION_STRING Revision: $BUILD_GIT_VERSION_STRING
Debug $enable_debug Debug: $enable_debug
CFLAGS $CFLAGS AppImage: $enable_appimage
CXXFLAGS $CXXFLAGS CFLAGS: $CFLAGS
CPPFLAGS $CPPFLAGS CXXFLAGS: $CXXFLAGS
LDFLAGS $LDFLAGS CPPFLAGS: $CPPFLAGS
LIBS $LIBS LDFLAGS: $LDFLAGS
LIBS: $LIBS
Default Settings Default Settings
Audio Player: $DEFAULT_PLAYER_AUDIO Audio Player: $DEFAULT_PLAYER_AUDIO

View file

@ -22,6 +22,12 @@
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <pwd.h> #include <pwd.h>
#ifndef __APPLE__
#include <fstream>
#include <stdlib.h>
#include <libgen.h>
#endif
namespace { namespace {
#ifndef __APPLE__ #ifndef __APPLE__
std::string home_dir() { std::string home_dir() {
@ -35,7 +41,30 @@ std::string home_dir() {
throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set."); 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 = "";
#ifdef __FreeBSD__
exe = realpath("/proc/self/file", NULL);
#else
exe = realpath("/proc/self/exe", NULL);
#endif #endif
if (!exe) return "";
if ((dir = dirname(exe)) && strlen(dir) > 0) {
data = dir;
}
free(exe);
return data;
}
#endif /* APPIMAGE_BUILD */
#endif /* !__APPLE__ */
} }
namespace agi { namespace agi {
@ -44,14 +73,23 @@ void Path::FillPlatformSpecificPaths() {
agi::fs::path home = home_dir(); agi::fs::path home = home_dir();
SetToken("?user", home/".aegisub"); SetToken("?user", home/".aegisub");
SetToken("?local", 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", Decode("?data/dictionaries"));
#else
SetToken("?data", P_DATA); SetToken("?data", P_DATA);
SetToken("?dictionary", "/usr/share/hunspell"); SetToken("?dictionary", "/usr/share/hunspell");
#endif
#else #else
agi::fs::path app_support = agi::util::GetApplicationSupportDirectory(); agi::fs::path app_support = agi::util::GetApplicationSupportDirectory();
SetToken("?user", app_support/"Aegisub"); SetToken("?user", app_support/"Aegisub");
SetToken("?local", app_support/"Aegisub"); SetToken("?local", app_support/"Aegisub");
SetToken("?data", agi::util::GetBundleSharedSupportDirectory()); SetToken("?data", agi::util::GetBundleSharedSupportDirectory());
SetToken("?dictionary", agi::util::GetBundleSharedSupportDirectory() + "/dictionaries"); SetToken("?dictionary", Decode("?data/dictionaries"));
#endif #endif
SetToken("?temp", boost::filesystem::temp_directory_path()); SetToken("?temp", boost::filesystem::temp_directory_path());
} }

View file

@ -202,6 +202,7 @@ $(d)auto4_lua.o_FLAGS := $(CFLAGS_LUA)
$(d)auto4_lua_assfile.o_FLAGS := $(CFLAGS_LUA) $(d)auto4_lua_assfile.o_FLAGS := $(CFLAGS_LUA)
$(d)auto4_lua_dialog.o_FLAGS := $(CFLAGS_LUA) $(d)auto4_lua_dialog.o_FLAGS := $(CFLAGS_LUA)
$(d)auto4_lua_progresssink.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 $(src_OBJ): $(d)libresrc/bitmap.h $(d)libresrc/default_config.h

View file

@ -55,6 +55,9 @@ wxTranslations *AegisubLocale::GetTranslations() {
if (!translations) { if (!translations) {
wxTranslations::Set(translations = new wxTranslations); wxTranslations::Set(translations = new wxTranslations);
wxFileTranslationsLoader::AddCatalogLookupPathPrefix(config::path->Decode("?data/locale/").wstring()); wxFileTranslationsLoader::AddCatalogLookupPathPrefix(config::path->Decode("?data/locale/").wstring());
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(APPIMAGE_BUILD)
wxFileTranslationsLoader::AddCatalogLookupPathPrefix(P_LOCALE);
#endif
} }
return translations; return translations;
} }