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"
32 // Store for the path to the lyx support files we're actually going to use.
33 string system_lyxdir_;
35 // Store for the path to the user-level support files.
39 /* The absolute path to the system-level lyx support files.
42 string const & lyx_dir()
44 static string const ld = "%LYX_DIR%";
49 /* The absolute path to the top of the lyx build tree.
52 string const & lyx_top_srcdir()
54 static string const lts = "%TOP_SRCDIR%";
65 /* The absolute path to the system-level lyx locale directory.
68 string const & lyx_localedir()
70 static string const ll = "%LOCALEDIR%";
75 string const & build_lyxdir()
77 static string const bl = "%BUILDDIR%";
82 string const & system_lyxdir()
84 return system_lyxdir_;
88 void system_lyxdir(string const & sld)
94 string const & user_lyxdir()
100 void user_lyxdir(string const & uld)
109 // Determine path of binary
112 string binpath = os::binpath();
113 string binname = os::binname();
114 string fullbinname = MakeAbsPath(binname, binpath);
116 if (binpath.empty()) {
117 lyxerr << _("Warning: could not determine path of binary.")
119 << _("If you have problems, try starting LyX with an absolute path.")
122 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
123 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
126 // Determine system directory.
129 // Directories are searched in this order:
130 // 1) -sysdir command line parameter
131 // 2) LYX_DIR_14x environment variable
132 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
133 // 4) <path of binary>/../share/<name of binary>/
134 // 4a) repeat 4 after following the Symlink if <path of
135 // binary> is a symbolic link.
136 // 5) hardcoded lyx_dir
137 // The directory is checked for the presence of the file
138 // "chkconfig.ltx", and if that is present, the directory
139 // is accepted as the system directory.
140 // If no chkconfig.ltx file is found, a warning is given,
141 // and the hardcoded lyx_dir is used.
143 // If we had a command line switch, system_lyxdir_ is already set
145 if (!system_lyxdir_.empty())
146 searchpath = MakeAbsPath(system_lyxdir_) + ';';
148 string const lyxdir = GetEnvPath("LYX_DIR_14x");
150 if (!lyxdir.empty()) {
151 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
152 searchpath += lyxdir + ';';
155 string fullbinpath = binpath;
156 FileInfo file(fullbinname, true);
158 lyxerr[Debug::INIT] << "binary is a link" << endl;
160 if (LyXReadLink(fullbinname, link, true)) {
161 // Path of binary/../share/name of binary/
162 searchpath += NormalizePath(AddPath(binpath,
164 + OnlyFilename(binname));
167 binpath = MakeAbsPath(OnlyPath(fullbinpath));
173 // Path of binary/../share/name of binary/
174 searchpath += NormalizePath(AddPath(binpath, "../share/") +
175 OnlyFilename(binname)) + ';';
178 FileInfo file(fullbinpath, true);
179 followlink = file.isLink();
181 lyxerr[Debug::INIT] << " directory " << fullbinpath
182 << " is a link" << endl;
184 if (LyXReadLink(fullbinpath, link, true)) {
186 binpath = MakeAbsPath(OnlyPath(fullbinpath));
192 } while (followlink);
194 // <absolute top srcdir>/lib
195 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
197 searchpath += lyx_dir();
199 lyxerr[Debug::INIT] << "System directory search path: "
200 << searchpath << endl;
202 string const filename = "chkconfig.ltx";
203 string const temp = FileOpenSearch(searchpath, filename, string());
204 system_lyxdir_ = OnlyPath(temp);
206 // Reduce "path/../path" stuff out of system directory
207 system_lyxdir_ = NormalizePath(system_lyxdir_);
209 bool path_shown = false;
211 // Warn if environment variable is set, but unusable
212 if (!lyxdir.empty()) {
213 if (system_lyxdir_ != NormalizePath(lyxdir)) {
214 lyxerr <<_("LYX_DIR_14x environment variable no good.")
216 << _("System directory set to: ")
217 << system_lyxdir_ << endl;
222 // Warn the user if we couldn't find "chkconfig.ltx"
223 if (system_lyxdir_ == "./") {
224 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
225 <<_("Try the '-sysdir' command line parameter or ")
226 <<_("set the environment variable LYX_DIR_14x to the "
227 "LyX system directory ")
228 << _("containing the file `chkconfig.ltx'.") << endl;
230 FileInfo fi(lyx_dir());
232 lyxerr << "Couldn't even find the default LYX_DIR." << endl
233 << "Giving up." << endl;
236 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
239 lyxerr << _("Expect problems.") << endl;
241 system_lyxdir_ = lyx_dir();
246 lyxerr[Debug::INIT] << "System directory: '"
247 << system_lyxdir_ << '\'' << endl;
250 // Determine user lyx-dir
253 // Directories are searched in this order:
254 // 1) -userdir command line parameter
255 // 2) LYX_USERDIR_14x environment variable
256 // 3) $HOME/.<name of binary>
258 // If we had a command line switch, user_lyxdir_ is already set
259 bool explicit_userdir = true;
260 if (user_lyxdir_.empty()) {
262 // LYX_USERDIR_14x environment variable
263 user_lyxdir_ = GetEnvPath("LYX_USERDIR_14x");
266 if (user_lyxdir_.empty())
267 user_lyxdir_ = AddPath(GetEnvPath("HOME"),
268 string(".") + PACKAGE);
269 explicit_userdir = false;
272 lyxerr[Debug::INIT] << "User LyX directory: '"
273 << user_lyxdir_ << '\'' << endl;
274 return explicit_userdir;
277 } // namespace support