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"
35 // Store for the path to the lyx support files we're actually going to use.
36 string system_lyxdir_;
38 /* The absolute path to the system-level lyx support files.
41 string const & lyx_dir()
43 static string const ld = "%LYX_DIR%";
48 /* The absolute path to the top of the lyx build tree.
51 string const & lyx_top_srcdir()
53 static string const lts = "%TOP_SRCDIR%";
58 /* The absolute path to the system-level lyx locale directory.
61 string const & lyx_localedir()
63 static string const ll = "%LOCALEDIR%";
73 string const & build_lyxdir()
75 static string const bl = "%BUILDDIR%";
80 string const & system_lyxdir()
82 return system_lyxdir_;
86 void system_lyxdir(string const & sld)
95 // Determine path of binary
98 string binpath = os::binpath();
99 string binname = os::binname();
100 string fullbinname = MakeAbsPath(binname, binpath);
102 if (binpath.empty()) {
103 lyxerr << _("Warning: could not determine path of binary.")
105 << _("If you have problems, try starting LyX with an absolute path.")
108 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
109 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
112 // Determine system directory.
115 // Directories are searched in this order:
116 // 1) -sysdir command line parameter
117 // 2) LYX_DIR_14x environment variable
118 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
119 // 4) <path of binary>/../share/<name of binary>/
120 // 4a) repeat 4 after following the Symlink if <path of
121 // binary> is a symbolic link.
122 // 5) hardcoded lyx_dir
123 // The directory is checked for the presence of the file
124 // "chkconfig.ltx", and if that is present, the directory
125 // is accepted as the system directory.
126 // If no chkconfig.ltx file is found, a warning is given,
127 // and the hardcoded lyx_dir is used.
129 // If we had a command line switch, system_lyxdir_ is already set
131 if (!system_lyxdir_.empty())
132 searchpath = MakeAbsPath(system_lyxdir_) + ';';
134 string const lyxdir = GetEnvPath("LYX_DIR_14x");
136 if (!lyxdir.empty()) {
137 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
138 searchpath += lyxdir + ';';
141 string fullbinpath = binpath;
142 FileInfo file(fullbinname, true);
144 lyxerr[Debug::INIT] << "binary is a link" << endl;
146 if (LyXReadLink(fullbinname, link, true)) {
147 // Path of binary/../share/name of binary/
148 searchpath += NormalizePath(AddPath(binpath,
150 + OnlyFilename(binname));
153 binpath = MakeAbsPath(OnlyPath(fullbinpath));
159 // Path of binary/../share/name of binary/
160 searchpath += NormalizePath(AddPath(binpath, "../share/") +
161 OnlyFilename(binname)) + ';';
164 FileInfo file(fullbinpath, true);
165 followlink = file.isLink();
167 lyxerr[Debug::INIT] << " directory " << fullbinpath
168 << " is a link" << endl;
170 if (LyXReadLink(fullbinpath, link, true)) {
172 binpath = MakeAbsPath(OnlyPath(fullbinpath));
178 } while (followlink);
180 // <absolute top srcdir>/lib
181 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
183 searchpath += lyx_dir();
185 lyxerr[Debug::INIT] << "System directory search path: "
186 << searchpath << endl;
188 string const filename = "chkconfig.ltx";
189 string const temp = FileOpenSearch(searchpath, filename, string());
190 system_lyxdir_ = OnlyPath(temp);
192 // Reduce "path/../path" stuff out of system directory
193 system_lyxdir_ = NormalizePath(system_lyxdir_);
195 bool path_shown = false;
197 // Warn if environment variable is set, but unusable
198 if (!lyxdir.empty()) {
199 if (system_lyxdir_ != NormalizePath(lyxdir)) {
200 lyxerr <<_("LYX_DIR_14x environment variable no good.")
202 << _("System directory set to: ")
203 << system_lyxdir_ << endl;
208 // Warn the user if we couldn't find "chkconfig.ltx"
209 if (system_lyxdir_ == "./") {
210 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
211 <<_("Try the '-sysdir' command line parameter or ")
212 <<_("set the environment variable LYX_DIR_14x to the "
213 "LyX system directory ")
214 << _("containing the file `chkconfig.ltx'.") << endl;
216 FileInfo fi(lyx_dir());
218 lyxerr << "Couldn't even find the default LYX_DIR." << endl
219 << "Giving up." << endl;
222 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
225 lyxerr << _("Expect problems.") << endl;
227 system_lyxdir_ = lyx_dir();
232 lyxerr[Debug::INIT] << "System directory: '"
233 << system_lyxdir_ << '\'' << endl;
236 // Determine user lyx-dir
239 // Directories are searched in this order:
240 // 1) -userdir command line parameter
241 // 2) LYX_USERDIR_14x environment variable
242 // 3) $HOME/.<name of binary>
244 // If we had a command line switch, user_lyxdir is already set
245 bool explicit_userdir = true;
246 if (user_lyxdir.empty()) {
248 // LYX_USERDIR_14x environment variable
249 user_lyxdir = GetEnvPath("LYX_USERDIR_14x");
252 if (user_lyxdir.empty())
253 user_lyxdir = AddPath(GetEnvPath("HOME"),
254 string(".") + PACKAGE);
255 explicit_userdir = false;
258 lyxerr[Debug::INIT] << "User LyX directory: '"
259 << user_lyxdir << '\'' << endl;
260 return explicit_userdir;
263 } // namespace support