-#if ARGV0_RELOCATION
-static int
-sane_putenv (char const* key, String value, bool overwrite = true)
-{
- if (overwrite || !getenv (key))
- {
- String combine = String (key) + "=" + value;
- char *s = strdup (combine.to_str0 ());
- return putenv (s);
- }
- return -1;
-}
-
-static int
-prepend_env_path (char const *key, String value)
-{
- if (char const* cur = getenv (key))
- value += to_string (PATHSEP) + cur;
- return sane_putenv (key, value.to_str0 ());
-}
-
-String
-dir_name (String const file_name)
-{
- String s = file_name;
- s.substitute ('\\', '/');
- s = s.left_string (s.index_last ('/'));
- return s;
-}
-#endif
-
-static void
-setup_paths (char const* argv0)
-{
- prefix_directory = LILYPOND_DATADIR;
-
-#if ARGV0_RELOCATION
- String bindir = dir_name (argv0);
- String argv0_prefix = dir_name (bindir);
- if (argv0_prefix != dir_name (dir_name (dir_name (prefix_directory))))
- {
-#if 0
- warning (_f ("argv0 relocation: argv0=%s, prefix=%s", argv0,
- prefix_directory));
-#endif
- String datadir = argv0_prefix + "/share";
- String libdir = argv0_prefix + "/lib";
- String sysconfdir = argv0_prefix + "/etc";
- prefix_directory = datadir + "/lilypond/" TOPLEVEL_VERSION;
-
- sane_putenv ("FONTCONFIG_FILE", sysconfdir + "/fonts/fonts.conf", false);
- prepend_env_path ("GUILE_LOAD_PATH", datadir
- + to_string ("/guile/%d.%d",
- SCM_MAJOR_VERSION, SCM_MINOR_VERSION));
- sane_putenv ("PANGO_RC_FILE", sysconfdir + "/pango/pango.modules", false);
- prepend_env_path ("PATH", bindir);
- }
-#endif /* ARGV0_RELOCATION */
-
- if (char const *env = getenv ("LILYPONDPREFIX"))
- prefix_directory = env;
-
- global_path.append ("");
-
- /* Adding mf/out make lilypond unchanged source directory, when setting
- LILYPONDPREFIX to lilypond-x.y.z */
- char *suffixes[] = {"ly", "ps", "scm", 0 };
-
- Array<String> dirs;
- for (char **s = suffixes; *s; s++)
- {
- String path = prefix_directory + to_string ('/') + String (*s);
- dirs.push (path);
- }
-
- /*
- ugh. C&P font-config.cc
- */
- struct stat statbuf;
- String builddir = prefix_directory + "/mf/out/";
- if (stat (builddir.to_str0 (), &statbuf) == 0)
- {
- dirs.push (builddir.to_str0 ());
- }
- else
- {
- dirs.push (prefix_directory + "/fonts/otf/");
- dirs.push (prefix_directory + "/fonts/type1/");
- dirs.push (prefix_directory + "/fonts/cff/");
- dirs.push (prefix_directory + "/fonts/svg/");
- dirs.push (prefix_directory + "/fonts/cff/");
- }
-
- for (int i = 0; i < dirs.size (); i++)
- global_path.prepend (dirs[i]);
-}
-