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"
34 // Store for the path to the lyx support files we're actually going to use.
35 string system_lyxdir_;
37 // Store for the path to the autogenerated files when running in place
40 // Store for the path to the user-level support files.
44 /* The absolute path to the system-level lyx support files.
47 string const & lyx_dir()
49 static string const ld = "%LYX_DIR%";
60 /* The absolute path to the top of the lyx build tree.
63 string const & top_srcdir()
65 static string const lts = "%TOP_SRCDIR%";
70 /* The absolute path to the system-level lyx locale directory.
73 string const & lyx_localedir()
75 static string const ll = "%LOCALEDIR%";
80 string const & build_dir()
82 static string const bl = "%BUILDDIR%";
87 string const & build_lyxdir()
93 void build_lyxdir(string const & sld)
99 string const & system_lyxdir()
101 return system_lyxdir_;
105 void system_lyxdir(string const & sld)
107 system_lyxdir_ = sld;
111 string const & user_lyxdir()
117 void user_lyxdir(string const & uld)
126 // Determine path of binary
129 string binpath = os::binpath();
130 string binname = os::binname();
131 string fullbinname = MakeAbsPath(binname, binpath);
133 if (binpath.empty()) {
134 lyxerr << _("Warning: could not determine path of binary.")
136 << _("If you have problems, try starting LyX with an absolute path.")
139 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
140 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
146 // Determine whether we are running in place and set
147 // build_lyxdir accordingly
150 string const buildlyxdir = MakeAbsPath("../lib", binpath);
151 if (!FileSearch(buildlyxdir, "lyxrc.defaults").empty()) {
152 searchpath += AddPath(top_srcdir(), "lib") + ';';
153 build_lyxdir(buildlyxdir);
154 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
155 "place... yes" << endl;
158 << "Checking whether LyX is run in place... no"
163 // Determine system directory.
166 // Directories are searched in this order:
167 // 1) -sysdir command line parameter
168 // 2) LYX_DIR_14x environment variable
169 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
170 // 4) <path of binary>/../Resources/<name of binary>/ [for LyX/Mac]
171 // 5) <path of binary>/../share/<name of binary>/
172 // 5a) repeat 4 after following the Symlink if <path of
173 // binary> is a symbolic link.
174 // 6) hardcoded lyx_dir
175 // The directory is checked for the presence of the file
176 // "chkconfig.ltx", and if that is present, the directory
177 // is accepted as the system directory.
178 // If no chkconfig.ltx file is found, a warning is given,
179 // and the hardcoded lyx_dir is used.
181 // If we had a command line switch, system_lyxdir_ is already set
182 if (!system_lyxdir_.empty())
183 searchpath = MakeAbsPath(system_lyxdir_) + ';';
185 string const lyxdir = GetEnvPath("LYX_DIR_14x");
187 if (!lyxdir.empty()) {
188 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
189 searchpath += lyxdir + ';';
192 // Path of binary/../Resources/
193 searchpath += NormalizePath(AddPath(binpath, "../Resources/") +
194 OnlyFilename(binname)) + ';';
196 string fullbinpath = binpath;
197 FileInfo file(fullbinname, true);
199 lyxerr[Debug::INIT] << "binary is a link" << endl;
201 if (LyXReadLink(fullbinname, link, true)) {
202 // Path of binary/../share/name of binary/
203 searchpath += NormalizePath(AddPath(binpath,
205 + OnlyFilename(binname));
208 binpath = MakeAbsPath(OnlyPath(fullbinpath));
214 // Path of binary/../share/name of binary/
215 searchpath += NormalizePath(AddPath(binpath, "../share/") +
216 OnlyFilename(binname)) + ';';
219 FileInfo file(fullbinpath, true);
220 followlink = file.isLink();
222 lyxerr[Debug::INIT] << " directory " << fullbinpath
223 << " is a link" << endl;
225 if (LyXReadLink(fullbinpath, link, true)) {
227 binpath = MakeAbsPath(OnlyPath(fullbinpath));
233 } while (followlink);
235 // <absolute top srcdir>/lib
236 searchpath += AddPath(top_srcdir(), "lib") + ';';
238 searchpath += lyx_dir();
240 lyxerr[Debug::INIT] << "System directory search path: "
241 << searchpath << endl;
243 string const filename = "chkconfig.ltx";
244 string const temp = FileOpenSearch(searchpath, filename, string());
245 system_lyxdir_ = OnlyPath(temp);
247 // Reduce "path/../path" stuff out of system directory
248 system_lyxdir_ = NormalizePath(system_lyxdir_);
250 bool path_shown = false;
252 // Warn if environment variable is set, but unusable
253 if (!lyxdir.empty()) {
254 if (system_lyxdir_ != NormalizePath(lyxdir)) {
255 lyxerr <<_("LYX_DIR_14x environment variable no good.")
257 << _("System directory set to: ")
258 << system_lyxdir_ << endl;
263 // Warn the user if we couldn't find "chkconfig.ltx"
264 if (system_lyxdir_ == "./") {
265 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
266 <<_("Try the '-sysdir' command line parameter or ")
267 <<_("set the environment variable LYX_DIR_14x to the "
268 "LyX system directory ")
269 << _("containing the file `chkconfig.ltx'.") << endl;
271 FileInfo fi(lyx_dir());
273 lyxerr << "Couldn't even find the default LYX_DIR." << endl
274 << "Giving up." << endl;
277 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
280 lyxerr << _("Expect problems.") << endl;
282 system_lyxdir_ = lyx_dir();
287 lyxerr[Debug::INIT] << "System directory: '"
288 << system_lyxdir_ << '\'' << endl;
291 // Set PATH for LyX/Mac
292 // LyX/Mac is a relocatable application bundle; here we add to
293 // the PATH so it can find binaries like reLyX inside its own
294 // application bundle, and also append PATH elements that it
295 // needs to run latex, previewers, etc.
298 if (system_lyxdir_ == NormalizePath(AddPath(binpath, "../Resources/")
299 + OnlyFilename(binname))) {
300 const string newpath = GetEnv("PATH") + ":" + binpath
301 + ":/sw/bin:/usr/local/bin"
302 + ":/usr/local/teTeX/bin/powerpc-apple-darwin-current";
303 lyx::support::putenv("PATH", newpath);
304 lyxerr[Debug::INIT] << "Running from LyX/Mac bundle. "
305 "Setting PATH to: " << GetEnv("PATH") << endl;
309 // Determine user lyx-dir
312 // Directories are searched in this order:
313 // 1) -userdir command line parameter
314 // 2) LYX_USERDIR_14x environment variable
315 // 3) $HOME/.<name of binary>
317 // If we had a command line switch, user_lyxdir_ is already set
318 bool explicit_userdir = true;
319 if (user_lyxdir_.empty()) {
321 // LYX_USERDIR_14x environment variable
322 user_lyxdir_ = GetEnvPath("LYX_USERDIR_14x");
325 if (user_lyxdir_.empty())
326 user_lyxdir_ = AddPath(GetEnvPath("HOME"),
327 string(".") + PACKAGE);
328 explicit_userdir = false;
331 lyxerr[Debug::INIT] << "User LyX directory: '"
332 << user_lyxdir_ << '\'' << endl;
333 return explicit_userdir;
336 } // namespace support