]> git.lyx.org Git - lyx.git/blobdiff - src/support/Package.cpp
TR1: check in cmake for GCC version, fallback in checktr1.h for other build systems...
[lyx.git] / src / support / Package.cpp
index 4c886029a50af679b1d2c4b23560e1923c7d4549..d947f9ae80a8996e095a5b5abb77483c4821e321 100644 (file)
@@ -73,7 +73,7 @@ Package const & package()
        // Commented out because package().locale_dir() can be called
        // from the message translation code in Messages.cpp before
        // init_package() is called. Lars is on the case...
-       // BOOST_ASSERT(initialised_);
+       // LASSERT(initialised_, /**/);
        return package_;
 }
 
@@ -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,
@@ -144,24 +139,33 @@ Package::Package(string const & command_line_arg0,
        explicit_user_support_dir_ = userSupportDir(default_user_support_dir,
                                     command_line_user_support_dir, user_support_dir_);
 
-       FileName const configure_script(addName(system_support().absFilename(), "configure.py"));
+       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"
-               << "\tbinary_dir " << binary_dir().absFilename() << '\n'
-               << "\tsystem_support " << system_support().absFilename() << '\n'
-               << "\tbuild_support " << build_support().absFilename() << '\n'
-               << "\tuser_support " << user_support().absFilename() << '\n'
-               << "\tlocale_dir " << locale_dir().absFilename() << '\n'
-               << "\tdocument_dir " << document_dir().absFilename() << '\n'
-               << "\ttemp_dir " << temp_dir().absFilename() << '\n'
-               << "\thome_dir " << home_dir().absFilename() << '\n'
+               << "\tbinary_dir " << binary_dir().absFileName() << '\n'
+               << "\tsystem_support " << system_support().absFileName() << '\n'
+               << "\tbuild_support " << build_support().absFileName() << '\n'
+               << "\tuser_support " << user_support().absFileName() << '\n'
+               << "\tlocale_dir " << locale_dir().absFileName() << '\n'
+               << "\tdocument_dir " << document_dir().absFileName() << '\n'
+               << "\ttemp_dir " << temp_dir().absFileName() << '\n'
+               << "\thome_dir " << home_dir().absFileName() << '\n'
                << "</package>\n");
 }
 
 
+void Package::set_temp_dir(FileName const & temp_dir) const
+{
+       if (temp_dir.empty())
+               temp_dir_ = system_temp_dir_;
+       else
+               temp_dir_ = temp_dir;
+}
+
+
 namespace {
 
 // These next functions contain the stuff that is substituted at
@@ -266,17 +270,14 @@ void buildDirs(FileName const & abs_binary,
        FileName binary = 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, "../");
+               string binary_dir = onlyPath(binary.absFileName());
                build_support_dir = buildSupportDir(binary_dir, top_build_dir_location);
-               if (!fileSearch(build_support_dir.absFilename(), "Makefile").empty()) {
+               if (!fileSearch(build_support_dir.absFileName(), "Makefile").empty()) {
                        // Try and find "chkconfig.ltx".
                        system_support_dir =
-                               FileName(addPath(Package::top_srcdir().absFilename(), "lib"));
+                               FileName(addPath(Package::top_srcdir().absFileName(), "lib"));
 
-                       if (!fileSearch(system_support_dir.absFilename(), "chkconfig.ltx").empty()) {
+                       if (!fileSearch(system_support_dir.absFileName(), "chkconfig.ltx").empty()) {
                                LYXERR(Debug::INIT, check_text << " yes");
                                return;
                        }
@@ -343,7 +344,7 @@ FileName const get_locale_dir(FileName const & system_support_dir)
        // 2. Search for system_support_dir / <relative locale dir>
        // The <relative locale dir> is OS-dependent. (On Unix, it will
        // be "../locale/".)
-       FileName path(addPath(system_support_dir.absFilename(),
+       FileName path(addPath(system_support_dir.absFileName(),
                relative_locale_dir()));
 
        if (path.exists() && path.isDirectory())
@@ -358,29 +359,14 @@ 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);
-       return FileName(to_utf8(from_local8bit(path)));
-#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)
 {
        if (command_line.empty())
                return FileName();
 
-       string const path = fix_dir_name(command_line);
-       return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path);
+       string const str_path = fix_dir_name(command_line);
+       return makeAbsPath(str_path);
 }
 
 
@@ -397,7 +383,7 @@ FileName const get_binary_path(string const & exe)
 #else
        string const exe_path = os::internal_path(exe);
 #endif
-       if (os::is_absolute_path(exe_path))
+       if (FileName::isAbsolute(exe_path))
                return FileName(exe_path);
 
        // Two possibilities present themselves.
@@ -408,7 +394,7 @@ FileName const get_binary_path(string const & exe)
 
        // 2. exe must be the name of the binary only and it
        // can be found on the PATH.
-       string const exe_name = onlyFilename(exe_path);
+       string const exe_name = onlyFileName(exe_path);
        if (exe_name != exe_path)
                return FileName();
 
@@ -417,7 +403,7 @@ FileName const get_binary_path(string const & exe)
        vector<string>::const_iterator const end = path.end();
        for (; it != end; ++it) {
                // This will do nothing if *it is already absolute.
-               string const exe_dir = makeAbsPath(*it).absFilename();
+               string const exe_dir = makeAbsPath(*it).absFileName();
 
                FileName const exe_path(addName(exe_dir, exe_name));
                if (exe_path.exists())
@@ -461,15 +447,15 @@ get_system_support_dir(FileName const & abs_binary,
        FileName path = abs_path_from_command_line(command_line_system_support_dir);
        if (!path.empty()) {
                searched_dirs.push_back(path);
-               if (check_command_line_dir(path.absFilename(), chkconfig_ltx, "-sysdir"))
+               if (check_command_line_dir(path.absFileName(), chkconfig_ltx, "-sysdir"))
                        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;
        }
 
@@ -485,12 +471,12 @@ get_system_support_dir(FileName const & abs_binary,
        FileName binary = abs_binary;
        while (true) {
                // Try and find "chkconfig.ltx".
-               string const binary_dir = onlyPath(binary.absFilename());
+               string const binary_dir = onlyPath(binary.absFileName());
 
                FileName const lyxdir(addPath(binary_dir, relative_lyxdir));
                searched_dirs.push_back(lyxdir);
 
-               if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
+               if (!fileSearch(lyxdir.absFileName(), chkconfig_ltx).empty()) {
                        // Success! "chkconfig.ltx" has been found.
                        return lyxdir;
                }
@@ -510,7 +496,7 @@ get_system_support_dir(FileName const & abs_binary,
        }
 
        // 4. Repeat the exercise on the directory itself.
-       FileName binary_dir(onlyPath(abs_binary.absFilename()));
+       FileName binary_dir(onlyPath(abs_binary.absFileName()));
        while (true) {
                // This time test whether the directory is a symbolic link
                // *before* looking for "chkconfig.ltx".
@@ -527,11 +513,11 @@ get_system_support_dir(FileName const & abs_binary,
                }
 
                // Try and find "chkconfig.ltx".
-               FileName const lyxdir(addPath(binary_dir.absFilename(),
+               FileName const lyxdir(addPath(binary_dir.absFileName(),
                        relative_lyxdir));
                searched_dirs.push_back(lyxdir);
 
-               if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
+               if (!fileSearch(lyxdir.absFileName(), chkconfig_ltx).empty()) {
                        // Success! "chkconfig.ltx" has been found.
                        return lyxdir;
                }
@@ -539,7 +525,7 @@ get_system_support_dir(FileName const & abs_binary,
 
        // 5. In desparation, try the hard-coded system support dir.
        path = hardcoded_system_support_dir();
-       if (!fileSearch(path.absFilename(), chkconfig_ltx).empty())
+       if (!fileSearch(path.absFileName(), chkconfig_ltx).empty())
                return path;
 
        // Everything has failed :-(
@@ -551,19 +537,19 @@ get_system_support_dir(FileName const & abs_binary,
        for (iterator it = begin; it != end; ++it) {
                if (it != begin)
                        searched_dirs_str += "\n\t";
-               searched_dirs_str += it->absFilename();
+               searched_dirs_str += it->absFileName();
        }
 
        // 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();
@@ -581,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;
 
@@ -623,13 +609,13 @@ FileName const get_default_user_support_dir(FileName const & home_dir)
        return FileName(addPath(reinterpret_cast<char const *>(store), PACKAGE));
 
 #else // USE_POSIX_PACKAGING
-       return FileName(addPath(home_dir.absFilename(), string(".") + PACKAGE));
+       return FileName(addPath(home_dir.absFileName(), string(".") + PACKAGE));
 #endif
 }
 
 
 // Check that directory @c dir contains @c file.
-// Else emit a warning about an invalid @c command_line_switch.
+// Else emit an error message about an invalid @c command_line_switch.
 bool check_command_line_dir(string const & dir,
                            string const & file,
                            string const & command_line_switch)
@@ -637,7 +623,7 @@ bool check_command_line_dir(string const & dir,
        FileName const abs_path = fileSearch(dir, file);
        if (abs_path.empty()) {
                // FIXME UNICODE
-               throw ExceptionMessage(WarningException, _("File not found"), bformat(
+               throw ExceptionMessage(ErrorException, _("File not found"), bformat(
                        _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
                        from_utf8(command_line_switch), from_utf8(dir),
                        from_utf8(file)));
@@ -661,13 +647,13 @@ bool check_env_var_dir(FileName const & dir,
                       string const & file,
                       string const & env_var)
 {
-       FileName const abs_path = fileSearch(dir.absFilename(), file);
+       FileName const abs_path = fileSearch(dir.absFileName(), file);
        if (abs_path.empty()) {
                // FIXME UNICODE
                throw ExceptionMessage(WarningException, _("File not found"), bformat(
                        _("Invalid %1$s environment variable.\n"
                                "Directory %2$s does not contain %3$s."),
-                       from_utf8(env_var), from_utf8(dir.absFilename()),
+                       from_utf8(env_var), from_utf8(dir.absFileName()),
                        from_utf8(file)));
        }
 
@@ -692,7 +678,7 @@ bool check_env_var_dir(FileName const & dir,
                        _("Invalid %1$s environment variable.\n%2$s is not a directory.");
 
                throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
-                       fmt, from_utf8(env_var), from_utf8(dir.absFilename())));
+                       fmt, from_utf8(env_var), from_utf8(dir.absFileName())));
        }
 
        return success;