diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-12-04 18:49:54 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-12-04 18:54:10 +0000 |
| commit | 3c06c78d79fb21cd66ad1c4a4e47d593715d3442 (patch) | |
| tree | 5f5ffd056feea6a8a79b55721298d9d7ec0c1220 /src | |
| parent | Merge branch 'transupdate-master' of gitlab.com:Moini/inkscape (diff) | |
| parent | Fix a compiler warning (diff) | |
| download | inkscape-3c06c78d79fb21cd66ad1c4a4e47d593715d3442.tar.gz inkscape-3c06c78d79fb21cd66ad1c4a4e47d593715d3442.zip | |
Allow to set INKSCAPE_DATADIR via environment variable
INKSCAPE_DATADIR is the prefix prepended to all resource paths
(i.e. typically /share or similar on Linux system)
and typically set at compile time with the INKSCAPE_DATADIR define
(unless configured with ENABLE_BINRELOC)
This commit allows to override this default on Windows and Linux
(compiled without ENABLE_BINRELOC) by setting the environment
variable INKSCAPE_DATADIR.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/path-prefix.cpp | 74 | ||||
| -rw-r--r-- | src/path-prefix.h | 106 | ||||
| -rw-r--r-- | src/prefix.cpp | 40 | ||||
| -rw-r--r-- | src/prefix.h | 7 |
5 files changed, 128 insertions, 100 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4c56b211d..c6ef78a4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -233,6 +233,7 @@ set(inkscape_SRC object-set.cpp object-snapper.cpp path-chemistry.cpp + path-prefix.cpp persp3d-reference.cpp persp3d.cpp perspective-line.cpp diff --git a/src/path-prefix.cpp b/src/path-prefix.cpp new file mode 100644 index 000000000..87b756eb4 --- /dev/null +++ b/src/path-prefix.cpp @@ -0,0 +1,74 @@ +/* + * path-prefix.cpp - Inkscape specific prefix handling + * + * Authors: + * Eduard Braun <eduard.braun2@gmx.de> + * + * Copyright (C) 2017 Authors + * + * This file is part of Inkscape. + * + * Inkscape is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * See the file COPYING for details. + * + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + + +#include <glib.h> +#include "path-prefix.h" + + +/** + * Determine the location of the Inkscape data directory (typically the share/ folder + * from where Inkscape should be loading resources) and append a relative path + * + * - by default use the compile time value of INKSCAPE_DATADIR + * - on Windows inkscape_datadir will be relative to the called executable by default + * (typically inkscape/share but also handles the case where the executable is in a /bin subfolder) + * - if the environment variable INKSCAPE_DATADIR is set it will override all of the above + */ +char *append_inkscape_datadir(const char *relative_path) +{ + static gchar const *inkscape_datadir; + if (!inkscape_datadir) { + gchar const *datadir_env = g_getenv("INKSCAPE_DATADIR"); + if (datadir_env) { + inkscape_datadir = g_strdup(datadir_env); + } else { +#ifdef _WIN32 + gchar *module_path = g_win32_get_package_installation_directory_of_module(NULL); + inkscape_datadir = g_build_filename(module_path, "share", NULL); + g_free(module_path); +#else + inkscape_datadir = INKSCAPE_DATADIR; +#endif + } + } + + if (!relative_path) { + relative_path = ""; + } + + return g_build_filename(inkscape_datadir, relative_path, NULL); +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/path-prefix.h b/src/path-prefix.h index d6514d832..b69ad3753 100644 --- a/src/path-prefix.h +++ b/src/path-prefix.h @@ -18,9 +18,13 @@ #endif #include "prefix.h" -//#ifdef __cplusplus -//extern "C" { -//#endif /* __cplusplus */ + +char *append_inkscape_datadir(const char *relative_path); + +#ifdef _WIN32 +#undef INKSCAPE_DATADIR +#define INKSCAPE_DATADIR append_inkscape_datadir(NULL) +#endif #ifdef ENABLE_BINRELOC /* The way that we're building now is with a shared library between Inkscape @@ -52,30 +56,30 @@ # define CREATE_PALETTESDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/create/swatches" ) # define CREATE_PATTERNSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/create/patterns/vector" ) #else -# ifdef WIN32 -# define INKSCAPE_APPICONDIR WIN32_DATADIR("pixmaps") -# define INKSCAPE_ATTRRELDIR WIN32_DATADIR("attributes") -# define INKSCAPE_BINDDIR WIN32_DATADIR("bind") -# define INKSCAPE_EXAMPLESDIR WIN32_DATADIR("examples") -# define INKSCAPE_EXTENSIONDIR WIN32_DATADIR("extensions") -# define INKSCAPE_FILTERDIR WIN32_DATADIR("filters") -# define INKSCAPE_FONTSDIR WIN32_DATADIR("fonts") -# define INKSCAPE_GRADIENTSDIR WIN32_DATADIR("gradients") -# define INKSCAPE_KEYSDIR WIN32_DATADIR("keys") -# define INKSCAPE_PIXMAPDIR WIN32_DATADIR("icons") -# define INKSCAPE_MARKERSDIR WIN32_DATADIR("markers") -# define INKSCAPE_PALETTESDIR WIN32_DATADIR("palettes") -# define INKSCAPE_PATTERNSDIR WIN32_DATADIR("patterns") -# define INKSCAPE_SCREENSDIR WIN32_DATADIR("screens") -# define INKSCAPE_SYMBOLSDIR WIN32_DATADIR("symbols") -# define INKSCAPE_THEMEDIR INKSCAPE_PIXMAPDIR -# define INKSCAPE_TUTORIALSDIR WIN32_DATADIR("tutorials") -# define INKSCAPE_TEMPLATESDIR WIN32_DATADIR("templates") -# define INKSCAPE_UIDIR WIN32_DATADIR("ui") +# ifdef _WIN32 +# define INKSCAPE_APPICONDIR append_inkscape_datadir("pixmaps") +# define INKSCAPE_ATTRRELDIR append_inkscape_datadir("attributes") +# define INKSCAPE_BINDDIR append_inkscape_datadir("bind") +# define INKSCAPE_EXAMPLESDIR append_inkscape_datadir("examples") +# define INKSCAPE_EXTENSIONDIR append_inkscape_datadir("extensions") +# define INKSCAPE_FILTERDIR append_inkscape_datadir("filters") +# define INKSCAPE_FONTSDIR append_inkscape_datadir("fonts") +# define INKSCAPE_GRADIENTSDIR append_inkscape_datadir("gradients") +# define INKSCAPE_KEYSDIR append_inkscape_datadir("keys") +# define INKSCAPE_PIXMAPDIR append_inkscape_datadir("icons") +# define INKSCAPE_MARKERSDIR append_inkscape_datadir("markers") +# define INKSCAPE_PALETTESDIR append_inkscape_datadir("palettes") +# define INKSCAPE_PATTERNSDIR append_inkscape_datadir("patterns") +# define INKSCAPE_SCREENSDIR append_inkscape_datadir("screens") +# define INKSCAPE_SYMBOLSDIR append_inkscape_datadir("symbols") +# define INKSCAPE_THEMEDIR append_inkscape_datadir("icons") +# define INKSCAPE_TUTORIALSDIR append_inkscape_datadir("tutorials") +# define INKSCAPE_TEMPLATESDIR append_inkscape_datadir("templates") +# define INKSCAPE_UIDIR append_inkscape_datadir("ui") //CREATE V0.1 WIN32 support -# define CREATE_GRADIENTSDIR WIN32_DATADIR("create\\gradients\\gimp") -# define CREATE_PALETTESDIR WIN32_DATADIR("create\\swatches") -# define CREATE_PATTERNSDIR WIN32_DATADIR("create\\patterns\\vector") +# define CREATE_GRADIENTSDIR append_inkscape_datadir("create\\gradients\\gimp") +# define CREATE_PALETTESDIR append_inkscape_datadir("create\\swatches") +# define CREATE_PATTERNSDIR append_inkscape_datadir("create\\patterns\\vector") # elif defined ENABLE_OSX_APP_LOCATIONS # define INKSCAPE_APPICONDIR "Contents/Resources/share/pixmaps" # define INKSCAPE_ATTRRELDIR "Contents/Resources/share/inkscape/attributes" @@ -101,34 +105,30 @@ # define CREATE_PALETTESDIR "/Library/Application Support/create/swatches" # define CREATE_PATTERNSDIR "/Library/Application Support/create/patterns/vector" # else -# define INKSCAPE_APPICONDIR INKSCAPE_DATADIR "/pixmaps" -# define INKSCAPE_ATTRRELDIR INKSCAPE_DATADIR "/inkscape/attributes" -# define INKSCAPE_BINDDIR INKSCAPE_DATADIR "/inkscape/bind" -# define INKSCAPE_EXAMPLESDIR INKSCAPE_DATADIR "/inkscape/examples" -# define INKSCAPE_EXTENSIONDIR INKSCAPE_DATADIR "/inkscape/extensions" -# define INKSCAPE_FILTERDIR INKSCAPE_DATADIR "/inkscape/filters" -# define INKSCAPE_FONTSDIR INKSCAPE_DATADIR "/inkscape/fonts" -# define INKSCAPE_GRADIENTSDIR INKSCAPE_DATADIR "/inkscape/gradients" -# define INKSCAPE_KEYSDIR INKSCAPE_DATADIR "/inkscape/keys" -# define INKSCAPE_PIXMAPDIR INKSCAPE_DATADIR "/inkscape/icons" -# define INKSCAPE_MARKERSDIR INKSCAPE_DATADIR "/inkscape/markers" -# define INKSCAPE_PALETTESDIR INKSCAPE_DATADIR "/inkscape/palettes" -# define INKSCAPE_PATTERNSDIR INKSCAPE_DATADIR "/inkscape/patterns" -# define INKSCAPE_SCREENSDIR INKSCAPE_DATADIR "/inkscape/screens" -# define INKSCAPE_SYMBOLSDIR INKSCAPE_DATADIR "/inkscape/symbols" -# define INKSCAPE_THEMEDIR INKSCAPE_DATADIR "/icons" -# define INKSCAPE_TUTORIALSDIR INKSCAPE_DATADIR "/inkscape/tutorials" -# define INKSCAPE_TEMPLATESDIR INKSCAPE_DATADIR "/inkscape/templates" -# define INKSCAPE_UIDIR INKSCAPE_DATADIR "/inkscape/ui" +# define INKSCAPE_APPICONDIR append_inkscape_datadir("pixmaps") +# define INKSCAPE_ATTRRELDIR append_inkscape_datadir("inkscape/attributes") +# define INKSCAPE_BINDDIR append_inkscape_datadir("inkscape/bind") +# define INKSCAPE_EXAMPLESDIR append_inkscape_datadir("inkscape/examples") +# define INKSCAPE_EXTENSIONDIR append_inkscape_datadir("inkscape/extensions") +# define INKSCAPE_FILTERDIR append_inkscape_datadir("inkscape/filters") +# define INKSCAPE_FONTSDIR append_inkscape_datadir("inkscape/fonts") +# define INKSCAPE_GRADIENTSDIR append_inkscape_datadir("inkscape/gradients") +# define INKSCAPE_KEYSDIR append_inkscape_datadir("inkscape/keys") +# define INKSCAPE_PIXMAPDIR append_inkscape_datadir("inkscape/icons") +# define INKSCAPE_MARKERSDIR append_inkscape_datadir("inkscape/markers") +# define INKSCAPE_PALETTESDIR append_inkscape_datadir("inkscape/palettes") +# define INKSCAPE_PATTERNSDIR append_inkscape_datadir("inkscape/patterns") +# define INKSCAPE_SCREENSDIR append_inkscape_datadir("inkscape/screens") +# define INKSCAPE_SYMBOLSDIR append_inkscape_datadir("inkscape/symbols") +# define INKSCAPE_THEMEDIR append_inkscape_datadir("icons") +# define INKSCAPE_TUTORIALSDIR append_inkscape_datadir("inkscape/tutorials") +# define INKSCAPE_TEMPLATESDIR append_inkscape_datadir("inkscape/templates") +# define INKSCAPE_UIDIR append_inkscape_datadir("inkscape/ui") //CREATE V0.1 support -# define CREATE_GRADIENTSDIR INKSCAPE_DATADIR "/create/gradients/gimp" -# define CREATE_PALETTESDIR INKSCAPE_DATADIR "/create/swatches" -# define CREATE_PATTERNSDIR INKSCAPE_DATADIR "/create/patterns/vector" -# endif +# define CREATE_GRADIENTSDIR append_inkscape_datadir("create/gradients/gimp") +# define CREATE_PALETTESDIR append_inkscape_datadir("create/swatches") +# define CREATE_PATTERNSDIR append_inkscape_datadir("create/patterns/vector") +# endif #endif -//#ifdef __cplusplus -//} -//#endif /* __cplusplus */ - #endif /* _PATH_PREFIX_H_ */ diff --git a/src/prefix.cpp b/src/prefix.cpp index c8bf7abec..14fdd04df 100644 --- a/src/prefix.cpp +++ b/src/prefix.cpp @@ -416,44 +416,4 @@ br_extract_prefix (const char *path) } #endif /* __cplusplus */ - - -#ifdef __WIN32__ -/** - * Provide a similar mechanism for Win32. Enable a macro, - * WIN32_DATADIR, that can look up subpaths for inkscape resources - */ - -/** - * Get the Windows-equivalent of INKSCAPE_DATADIR and append a relative path - * - * - by default INKSCAPE_DATADIR will be relative to the called executable - * (typically inkscape/share but also handles the case where the executable is in a /bin subfolder) - * - to override set the INKSCAPE_DATADIR environment variable - */ -char *win32_append_datadir(const char *relative_path) -{ - static gchar *datadir; - if (!datadir) { - gchar const *inkscape_datadir = g_getenv("INKSCAPE_DATADIR"); - if (inkscape_datadir) { - datadir = g_strdup(inkscape_datadir); - } else { - gchar *module_path = g_win32_get_package_installation_directory_of_module(NULL); - datadir = g_build_filename(module_path, "share", NULL); - g_free(module_path); - } - } - - if (!relative_path) { - relative_path = ""; - } - - return g_build_filename(datadir, relative_path, NULL); -} -#endif /* __WIN32__ */ - - - - #endif /* _PREFIX_C */ diff --git a/src/prefix.h b/src/prefix.h index d28e896d0..bdf3b6df4 100644 --- a/src/prefix.h +++ b/src/prefix.h @@ -118,11 +118,4 @@ char *br_extract_prefix(const char *path); } #endif /* __cplusplus */ -#ifdef __WIN32__ -char *win32_append_datadir(const char *relative_path); -#undef INKSCAPE_DATADIR -#define INKSCAPE_DATADIR win32_append_datadir(NULL) -#define WIN32_DATADIR(suffix) (win32_append_datadir(suffix)) -#endif - #endif /* _PREFIX_H_ */ |
