]> git.lyx.org Git - lyx.git/blobdiff - src/support/Package.cpp
CMake: fix merged build, seems GCC could not handle the namespaces correctly
[lyx.git] / src / support / Package.cpp
index 10134a414d70beb56b1fa0d786227ea13e0b59e9..138f06b9eefb0a89733a062bab5e50195e7ac7b5 100644 (file)
@@ -95,8 +95,6 @@ FileName const get_locale_dir(FileName const & system_support_dir);
 FileName const get_system_support_dir(FileName const & abs_binary,
                                    string const & command_line_system_support_dir);
 
-FileName const get_temp_dir();
-
 FileName const get_default_user_support_dir(FileName const & home_dir);
 
 bool userSupportDir(FileName const & default_user_support_dir,
@@ -115,17 +113,14 @@ Package::Package(string const & command_line_arg0,
        : explicit_user_support_dir_(false)
 {
        home_dir_ = get_home_dir();
-       system_temp_dir_ = get_temp_dir();
+       // Specification of temp_dir_ may be reset by LyXRC,
+       // but the default is fixed for a given OS.
+       system_temp_dir_ = FileName::tempPath();
        temp_dir_ = system_temp_dir_;
        document_dir_ = get_document_dir(home_dir_);
 
        FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
-       string const bdir = onlyPath(abs_binary.absFilename());
-       // We may be using libtools
-       if (suffixIs(bdir, ".libs/"))
-               binary_dir_ = FileName(addPath(bdir, "../"));
-       else
-               binary_dir_ = FileName(bdir);
+       binary_dir_ = FileName(onlyPath(abs_binary.absFilename()));
 
        // Is LyX being run in-place from the build tree?
        buildDirs(abs_binary, top_build_dir_location,
@@ -146,7 +141,7 @@ Package::Package(string const & command_line_arg0,
 
        FileName const configure_script(addName(system_support().absFilename(), "configure.py"));
        configure_command_ = os::python() + ' ' +
-                       quoteName(configure_script.toFilesystemEncoding()) +
+                       quoteName(configure_script.toFilesystemEncoding(), quote_python) +
                        with_version_suffix();
 
        LYXERR(Debug::INIT, "<package>\n"
@@ -276,9 +271,6 @@ void buildDirs(FileName const & abs_binary,
        while (true) {
                // Try and find "lyxrc.defaults".
                string binary_dir = onlyPath(binary.absFilename());
-               // We may be using libtools with static linking.
-               if (suffixIs(binary_dir, ".libs/"))
-                       binary_dir = addPath(binary_dir, "../");
                build_support_dir = buildSupportDir(binary_dir, top_build_dir_location);
                if (!fileSearch(build_support_dir.absFilename(), "Makefile").empty()) {
                        // Try and find "chkconfig.ltx".
@@ -367,25 +359,6 @@ FileName const get_locale_dir(FileName const & system_support_dir)
 }
 
 
-// Specification of temp_dir_ may be reset by LyXRC,
-// but the default is fixed for a given OS.
-FileName const get_temp_dir()
-{
-#if defined (USE_WINDOWS_PACKAGING)
-       // Typical example: C:/TEMP/.
-       char path[MAX_PATH];
-       GetTempPath(MAX_PATH, path);
-       string tmp = to_utf8(from_local8bit(path));
-       size_t const size = tmp.size();
-       if (size && (tmp[size - 1] == '/' || tmp[size - 1] == '\\'))
-               tmp.erase(size - 1, 1);
-       return FileName(tmp);
-#else // Posix-like.
-       return FileName("/tmp");
-#endif
-}
-
-
 // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
 FileName const abs_path_from_command_line(string const & command_line)
 {
@@ -393,8 +366,7 @@ FileName const abs_path_from_command_line(string const & command_line)
                return FileName();
 
        string const str_path = fix_dir_name(command_line);
-       FileName path(str_path);
-       return path.isAbsolute() ? path : makeAbsPath(str_path);
+       return makeAbsPath(str_path);
 }
 
 
@@ -411,9 +383,8 @@ FileName const get_binary_path(string const & exe)
 #else
        string const exe_path = os::internal_path(exe);
 #endif
-       FileName exepath(exe_path);
-       if (exepath.isAbsolute())
-               return exepath;
+       if (FileName::isAbsolute(exe_path))
+               return FileName(exe_path);
 
        // Two possibilities present themselves.
        // 1. The binary is relative to the CWD.
@@ -480,11 +451,11 @@ get_system_support_dir(FileName const & abs_binary,
                        return path;
        }
 
-       // 2. Use the "LYX_DIR_15x" environment variable.
-       path = extract_env_var_dir("LYX_DIR_15x");
+       // 2. Use the "LYX_DIR_${major}${minor}x" environment variable.
+       path = extract_env_var_dir(LYX_DIR_VER);
        if (!path.empty()) {
                searched_dirs.push_back(path);
-               if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_15x"))
+               if (check_env_var_dir(path, chkconfig_ltx, LYX_DIR_VER))
                        return path;
        }
 
@@ -572,13 +543,13 @@ get_system_support_dir(FileName const & abs_binary,
        // FIXME UNICODE
        throw ExceptionMessage(ErrorException, _("No system directory"),
                bformat(_("Unable to determine the system directory "
-                                        "having searched\n"
-                                        "\t%1$s\n"
-                                        "Use the '-sysdir' command line parameter or "
-                                        "set the environment variable LYX_DIR_15x to "
-                                        "the LyX system directory containing the file "
-                                        "`chkconfig.ltx'."),
-                         from_utf8(searched_dirs_str)));
+                               "having searched\n"
+                               "\t%1$s\n"
+                               "Use the '-sysdir' command line parameter or "
+                               "set the environment variable\n%2$s "
+                               "to the LyX system directory containing the "
+                               "file `chkconfig.ltx'."),
+                         from_utf8(searched_dirs_str), from_ascii(LYX_DIR_VER)));
 
        // Keep the compiler happy.
        return FileName();
@@ -596,8 +567,8 @@ bool userSupportDir(FileName const & default_user_support_dir,
        if (!result.empty())
                return true;
 
-       // 2. Use the LYX_USERDIR_15x environment variable.
-       result = extract_env_var_dir("LYX_USERDIR_15x");
+       // 2. Use the LYX_USERDIR_${major}${minor}x environment variable.
+       result = extract_env_var_dir(LYX_USERDIR_VER);
        if (!result.empty())
                return true;