]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/relocate.cc
Merge tag 'upstream/2.18.0' into debian-experimental
[lilypond.git] / lily / relocate.cc
index 2f314f1063dd959ff43d60648fdb851e1505af01..bf670edb1502b0b9d47b430ba379293297862a01 100644 (file)
@@ -44,7 +44,7 @@
 #define FRAMEWORKDIR ".."
 
 int
-sane_putenv (char const *key, string value, bool overwrite)
+sane_putenv (char const *key, const string &value, bool overwrite)
 {
   if (overwrite || !getenv (key))
     {
@@ -66,7 +66,7 @@ sane_putenv (char const *key, string value, bool overwrite)
 }
 
 static int
-set_env_file (char const *key, string value, bool overwrite = false)
+set_env_file (char const *key, const string &value, bool overwrite = false)
 {
   if (is_file (value))
     return sane_putenv (key, value, overwrite);
@@ -77,7 +77,7 @@ set_env_file (char const *key, string value, bool overwrite = false)
 }
 
 static int
-set_env_dir (char const *key, string value)
+set_env_dir (char const *key, const string &value)
 {
   if (is_dir (value))
     return sane_putenv (key, value, false);
@@ -110,7 +110,7 @@ prepend_env_path (char const *key, string value)
 #endif
 
 static void
-prefix_relocation (string prefix)
+prefix_relocation (const string &prefix)
 {
   string bindir = prefix + "/bin";
   string datadir = prefix + "/share";
@@ -143,7 +143,7 @@ prefix_relocation (string prefix)
 */
 
 static void
-framework_relocation (string prefix)
+framework_relocation (const string &prefix)
 {
   debug_output (_f ("Relocation: framework_prefix=%s", prefix));
 
@@ -167,66 +167,51 @@ setup_paths (char const *argv0_ptr)
   if (relocate_binary)
     {
       string prefix_directory;
-      if (getenv ("LILYPOND_RELOCATE_PREFIX"))
+      string argv0_abs;
+      if (argv0_filename.is_absolute ())
         {
-          prefix_directory = getenv ("LILYPOND_RELOCATE_PREFIX");
-#ifdef __MINGW32__
-          /* 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);
+          argv0_abs = argv0_filename.to_string ();
+          debug_output (_f ("Relocation: is absolute: argv0=%s\n", argv0_ptr));
         }
-      else if (relocate_binary)
+      else if (argv0_filename.dir_.length ())
         {
-          string argv0_abs;
-          if (argv0_filename.is_absolute ())
-            {
-              argv0_abs = argv0_filename.to_string ();
-              debug_output (_f ("Relocation: is absolute: argv0=%s\n", argv0_ptr));
-            }
-          else if (argv0_filename.dir_.length ())
-            {
-              argv0_abs = get_working_directory ()
-                          + "/" + string (argv0_filename.to_string ());
-              debug_output (_f ("Relocation: from cwd: argv0=%s\n", argv0_ptr));
-            }
-          else
-            {
-              /* Find absolute ARGV0 name, using PATH.  */
-              File_path path;
-              path.parse_path (getenv ("PATH"));
+          argv0_abs = get_working_directory ()
+                      + "/" + string (argv0_filename.to_string ());
+          debug_output (_f ("Relocation : from cwd: argv0=%s\n", argv0_ptr));
+        }
+      else
+        {
+          /* Find absolute ARGV0 name, using PATH.  */
+          File_path path;
+          path.parse_path (getenv ("PATH"));
 
 #ifndef __MINGW32__
-              argv0_abs = path.find (argv0_filename.to_string ());
+          argv0_abs = path.find (argv0_filename.to_string ());
 #else /* __MINGW32__ */
-              path.prepend (get_working_directory ());
-              char const *ext[] = {"exe", "", 0 };
-              argv0_abs = path.find (argv0_filename.to_string (), ext);
+          path.prepend (get_working_directory ());
+          char const *ext[] = {"exe", "", 0 };
+          argv0_abs = path.find (argv0_filename.to_string (), ext);
 #endif /* __MINGW32__ */
 
-              debug_output (_f ("Relocation: from PATH=%s\nargv0=%s",
-                                path.to_string ().c_str (), argv0_ptr), true);
+          debug_output (_f ("Relocation: from PATH=%s\nargv0=%s\n",
+                            path.to_string ().c_str (), argv0_ptr), true);
 
-              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 (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;
-            }
+      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
@@ -274,7 +259,7 @@ setup_paths (char const *argv0_ptr)
 }
 
 string
-expand_environment_variables (string orig)
+expand_environment_variables (const string &orig)
 {
   char const *start_ptr = orig.c_str ();
   char const *ptr = orig.c_str ();
@@ -357,7 +342,7 @@ read_line (FILE *f)
 }
 
 void
-read_relocation_file (string filename)
+read_relocation_file (const string &filename)
 {
   debug_output (_f ("Relocation file: %s", filename.c_str ()) + "\n");
   char const *cname = filename.c_str ();
@@ -400,7 +385,7 @@ read_relocation_file (string filename)
 }
 
 void
-read_relocation_dir (string dirname)
+read_relocation_dir (const string &dirname)
 {
   if (DIR *dir = opendir (dirname.c_str ()))
     while (struct dirent *ent = readdir (dir))