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 autogenerated files when running in place
38 // Store for the path to the user-level support files.
42 /* The absolute path to the system-level lyx support files.
45 string const & lyx_dir()
47 static string const ld = "%LYX_DIR%";
52 /* The absolute path to the top of the lyx build tree.
55 string const & lyx_top_srcdir()
57 static string const lts = "%TOP_SRCDIR%";
68 /* The absolute path to the system-level lyx locale directory.
71 string const & lyx_localedir()
73 static string const ll = "%LOCALEDIR%";
78 string const & build_dir()
80 static string const bl = "%BUILDDIR%";
85 string const & build_lyxdir()
91 void build_lyxdir(string const & sld)
97 string const & system_lyxdir()
99 return system_lyxdir_;
103 void system_lyxdir(string const & sld)
105 system_lyxdir_ = sld;
109 string const & user_lyxdir()
115 void user_lyxdir(string const & uld)
124 // Determine path of binary
127 string binpath = os::binpath();
128 string binname = os::binname();
129 string fullbinname = MakeAbsPath(binname, binpath);
131 if (binpath.empty()) {
132 lyxerr << _("Warning: could not determine path of binary.")
134 << _("If you have problems, try starting LyX with an absolute path.")
137 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
138 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
144 // Determine whether we are running in place and set
145 // build_lyxdir accordingly
148 string const buildlyxdir = MakeAbsPath("../lib", binpath);
149 if (!FileSearch(buildlyxdir, "lyxrc.defaults").empty()) {
150 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
151 build_lyxdir(buildlyxdir);
152 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
153 "place... yes" << endl;
156 << "Checking whether LyX is run in place... no"
161 // Determine system directory.
164 // Directories are searched in this order:
165 // 1) -sysdir command line parameter
166 // 2) LYX_DIR_14x environment variable
167 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
168 // 4) <path of binary>/../share/<name of binary>/
169 // 4a) repeat 4 after following the Symlink if <path of
170 // binary> is a symbolic link.
171 // 5) hardcoded lyx_dir
172 // The directory is checked for the presence of the file
173 // "chkconfig.ltx", and if that is present, the directory
174 // is accepted as the system directory.
175 // If no chkconfig.ltx file is found, a warning is given,
176 // and the hardcoded lyx_dir is used.
178 // If we had a command line switch, system_lyxdir_ is already set
179 if (!system_lyxdir_.empty())
180 searchpath = MakeAbsPath(system_lyxdir_) + ';';
182 string const lyxdir = GetEnvPath("LYX_DIR_14x");
184 if (!lyxdir.empty()) {
185 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
186 searchpath += lyxdir + ';';
189 string fullbinpath = binpath;
190 FileInfo file(fullbinname, true);
192 lyxerr[Debug::INIT] << "binary is a link" << endl;
194 if (LyXReadLink(fullbinname, link, true)) {
195 // Path of binary/../share/name of binary/
196 searchpath += NormalizePath(AddPath(binpath,
198 + OnlyFilename(binname));
201 binpath = MakeAbsPath(OnlyPath(fullbinpath));
207 // Path of binary/../share/name of binary/
208 searchpath += NormalizePath(AddPath(binpath, "../share/") +
209 OnlyFilename(binname)) + ';';
212 FileInfo file(fullbinpath, true);
213 followlink = file.isLink();
215 lyxerr[Debug::INIT] << " directory " << fullbinpath
216 << " is a link" << endl;
218 if (LyXReadLink(fullbinpath, link, true)) {
220 binpath = MakeAbsPath(OnlyPath(fullbinpath));
226 } while (followlink);
228 // <absolute top srcdir>/lib
229 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
231 searchpath += lyx_dir();
233 lyxerr[Debug::INIT] << "System directory search path: "
234 << searchpath << endl;
236 string const filename = "chkconfig.ltx";
237 string const temp = FileOpenSearch(searchpath, filename, string());
238 system_lyxdir_ = OnlyPath(temp);
240 // Reduce "path/../path" stuff out of system directory
241 system_lyxdir_ = NormalizePath(system_lyxdir_);
243 bool path_shown = false;
245 // Warn if environment variable is set, but unusable
246 if (!lyxdir.empty()) {
247 if (system_lyxdir_ != NormalizePath(lyxdir)) {
248 lyxerr <<_("LYX_DIR_14x environment variable no good.")
250 << _("System directory set to: ")
251 << system_lyxdir_ << endl;
256 // Warn the user if we couldn't find "chkconfig.ltx"
257 if (system_lyxdir_ == "./") {
258 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
259 <<_("Try the '-sysdir' command line parameter or ")
260 <<_("set the environment variable LYX_DIR_14x to the "
261 "LyX system directory ")
262 << _("containing the file `chkconfig.ltx'.") << endl;
264 FileInfo fi(lyx_dir());
266 lyxerr << "Couldn't even find the default LYX_DIR." << endl
267 << "Giving up." << endl;
270 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
273 lyxerr << _("Expect problems.") << endl;
275 system_lyxdir_ = lyx_dir();
280 lyxerr[Debug::INIT] << "System directory: '"
281 << system_lyxdir_ << '\'' << endl;
284 // Determine user lyx-dir
287 // Directories are searched in this order:
288 // 1) -userdir command line parameter
289 // 2) LYX_USERDIR_14x environment variable
290 // 3) $HOME/.<name of binary>
292 // If we had a command line switch, user_lyxdir_ is already set
293 bool explicit_userdir = true;
294 if (user_lyxdir_.empty()) {
296 // LYX_USERDIR_14x environment variable
297 user_lyxdir_ = GetEnvPath("LYX_USERDIR_14x");
300 if (user_lyxdir_.empty())
301 user_lyxdir_ = AddPath(GetEnvPath("HOME"),
302 string(".") + PACKAGE);
303 explicit_userdir = false;
306 lyxerr[Debug::INIT] << "User LyX directory: '"
307 << user_lyxdir_ << '\'' << endl;
308 return explicit_userdir;
311 } // namespace support