]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/relocate.cc
robust_scm2fraction
[lilypond.git] / lily / relocate.cc
index 64092fcc889c8518c8d12a1a9db7f94f933bb7d1..47502f7dbda9f054f9524c0587763cf5b26bc91b 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
 */
 
@@ -32,7 +32,6 @@
 
 #define FRAMEWORKDIR ".."
 
-
 int
 sane_putenv (char const *key, string value, bool overwrite)
 {
@@ -40,7 +39,17 @@ sane_putenv (char const *key, string value, bool overwrite)
     {
       string combine = string (key) + "=" + value;
       char *s = strdup (combine.c_str ());
-      return putenv (s);
+
+      if (be_verbose_global)
+       progress_indication (_f ("Setting %s to %s" , key, value.c_str ())
+                            + "\n");
+                            
+      int retval =  putenv (s);
+      /*
+       unfortunately, we can't portably free S here,
+       due to various bugs in glibc prior to 2.1.1
+       */ 
+      return retval;
     }
   
   return -1;
@@ -114,65 +123,28 @@ prefix_relocation (string prefix)
   prepend_env_path ("PATH", bindir);
 }
 
+/*
+  UGH : this is a complete mess.
+ */
+
 void
 framework_relocation (string prefix)
 {
   if (be_verbose_global)
     warning (_f ("Relocation: framework_prefix=%s", prefix));
 
-  sane_putenv ("INSTALLER_ROOT", prefix, true);
+  sane_putenv ("INSTALLER_PREFIX", prefix, true);
               
   read_relocation_dir (prefix + "/etc/relocate/");
 
-#ifdef OLD_RELOCATION
   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_FONTPATH", font_dir);
-#endif
-
-  string gs_version =
-#ifdef GHOSTSCRIPT_VERSION
-    GHOSTSCRIPT_VERSION
-#else
-    "ghostscript-version-undefined"
-#endif
-    ;
-  
-  if (char const *cur = getenv ("LILYPOND_GS_VERSION"))
-    gs_version = cur;
-  
-  prepend_env_path ("GS_FONTPATH", datadir + "/ghostscript/" + gs_version + "/fonts");
-  prepend_env_path ("GS_LIB", datadir + "/ghostscript/" + gs_version + "/Resource");
-  prepend_env_path ("GS_LIB", datadir + "/ghostscript/" + gs_version + "/lib");
-
-  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));
-  set_env_file ("PANGO_RC_FILE", sysconfdir + "/pango/pangorc");
-  set_env_dir ("PANGO_PREFIX", prefix);
-
-#endif
-  
   
   prepend_env_path ("PATH", bindir);
 }
 
+/*
+  UGH : this is a complete mess.
+ */
 void
 setup_paths (char const *argv0_ptr)
 {
@@ -182,13 +154,14 @@ setup_paths (char const *argv0_ptr)
   if (relocate_binary
       && getenv ("LILYPOND_RELOCATE_PREFIX"))
     {
-      string prefix = getenv ("LILYPOND_RELOCATE_PREFIX");
+      prefix_directory = getenv ("LILYPOND_RELOCATE_PREFIX");
 #ifdef __MINGW32__
       /* Normalize file name.  */
-      prefix = File_name (prefix).to_string ();
+      prefix_directory = File_name (prefix_directory).to_string ();
 #endif /* __MINGW32__ */
-      prefix_relocation (prefix);
-      string bindir = prefix + "/bin";
+      
+      prefix_relocation (prefix_directory);
+      string bindir = prefix_directory + "/bin";
       framework_relocation (bindir);
     }
   else if (relocate_binary)
@@ -225,22 +198,27 @@ setup_paths (char const *argv0_ptr)
 #endif /* __MINGW32__ */
 
          if (argv0_abs.empty ())
-           programming_error ("can't find absolute argv0.");
+           programming_error ("cannot find absolute argv0");
        }
 
       string bindir = dir_name (argv0_abs);
       string argv0_prefix = dir_name (bindir);
       string compile_prefix = dir_name (dir_name (dir_name (prefix_directory)));
       if (argv0_prefix != compile_prefix)
-       prefix_relocation (argv0_prefix);
+       {
+         prefix_relocation (argv0_prefix);
+         prefix_directory = argv0_prefix;
+       }
       if (argv0_prefix != compile_prefix || string (FRAMEWORKDIR) != "..")
-       framework_relocation (bindir + "/" + FRAMEWORKDIR);
+       {
+         framework_relocation (bindir + "/" + FRAMEWORKDIR);
+         prefix_directory = bindir + "/" + FRAMEWORKDIR;
+       }
     }
 
   /* FIXME: use LILYPOND_DATADIR.  */
   if (char const *env = getenv ("LILYPONDPREFIX"))
     {
-
 #ifdef __MINGW32__
       /* Normalize file name.  */
       prefix_directory = File_name (env).to_string ();
@@ -255,11 +233,7 @@ setup_paths (char const *argv0_ptr)
   /*
     When running from build dir, a full LILYPOND_PREFIX is set-up at
 
-        $(OUTBASE)/share/lilypond/TOPLEVEL_VERSION
-
-     This historical hack will allow the shorthand
-
-        LILYPONDPREFIX=out lily/out/lilypond ...
+        $(OUTBASE)/{share,lib}/lilypond/current
 
   */
   
@@ -377,10 +351,14 @@ read_line (FILE *f)
 void
 read_relocation_file (string filename)
 {
+  if (be_verbose_global)
+    progress_indication (_f ("Relocation file: %s", filename.c_str ())
+                        + "\n");
+      
   char const *cname = filename.c_str ();
   FILE *f = fopen (cname, "r");
   if (!f)
-    error (_f ("can't open file %s", cname));
+    error (_f ("cannot open file: `%s'", cname));
 
   while (!feof (f))
     {
@@ -410,7 +388,7 @@ read_relocation_file (string filename)
       else if (command == "prependdir")
        prepend_env_path (variable.c_str (), value);
       else
-       error ( _f("Unknown relocation command %s", command));
+       error (_f ("Unknown relocation command %s", command));
     }
 
   fclose (f);
@@ -419,14 +397,11 @@ read_relocation_file (string filename)
 void
 read_relocation_dir (string dirname)
 {
-  DIR *dir = opendir  (dirname.c_str ());
-
-  while (struct dirent *ent = readdir (dir))
-    {
-      File_name name (ent->d_name);
-      if (name.ext_ == "reloc")
-       {
-         read_relocation_file (name.to_string ());
-       }
-    }
+  if (DIR *dir = opendir (dirname.c_str ()))
+    while (struct dirent *ent = readdir (dir))
+      {
+       File_name name (ent->d_name);
+       if (name.ext_ == "reloc")
+           read_relocation_file (dirname + "/" + name.to_string ());
+      }
 }