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"
33 // Store for the path to the lyx support files we're actually going to use.
34 string system_lyxdir_;
36 // Store for the path to the autogenerated files when running in place
39 // Store for the path to the user-level support files.
43 /* The absolute path to the system-level lyx support files.
46 string const & lyx_dir()
48 static string const ld = "%LYX_DIR%";
53 /* The absolute path to the top of the lyx build tree.
56 string const & lyx_top_srcdir()
58 static string const lts = "%TOP_SRCDIR%";
69 /* The absolute path to the system-level lyx locale directory.
72 string const & lyx_localedir()
74 static string const ll = "%LOCALEDIR%";
79 string const & build_dir()
81 static string const bl = "%BUILDDIR%";
86 string const & build_lyxdir()
92 void build_lyxdir(string const & sld)
98 string const & system_lyxdir()
100 return system_lyxdir_;
104 void system_lyxdir(string const & sld)
106 system_lyxdir_ = sld;
110 string const & user_lyxdir()
116 void user_lyxdir(string const & uld)
125 // Determine path of binary
128 string binpath = os::binpath();
129 string binname = os::binname();
130 string fullbinname = MakeAbsPath(binname, binpath);
132 if (binpath.empty()) {
133 lyxerr << _("Warning: could not determine path of binary.")
135 << _("If you have problems, try starting LyX with an absolute path.")
138 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
139 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
145 // Determine whether we are running in place and set
146 // build_lyxdir accordingly
149 string const buildlyxdir = MakeAbsPath("../lib", binpath);
150 if (!FileSearch(buildlyxdir, "lyxrc.defaults").empty()) {
151 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
152 build_lyxdir(buildlyxdir);
153 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
154 "place... yes" << endl;
157 << "Checking whether LyX is run in place... no"
162 // Determine system directory.
165 // Directories are searched in this order:
166 // 1) -sysdir command line parameter
167 // 2) LYX_DIR_14x environment variable
168 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
169 // 4) <path of binary>/../share/<name of binary>/
170 // 4a) repeat 4 after following the Symlink if <path of
171 // binary> is a symbolic link.
172 // 5) hardcoded lyx_dir
173 // The directory is checked for the presence of the file
174 // "chkconfig.ltx", and if that is present, the directory
175 // is accepted as the system directory.
176 // If no chkconfig.ltx file is found, a warning is given,
177 // and the hardcoded lyx_dir is used.
179 // If we had a command line switch, system_lyxdir_ is already set
180 if (!system_lyxdir_.empty())
181 searchpath = MakeAbsPath(system_lyxdir_) + ';';
183 string const lyxdir = GetEnvPath("LYX_DIR_14x");
185 if (!lyxdir.empty()) {
186 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
187 searchpath += lyxdir + ';';
190 string fullbinpath = binpath;
191 FileInfo file(fullbinname, true);
193 lyxerr[Debug::INIT] << "binary is a link" << endl;
195 if (LyXReadLink(fullbinname, link, true)) {
196 // Path of binary/../share/name of binary/
197 searchpath += NormalizePath(AddPath(binpath,
199 + OnlyFilename(binname));
202 binpath = MakeAbsPath(OnlyPath(fullbinpath));
208 // Path of binary/../share/name of binary/
209 searchpath += NormalizePath(AddPath(binpath, "../share/") +
210 OnlyFilename(binname)) + ';';
213 FileInfo file(fullbinpath, true);
214 followlink = file.isLink();
216 lyxerr[Debug::INIT] << " directory " << fullbinpath
217 << " is a link" << endl;
219 if (LyXReadLink(fullbinpath, link, true)) {
221 binpath = MakeAbsPath(OnlyPath(fullbinpath));
227 } while (followlink);
229 // <absolute top srcdir>/lib
230 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
232 searchpath += lyx_dir();
234 lyxerr[Debug::INIT] << "System directory search path: "
235 << searchpath << endl;
237 string const filename = "chkconfig.ltx";
238 string const temp = FileOpenSearch(searchpath, filename, string());
239 system_lyxdir_ = OnlyPath(temp);
241 // Reduce "path/../path" stuff out of system directory
242 system_lyxdir_ = NormalizePath(system_lyxdir_);
244 bool path_shown = false;
246 // Warn if environment variable is set, but unusable
247 if (!lyxdir.empty()) {
248 if (system_lyxdir_ != NormalizePath(lyxdir)) {
249 lyxerr <<_("LYX_DIR_14x environment variable no good.")
251 << _("System directory set to: ")
252 << system_lyxdir_ << endl;
257 // Warn the user if we couldn't find "chkconfig.ltx"
258 if (system_lyxdir_ == "./") {
259 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
260 <<_("Try the '-sysdir' command line parameter or ")
261 <<_("set the environment variable LYX_DIR_14x to the "
262 "LyX system directory ")
263 << _("containing the file `chkconfig.ltx'.") << endl;
265 FileInfo fi(lyx_dir());
267 lyxerr << "Couldn't even find the default LYX_DIR." << endl
268 << "Giving up." << endl;
271 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
274 lyxerr << _("Expect problems.") << endl;
276 system_lyxdir_ = lyx_dir();
281 lyxerr[Debug::INIT] << "System directory: '"
282 << system_lyxdir_ << '\'' << endl;
285 // Determine user lyx-dir
288 // Directories are searched in this order:
289 // 1) -userdir command line parameter
290 // 2) LYX_USERDIR_14x environment variable
291 // 3) $HOME/.<name of binary>
293 // If we had a command line switch, user_lyxdir_ is already set
294 bool explicit_userdir = true;
295 if (user_lyxdir_.empty()) {
297 // LYX_USERDIR_14x environment variable
298 user_lyxdir_ = GetEnvPath("LYX_USERDIR_14x");
301 if (user_lyxdir_.empty())
302 user_lyxdir_ = AddPath(GetEnvPath("HOME"),
303 string(".") + PACKAGE);
304 explicit_userdir = false;
307 lyxerr[Debug::INIT] << "User LyX directory: '"
308 << user_lyxdir_ << '\'' << endl;
309 return explicit_userdir;
312 } // namespace support