source file of the GNU LilyPond music typesetter
- (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
#include "relocate.hh"
-#include "string.hh"
+#include "config.hh"
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+#if HAVE_GETTEXT
+#include <libintl.h>
+#endif
+
#include "file-name.hh"
#include "file-path.hh"
+#include "lily-guile.hh"
+#include "lily-version.hh"
#include "main.hh"
-#include "warn.hh"
-#include "config.hh"
#include "version.hh"
+#include "warn.hh"
-#include "lily-guile.hh"
-#include "lily-version.hh"
-
-#include <unistd.h>
-#include <sys/stat.h>
int
sane_putenv (char const *key, String value, bool overwrite)
}
static int
-set_env_file (char const *key, String value)
+set_env_file (char const *key, String value, bool overwrite = false)
{
if (is_file (value))
+ return sane_putenv (key, value, overwrite);
+ else if (be_verbose_global)
+ warning (_f ("no such file: %s for %s", value, key));
+ return -1;
+}
+
+static int
+set_env_dir (char const *key, String value)
+{
+ if (is_dir (value))
return sane_putenv (key, value, false);
else if (be_verbose_global)
- warning (_f ("no such file: %s", value));
+ warning (_f ("no such directory: %s for %s", value, key));
return -1;
}
{
String s = file_name;
s.substitute ('\\', '/');
+ int n = s.length ();
+ if (n && s[n - 1] == '/')
+ s[n - 1] = 0;
s = s.left_string (s.index_last ('/'));
return s;
}
#endif
void
-set_relocation (String bindir, String prefix)
+prefix_relocation (String prefix)
{
if (be_verbose_global)
warning (_f ("Relocation: compile prefix=%s, new prefix=%s",
prefix_directory,
prefix.to_str0 ()));
+ String bindir = prefix + "/bin";
String datadir = prefix + "/share";
- String libdir = prefix + "/lib";
String localedir = datadir + "/locale";
- String sysconfdir = prefix + "/etc";
String lilypond_datadir = datadir + "/lilypond/" TOPLEVEL_VERSION;
if (is_dir (lilypond_datadir))
bindtextdomain ("lilypond", localedir.to_str0 ());
#endif
- set_env_file ("FONTCONFIG_FILE", sysconfdir + "/fonts/fonts.conf");
+ prepend_env_path ("PATH", bindir);
+}
+
+void
+framework_relocation (String prefix)
+{
+ if (be_verbose_global)
+ warning (_f ("Relocation: framework_prefix=%s", prefix));
+
+ String bindir = prefix + "/bin";
+ String datadir = prefix + "/share";
+ String libdir = prefix + "/lib";
+ String sysconfdir = prefix + "/etc";
+
+ /* need otherwise dynamic .so's aren't found. */
+ prepend_env_path ("DYLD_LIBRARY_PATH", libdir);
+
+ set_env_file ("FONTCONFIG_FILE", sysconfdir + "/fonts/fonts.conf", true);
+ set_env_dir ("FONTCONFIG_PATH", sysconfdir + "/fonts");
+
#ifdef __MINGW32__
char font_dir[PATH_MAX];
ExpandEnvironmentStrings ("%windir%/fonts", font_dir, sizeof (font_dir));
prepend_env_path ("GS_LIB", datadir + "/gs/Resource");
prepend_env_path ("GS_LIB", datadir + "/gs/lib");
- /* need otherwise dynamic .so's aren't found. */
- prepend_env_path ("DYLD_LIBRARY_PATH", libdir);
-
prepend_env_path ("GUILE_LOAD_PATH", datadir
+ to_string ("/guile/%d.%d",
SCM_MAJOR_VERSION, SCM_MINOR_VERSION));
+
set_env_file ("PANGO_RC_FILE", sysconfdir + "/pango/pangorc");
+ set_env_dir ("PANGO_PREFIX", prefix);
+
prepend_env_path ("PATH", bindir);
}
}
void
-setup_paths (char const *argv0)
+setup_paths (char const *argv0_ptr)
{
- prefix_directory = LILYPOND_DATADIR;
+ File_name argv0_filename (argv0_ptr);
+ prefix_directory = LILYPOND_DATADIR;
if (relocate_binary
&& getenv ("LILYPOND_RELOCATE_PREFIX"))
{
String prefix = getenv ("LILYPOND_RELOCATE_PREFIX");
- /*
- fixme: need different sep for mingw?
- */
- set_relocation (prefix + "/bin", prefix);
+#ifdef __MINGW32__
+ /* Normalize file name. */
+ prefix = File_name (prefix).to_string ().get_copy_str0 ();
+#endif /* __MINGW32__ */
+ prefix_relocation (prefix);
+ String bindir = prefix + "/bin";
+ framework_relocation (bindir + "/" FRAMEWORKDIR);
}
else if (relocate_binary)
{
-#if defined (__CYGWIN__) || defined (__MINGW32__)
- String s = argv0;
- s.substitute ('\\', '/');
- argv0 = s.to_str0 ();
-#endif /* __CYGWIN__ || __MINGW32__ */
-
-
- /* if name contains slashes, we should not look in $PATH */
String argv0_abs;
- if (argv0[0] == '/')
- argv0_abs = argv0_abs;
- else if (String (argv0).index ('/') > 0)
- argv0_abs = get_working_directory () + "/" + String (argv0);
+ if (argv0_filename.is_absolute ())
+ {
+ argv0_abs = argv0_filename.to_string ();
+ if (be_verbose_global)
+ warning (_f ("Relocation: is absolute: argv0=%s", argv0_ptr));
+ }
+ else if (argv0_filename.dir_.length ())
+ {
+ argv0_abs = get_working_directory ()
+ + "/" + String (argv0_filename.to_string ());
+ if (be_verbose_global)
+ warning (_f ("Relocation: from cwd: argv0=%s", argv0_ptr));
+ }
else
{
/* Find absolute ARGV0 name, using PATH. */
File_path path;
path.parse_path (getenv ("PATH"));
-
+ if (be_verbose_global)
+ warning (_f ("Relocation: from PATH=%s\nargv0=%s",
+ path.to_string ().get_str0 (), argv0_ptr));
+
#ifndef __MINGW32__
- String argv0_abs = path.find (argv0);
+ argv0_abs = path.find (argv0_filename.to_string ());
#else /* __MINGW32__ */
char const *ext[] = {"exe", "", 0 };
- String argv0_abs = path.find (argv0, ext);
+ argv0_abs = path.find (argv0_filename.to_string (), ext);
#endif /* __MINGW32__ */
if (argv0_abs.is_empty ())
- {
- File_name name (argv0);
- /* If NAME contains slashes and its DIR is not absolute, it can
- only be referenced from CWD. */
- if (name.to_string ().index ('/') >= 0 && name.dir_[0] != '/')
- {
- argv0_abs = get_working_directory () + "/" + argv0;
- }
- else
- programming_error ("can't find absolute argv0");
- }
+ programming_error ("can't find absolute argv0.");
}
-
+
String bindir = dir_name (argv0_abs);
String argv0_prefix = dir_name (bindir);
- if (argv0_prefix != dir_name (dir_name (dir_name (prefix_directory))))
- set_relocation (bindir, argv0_prefix);
+ String compile_prefix = dir_name (dir_name (dir_name (prefix_directory)));
+ if (argv0_prefix != compile_prefix)
+ prefix_relocation (argv0_prefix);
+ if (argv0_prefix != compile_prefix || String (FRAMEWORKDIR) != "..")
+ framework_relocation (bindir + "/" FRAMEWORKDIR);
}
- else
- (void) argv0;
/* FIXME: use LILYPOND_DATADIR. */
if (char const *env = getenv ("LILYPONDPREFIX"))