4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
11 * Warning! This file is autogenerated from path_defines.C.in.
12 * All changes to this file will be lost.
17 #include "path_defines.h"
23 #include "filetools.h"
37 /* The absolute path to the system-level lyx support files.
38 * (Compile-time value.)
40 string const & lyx_dir()
42 static string const ld = "%LYX_DIR%";
47 /* The absolute path to the top of the lyx build tree.
48 * (Compile-time value.)
50 string const & lyx_top_srcdir()
52 static string const lts = "%TOP_SRCDIR%";
57 /* The absolute path to the system-level lyx locale directory.
58 * (Compile-time value.)
60 string const & lyx_localedir()
62 static string const ll = "%LOCALEDIR%";
75 // Determine path of binary
78 string binpath = os::binpath();
79 string binname = os::binname();
80 string fullbinname = MakeAbsPath(binname, binpath);
82 if (binpath.empty()) {
83 lyxerr << _("Warning: could not determine path of binary.")
85 << _("If you have problems, try starting LyX with an absolute path.")
88 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
89 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
92 // Determine system directory.
95 // Directories are searched in this order:
96 // 1) -sysdir command line parameter
97 // 2) LYX_DIR_14x environment variable
98 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
99 // 4) <path of binary>/../share/<name of binary>/
100 // 4a) repeat 4 after following the Symlink if <path of
101 // binary> is a symbolic link.
102 // 5) hardcoded lyx_dir
103 // The directory is checked for the presence of the file
104 // "chkconfig.ltx", and if that is present, the directory
105 // is accepted as the system directory.
106 // If no chkconfig.ltx file is found, a warning is given,
107 // and the hardcoded lyx_dir is used.
109 // If we had a command line switch, system_lyxdir is already set
111 if (!system_lyxdir.empty())
112 searchpath = MakeAbsPath(system_lyxdir) + ';';
114 string const lyxdir = GetEnvPath("LYX_DIR_14x");
116 if (!lyxdir.empty()) {
117 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
118 searchpath += lyxdir + ';';
121 string fullbinpath = binpath;
122 FileInfo file(fullbinname, true);
124 lyxerr[Debug::INIT] << "binary is a link" << endl;
126 if (LyXReadLink(fullbinname, link, true)) {
127 // Path of binary/../share/name of binary/
128 searchpath += NormalizePath(AddPath(binpath,
130 + OnlyFilename(binname));
133 binpath = MakeAbsPath(OnlyPath(fullbinpath));
139 // Path of binary/../share/name of binary/
140 searchpath += NormalizePath(AddPath(binpath, "../share/") +
141 OnlyFilename(binname)) + ';';
144 FileInfo file(fullbinpath, true);
145 followlink = file.isLink();
147 lyxerr[Debug::INIT] << " directory " << fullbinpath
148 << " is a link" << endl;
150 if (LyXReadLink(fullbinpath, link, true)) {
152 binpath = MakeAbsPath(OnlyPath(fullbinpath));
158 } while (followlink);
160 // <absolute top srcdir>/lib
161 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
163 searchpath += lyx_dir();
165 lyxerr[Debug::INIT] << "System directory search path: "
166 << searchpath << endl;
168 string const filename = "chkconfig.ltx";
169 string const temp = FileOpenSearch(searchpath, filename, string());
170 system_lyxdir = OnlyPath(temp);
172 // Reduce "path/../path" stuff out of system directory
173 system_lyxdir = NormalizePath(system_lyxdir);
175 bool path_shown = false;
177 // Warn if environment variable is set, but unusable
178 if (!lyxdir.empty()) {
179 if (system_lyxdir != NormalizePath(lyxdir)) {
180 lyxerr <<_("LYX_DIR_14x environment variable no good.")
182 << _("System directory set to: ")
183 << system_lyxdir << endl;
188 // Warn the user if we couldn't find "chkconfig.ltx"
189 if (system_lyxdir == "./") {
190 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
191 <<_("Try the '-sysdir' command line parameter or ")
192 <<_("set the environment variable LYX_DIR_14x to the "
193 "LyX system directory ")
194 << _("containing the file `chkconfig.ltx'.") << endl;
196 FileInfo fi(lyx_dir());
198 lyxerr << "Couldn't even find the default LYX_DIR." << endl
199 << "Giving up." << endl;
202 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
205 lyxerr << _("Expect problems.") << endl;
207 system_lyxdir = lyx_dir();
212 lyxerr[Debug::INIT] << "System directory: '"
213 << system_lyxdir << '\'' << endl;
216 // Determine user lyx-dir
219 // Directories are searched in this order:
220 // 1) -userdir command line parameter
221 // 2) LYX_USERDIR_14x environment variable
222 // 3) $HOME/.<name of binary>
224 // If we had a command line switch, user_lyxdir is already set
225 bool explicit_userdir = true;
226 if (user_lyxdir.empty()) {
228 // LYX_USERDIR_14x environment variable
229 user_lyxdir = GetEnvPath("LYX_USERDIR_14x");
232 if (user_lyxdir.empty())
233 user_lyxdir = AddPath(GetEnvPath("HOME"),
234 string(".") + PACKAGE);
235 explicit_userdir = false;
238 lyxerr[Debug::INIT] << "User LyX directory: '"
239 << user_lyxdir << '\'' << endl;
240 return explicit_userdir;
243 } // namespace support