]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/relocate.cc
Run `make grand-replace'.
[lilypond.git] / lily / relocate.cc
index 635b4165c9b2039bdda7fe8654795665ff81beaa..fd6cf85c458f2fbac7dd76ae8c3bae1f8c8b3714 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
 */
 
@@ -48,7 +48,7 @@ sane_putenv (char const *key, string value, bool overwrite)
       /*
        unfortunately, we can't portably free S here,
        due to various bugs in glibc prior to 2.1.1
-       */ 
+      */ 
       return retval;
     }
   
@@ -97,37 +97,41 @@ prepend_env_path (char const *key, string value)
 #include <winbase.h>
 #endif
 
-void
+static void
 prefix_relocation (string prefix)
 {
-  if (be_verbose_global)
-    warning (_f ("Relocation: compile prefix=%s, new prefix=%s",
-                prefix_directory,
-                prefix.c_str ()));
-  
   string bindir = prefix + "/bin";
   string datadir = prefix + "/share";
   string localedir = datadir + "/locale";
-  string lilypond_datadir = datadir + "/lilypond/";
-
-  if (is_dir (lilypond_datadir + "/" + TOPLEVEL_VERSION))
-    prefix_directory = lilypond_datadir + "/" + TOPLEVEL_VERSION;
-  else if (is_dir (lilypond_datadir + "/current"))
-    prefix_directory = lilypond_datadir + "/current";
-
+  string package_datadir = datadir + "/lilypond/";
+  string old_lilypond_datadir = lilypond_datadir;
+
+  if (is_dir (package_datadir + "/" + TOPLEVEL_VERSION))
+    lilypond_datadir = package_datadir + "/" + TOPLEVEL_VERSION;
+  else if (is_dir (package_datadir + "/current"))
+    lilypond_datadir = package_datadir + "/current";
+  else
+    warning (_f ("not relocating, no %s/ or current/ found under %s",
+                TOPLEVEL_VERSION, package_datadir.c_str ()));
+  
 #if HAVE_GETTEXT
   if (is_dir (localedir))
     bindtextdomain ("lilypond", localedir.c_str ());
 #endif
 
   prepend_env_path ("PATH", bindir);
+
+  if (be_verbose_global)
+    warning (_f ("Relocation: compile datadir=%s, new datadir=%s",
+                old_lilypond_datadir.c_str (),
+                lilypond_datadir.c_str ()));
 }
 
 /*
   UGH : this is a complete mess.
- */
+*/
 
-void
+static void
 framework_relocation (string prefix)
 {
   if (be_verbose_global)
@@ -144,106 +148,105 @@ framework_relocation (string prefix)
 
 /*
   UGH : this is a complete mess.
- */
+*/
 void
 setup_paths (char const *argv0_ptr)
 {
   File_name argv0_filename (argv0_ptr);
   
-  prefix_directory = LILYPOND_DATADIR;
-  if (relocate_binary
-      && getenv ("LILYPOND_RELOCATE_PREFIX"))
+  if (relocate_binary)
     {
-      prefix_directory = getenv ("LILYPOND_RELOCATE_PREFIX");
+      string prefix_directory;
+      if (getenv ("LILYPOND_RELOCATE_PREFIX"))
+       {
+         prefix_directory = getenv ("LILYPOND_RELOCATE_PREFIX");
 #ifdef __MINGW32__
-      /* Normalize file name.  */
-      prefix_directory = File_name (prefix_directory).to_string ();
+         /* Normalize file name.  */
+         prefix_directory = File_name (prefix_directory).to_string ();
 #endif /* __MINGW32__ */
       
-      prefix_relocation (prefix_directory);
-      string bindir = prefix_directory + "/bin";
-      framework_relocation (bindir);
-    }
-  else if (relocate_binary)
-    {
-      string argv0_abs;
-      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));
+         prefix_relocation (prefix_directory);
+         string bindir = prefix_directory + "/bin";
+         framework_relocation (bindir);
        }
-      else
+      else if (relocate_binary)
        {
-         /* Find absolute ARGV0 name, using PATH.  */
-         File_path path;
-         path.parse_path (getenv ("PATH"));
+         string argv0_abs;
+         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 ().c_str (), argv0_ptr));
+             if (be_verbose_global)
+               warning (_f ("Relocation: from PATH=%s\nargv0=%s",
+                            path.to_string ().c_str (), argv0_ptr));
 
 #ifndef __MINGW32__
-         argv0_abs = path.find (argv0_filename.to_string ());
+             argv0_abs = path.find (argv0_filename.to_string ());
 #else /* __MINGW32__ */
-         char const *ext[] = {"exe", "", 0 };
-         argv0_abs = path.find (argv0_filename.to_string (), ext);
+             char const *ext[] = {"exe", "", 0 };
+             argv0_abs = path.find (argv0_filename.to_string (), ext);
 #endif /* __MINGW32__ */
 
-         if (argv0_abs.empty ())
-           programming_error ("cannot find absolute argv0");
-       }
+             if (argv0_abs.empty ())
+               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_directory = argv0_prefix;
-       }
-      if (argv0_prefix != compile_prefix || string (FRAMEWORKDIR) != "..")
-       {
-         framework_relocation (bindir + "/" + FRAMEWORKDIR);
-         prefix_directory = bindir + "/" + FRAMEWORKDIR;
+         string bindir = dir_name (argv0_abs);
+         string argv0_prefix = dir_name (bindir);
+         string compile_prefix = dir_name (dir_name (dir_name (lilypond_datadir)));
+         if (argv0_prefix != compile_prefix)
+           {
+             prefix_relocation (argv0_prefix);
+             prefix_directory = argv0_prefix;
+           }
+         if (argv0_prefix != compile_prefix || string (FRAMEWORKDIR) != "..")
+           {
+             framework_relocation (bindir + "/" + FRAMEWORKDIR);
+             prefix_directory = bindir + "/" + FRAMEWORKDIR;
+           }
        }
+
+      lilypond_datadir = prefix_directory
+       + "/share/lilypond/" TOPLEVEL_VERSION;
     }
 
-  /* FIXME: use LILYPOND_DATADIR.  */
-  if (char const *env = getenv ("LILYPONDPREFIX"))
+  if (getenv ("LILYPONDPREFIX"))
+    error (_ ("LILYPONDPREFIX is obsolete, use LILYPOND_DATADIR"));
+
+  if (char const *env = getenv ("LILYPOND_DATADIR"))
     {
-#ifdef __MINGW32__
       /* Normalize file name.  */
-      prefix_directory = File_name (env).to_string ();
-#else
-      prefix_directory = env;
-#endif
+      lilypond_datadir = File_name (env).to_string ();
     }
 
-  global_path.append ("");
-
+  /* When running from build dir, a full LILYPOND_DATADIR is set-up at
+     $(OUTBASE)/{share, lib}/lilypond/current.  Configure lily using
+     ./configure --prefix=$(pwd)/out */
+  string build_datadir_current = dir_name (lilypond_datadir) + "/current";
+  if (!is_dir (lilypond_datadir.c_str ())
+      && is_dir (build_datadir_current.c_str ()))
+    lilypond_datadir = build_datadir_current;
 
-  /*
-    When running from build dir, a full LILYPOND_PREFIX is set-up at
 
-        $(OUTBASE)/{share, lib}/lilypond/current
-
-  */
-  
-  string build_prefix_current = prefix_directory + "/share/lilypond/" "current";
-  string build_prefix_version = prefix_directory + "/share/lilypond/" TOPLEVEL_VERSION;
-  if (is_dir (build_prefix_version.c_str ()))
-    prefix_directory = build_prefix_version;
-  else if (is_dir (build_prefix_current.c_str ()))
-    prefix_directory = build_prefix_current;
+  lilypond_datadir = File_name (lilypond_datadir).canonicalized().to_string();
   
+  global_path.append ("");
+
   /* Adding mf/out make lilypond unchanged source directory, when setting
      LILYPONDPREFIX to lilypond-x.y.z */
   char const *suffixes[] = {"ly", "ps", "scm", 0 };
@@ -251,20 +254,18 @@ setup_paths (char const *argv0_ptr)
   vector<string> dirs;
   for (char const **s = suffixes; *s; s++)
     {
-      string path = prefix_directory + to_string ('/') + string (*s);
+      string path = lilypond_datadir + to_string ('/') + string (*s);
       dirs.push_back (path);
     }
   
-  dirs.push_back (prefix_directory + "/fonts/otf/");
-  dirs.push_back (prefix_directory + "/fonts/type1/");
-  dirs.push_back (prefix_directory + "/fonts/svg/");
+  dirs.push_back (lilypond_datadir + "/fonts/otf/");
+  dirs.push_back (lilypond_datadir + "/fonts/type1/");
+  dirs.push_back (lilypond_datadir + "/fonts/svg/");
   
   for (vsize i = 0; i < dirs.size (); i++)
     global_path.prepend (dirs[i]);
 }
 
-
-
 string
 expand_environment_variables (string orig)
 {
@@ -306,7 +307,7 @@ expand_environment_variables (string orig)
            {
              /*
                Hmm. what to do for $1 , $~ etc.?
-              */
+             */
              do
                {
                  end_var ++;
@@ -335,15 +336,15 @@ expand_environment_variables (string orig)
   return out;
 }
 
-
-string
+// Ugh - very inefficient, but safer than fgets.
+static string
 read_line (FILE *f)
 {
   string out;
   
   int c = 0;
   while ((c = fgetc (f)) != EOF && c != '\n')
-    out += c;
+    out += char(c);
 
   return out;
 }
@@ -402,6 +403,6 @@ read_relocation_dir (string dirname)
       {
        File_name name (ent->d_name);
        if (name.ext_ == "reloc")
-           read_relocation_file (dirname + "/" + name.to_string ());
+         read_relocation_file (dirname + "/" + name.to_string ());
       }
 }