]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/main.cc
* lily/main.cc (setup_paths)[__MINGW32__]: Normalize LILYPONDPREFIX.
[lilypond.git] / lily / main.cc
index 1a76689c3268f097860b2bfd398a7429c7da3933..4c8af368e029313221c75ffd203486b2e93d508b 100644 (file)
@@ -152,7 +152,7 @@ static Long_option_init options_static[]
   {0, "ps", 0, _i ("generate PostScript")},
   {0, "tex", 0, _i ("generate TeX (tex backend only)")},
   {0, "help", 'h',  _i ("print this help")},
-  {_i ("FIELD"), "header", 'H',  _i ("write header field to BASENAME.FIELD")},
+  {_i ("FIELD"), "header", 'H',  _i ("dump a header field to file BASENAME.FIELD")},
   {_i ("DIR"), "include", 'I',  _i ("add DIR to search path")},
   {_i ("FILE"), "init", 'i',  _i ("use FILE as init file")},
   {_i ("FILE"), "output", 'o',  _i ("write output to FILE (suffix will be added)")},
@@ -170,16 +170,32 @@ static Long_option_init options_static[]
 
 #define LILYPOND_DATADIR PACKAGE_DATADIR "/" TOPLEVEL_VERSION
 
+static void
+env_var_info (FILE *out, char const* key)
+{
+  if (char const *value = getenv (key))
+    fprintf (out, "%s=\"%s\"\n", key, value);
+}
+
 static void
 dir_info (FILE *out)
 {
   fputs ("\n", out);
   fprintf (out, "LILYPOND_DATADIR=\"%s\"\n", LILYPOND_DATADIR);
-  if (char const *env = getenv ("LILYPONDPREFIX"))
-    fprintf (out, "LILYPONDPREFIX=\"%s\"\n", env);
+  env_var_info (out, "LILYPONDPREFIX");
   fprintf (out, "LOCALEDIR=\"%s\"\n", LOCALEDIR);
 
   fprintf (out, "\nEffective prefix: \"%s\"\n", prefix_directory.to_str0 ());
+
+#if ARGV0_RELOCATION
+  env_var_info (out, "FONTCONFIG_FILE");
+  env_var_info (out, "FONTCONFIG_PATH");
+  env_var_info (out, "GS_FONTPATH");
+  env_var_info (out, "GS_LIB");
+  env_var_info (out, "GUILE_LOAD_PATH");
+  env_var_info (out, "PANGO_RC_FILE");
+  env_var_info (out, "PATH");
+#endif  
 }
 
 static void
@@ -240,12 +256,87 @@ warranty ()
   printf (_ (WARRANTY).to_str0 ());
 }
 
+#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
+
+#ifdef __MINGW32__
+#  include <winbase.h>
+#endif
+
 static void
-setup_paths ()
+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);
+#ifdef __MINGW32__
+      char font_dir[PATH_MAX];
+      ExpandEnvironmentStrings ("%windir%/fonts", font_dir, sizeof (font_dir));
+      prepend_env_path ("GS_FONTPATH", font_dir);
+#endif
+      prepend_env_path ("GS_FONTPATH", datadir + "/gs/fonts");
+      prepend_env_path ("GS_LIB", datadir + "/gs/Resource");
+      prepend_env_path ("GS_LIB", datadir + "/gs/lib");
+      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/pangorc", false);
+      prepend_env_path ("PATH", bindir);
+    }
+#else
+  (void) argv0;
+#endif /* ARGV0_RELOCATION */
+    
   if (char const *env = getenv ("LILYPONDPREFIX"))
-    prefix_directory = env;
+    {
+#ifdef __MINGW32__
+      /* Normalize file name.  */
+      env = File_name (env).to_string ().get_copy_str0 ();
+#endif
+      prefix_directory = env;
+    }
 
   global_path.append ("");
 
@@ -420,9 +511,7 @@ main_with_guile (void *, int, char **)
       char const *str0 = init_scheme_code_string.to_str0 ();
       
       if (be_verbose_global)
-       {
-         progress_indication (_f("Evaluating %s", str0));
-       }
+       progress_indication (_f("Evaluating %s", str0));
       scm_c_eval_string ((char *) str0);
     }
 
@@ -594,14 +683,13 @@ int
 main (int argc, char **argv)
 {
   setup_localisation ();
-  setup_paths ();
+  setup_paths (argv[0]);
   parse_argv (argc, argv);
-  identify (stderr);
+  if (isatty (STDIN_FILENO))
+    identify (stderr);
 
   scm_boot_guile (argc, argv, main_with_guile, 0);
 
-  /*
-    If we get here, GUILE exited. This is an error.
-   */
+  /* Only reachable if GUILE exits.  That is an error.  */
   return 1;
 }