Commit 12bc46ce authored by Alex Samorukov's avatar Alex Samorukov

Set required variables if is running from Apple application bundle

(cherry picked with small changes from commit 
e13e7fd8)
parent 38fff3b6
Pipeline #128232 failed with stages
in 9 minutes and 14 seconds
......@@ -38,6 +38,12 @@
#endif /* G_OS_WIN32 */
#if defined(ENABLE_RELOCATABLE_RESOURCES) && defined(__APPLE__)
#include <sys/param.h> /* PATH_MAX */
#include <libgen.h> /* dirname */
#include <sys/stat.h>
#endif /* __APPLE__ */
#ifndef GIMP_CONSOLE_COMPILATION
#include <gdk/gdk.h>
#else
......@@ -298,6 +304,86 @@ static const GOptionEntry main_entries[] =
{ NULL }
};
#if defined(ENABLE_RELOCATABLE_RESOURCES) && defined(__APPLE__)
static void
gimp_macos_setenv (const char * progname)
{
/* helper to set environment variables for GIMP to be relocatable.
* Due to the latest changes it is not recommended to set it in the shell
* wrapper anymore.
*/
gchar resolved_path[PATH_MAX];
/* on some OSX installations open file limit is 256 and GIMP needs more */
struct rlimit limit;
limit.rlim_cur = 10000;
limit.rlim_max = 10000;
setrlimit (RLIMIT_NOFILE, &limit);
if (realpath (progname, resolved_path) && !g_getenv ("GIMP_NO_WRAPPER"))
{
/* set path to the app folder to make sure that our python is called
* instead of system one
*/
static gboolean show_playground = TRUE;
gchar *path;
gchar tmp[PATH_MAX];
gchar *app_dir;
gchar res_dir[PATH_MAX];
size_t path_len;
struct stat sb;
app_dir = g_path_get_dirname (resolved_path);
g_snprintf (tmp, sizeof(tmp), "%s/../Resources", app_dir);
if (realpath (tmp, res_dir) && !stat (res_dir,&sb) && S_ISDIR (sb.st_mode))
g_print ("GIMP is started as MacOS application\n");
else
return;
path_len = strlen (g_getenv ("PATH") ? g_getenv ("PATH") : "") + strlen (app_dir) + 2;
path = g_try_malloc (path_len);
if (path == NULL)
{
g_warning ("Failed to allocate memory");
app_exit (EXIT_FAILURE);
}
if (g_getenv ("PATH"))
g_snprintf (path, path_len, "%s:%s", app_dir, g_getenv ("PATH"));
else
g_snprintf (path, path_len, "%s", app_dir);
g_free (app_dir);
g_setenv ("PATH", path, TRUE);
g_free (path);
g_snprintf (tmp, sizeof(tmp), "%s/lib/gtk-3.0/3.0.0", res_dir);
g_setenv ("GTK_PATH", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/etc/gtk-3.0/gtk.immodules", res_dir);
g_setenv ("GTK_IM_MODULE_FILE", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/lib/gegl-0.4", res_dir);
g_setenv ("GEGL_PATH", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/lib/babl-0.1", res_dir);
g_setenv ("BABL_PATH", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache", res_dir);
g_setenv ("GDK_PIXBUF_MODULE_FILE", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/etc/fonts", res_dir);
g_setenv ("FONTCONFIG_PATH", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s", res_dir);
g_setenv ("PYTHONHOME", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/lib/python2.7:%s/lib/gimp/2.0/python", res_dir, res_dir);
g_setenv ("PYTHONPATH", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/lib/gio/modules", res_dir);
g_setenv ("GIO_MODULE_DIR", tmp, TRUE);
g_snprintf (tmp, sizeof(tmp), "%s/share/libwmf/fonts", res_dir);
g_setenv ("WMF_FONTDIR", tmp, TRUE);
if (g_getenv ("HOME")!=NULL)
{
g_snprintf (tmp, sizeof(tmp),
"%s/Library/Application Support/GIMP/3.00/cache",
g_getenv("HOME"));
g_setenv ("XDG_CACHE_HOME", tmp, TRUE);
}
}
}
#endif
int
main (int argc,
char **argv)
......@@ -314,6 +400,25 @@ main (int argc,
#ifdef ENABLE_WIN32_DEBUG_CONSOLE
gimp_open_console_window ();
#endif
#if defined(ENABLE_RELOCATABLE_RESOURCES) && defined(__APPLE__)
/* remove MacOS session identifier from the command line args */
gint newargc = 0;
for (gint i = 0; i < argc; i++)
{
if (!g_str_has_prefix (argv[i], "-psn_"))
{
argv[newargc] = argv[i];
newargc++;
}
}
if (argc > newargc)
{
argv[newargc] = NULL; /* glib expects NULL terminated array */
argc = newargc;
}
gimp_macos_setenv (argv[0]);
#endif
#if defined (__GNUC__) && defined (_WIN64)
/* mingw-w64, at least the unstable build from late July 2008,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment