From 9cce7d263ea3f2984a619cdfcb54d264c6a4c51d Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 5 Nov 2024 01:29:53 +0300 Subject: fully support relocatable binaries, improving AppImages * You can now specify `--with-scitecodatadir` as a relative path, that will be interpreted relative to the binary's location. * Win32 binaries already were relocatable, but this was a Windows-specific hack. Win32 binaries are now built with `--with-scitecodatadir=.` since everything is in a single directory. * Ubuntu packages are now also built `--with-scitecodatadir=../share/sciteco`. This is not crucial for ordinary installations, but is meant for AppImage creation. * Since AppImages are now built from relocatable packages, we no longer need the unionfs-workaround from pkg2appimage. This should fix the strange root contents when autocompleting in AppImage builds. * This might also fix the appimage.github.io CI issues. I assume that because I could reproduce the issue on FreeBSD's Linuxulator in dependence of pkg2appimage's "union"-setting. See https://github.com/AppImage/appimage.github.io/pull/3402 * Determining the binary location actually turned out be hard and very platform-dependant. There are now implementations for Windows (which could also read argv[0]), Linux and generic UNIX (which works on FreeBSD, but I am not sure about the others). I believe this could also be useful on Mac OS to create app bundles, but this needs to be tested - currently the Mac OS binaries are installed into fixed locations and don't use relocation. --- src/main.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 45149e6..e2c6b9e 100644 --- a/src/main.c +++ b/src/main.c @@ -77,15 +77,15 @@ volatile sig_atomic_t teco_interrupted = FALSE; * program's directory. */ static inline gchar * -teco_get_default_config_path(const gchar *program) +teco_get_default_config_path(void) { - return g_path_get_dirname(program); + return teco_file_get_program_path(); } #elif defined(G_OS_UNIX) && !defined(__HAIKU__) static inline gchar * -teco_get_default_config_path(const gchar *program) +teco_get_default_config_path(void) { return g_strdup(g_get_home_dir()); } @@ -99,7 +99,7 @@ teco_get_default_config_path(const gchar *program) * with config files. */ static inline gchar * -teco_get_default_config_path(const gchar *program) +teco_get_default_config_path(void) { return g_strdup(g_get_user_config_dir()); } @@ -210,7 +210,7 @@ teco_process_options(gchar ***argv) } static void -teco_initialize_environment(const gchar *program) +teco_initialize_environment(void) { g_autoptr(GError) error = NULL; gchar *abs_path; @@ -252,14 +252,11 @@ teco_initialize_environment(const gchar *program) /* * Initialize $SCITECOCONFIG and $SCITECOPATH */ - g_autofree gchar *default_configpath = teco_get_default_config_path(program); + g_autofree gchar *default_configpath = teco_get_default_config_path(); g_setenv("SCITECOCONFIG", default_configpath, FALSE); -#ifdef G_OS_WIN32 - g_autofree gchar *default_scitecopath = g_build_filename(default_configpath, "lib", NULL); - g_setenv("SCITECOPATH", default_scitecopath, FALSE); -#else - g_setenv("SCITECOPATH", SCITECOLIBDIR, FALSE); -#endif + g_autofree gchar *datadir = teco_file_get_datadir(); + g_autofree gchar *default_libdir = g_build_filename(datadir, "lib", NULL); + g_setenv("SCITECOPATH", default_libdir, FALSE); /* * $SCITECOCONFIG and $SCITECOPATH may still be relative. @@ -389,7 +386,7 @@ main(int argc, char **argv) /* current working directory ("$") */ teco_qreg_table_insert(&teco_qreg_table_globals, teco_qreg_workingdir_new()); /* environment defaults and registers */ - teco_initialize_environment(argv_utf8[0]); + teco_initialize_environment(); teco_qreg_table_t local_qregs; teco_qreg_table_init(&local_qregs, TRUE); -- cgit v1.2.3