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%";
59 /* The absolute path to the system-level lyx locale directory.
62 string const & lyx_localedir()
64 static string const ll = "%LOCALEDIR%";
74 string const & build_lyxdir()
76 static string const bl = "%BUILDDIR%";
81 string const & system_lyxdir()
83 return system_lyxdir_;
87 void system_lyxdir(string const & sld)
93 string const & user_lyxdir()
99 void user_lyxdir(string const & uld)
108 // Determine path of binary
111 string binpath = os::binpath();
112 string binname = os::binname();
113 string fullbinname = MakeAbsPath(binname, binpath);
115 if (binpath.empty()) {
116 lyxerr << _("Warning: could not determine path of binary.")
118 << _("If you have problems, try starting LyX with an absolute path.")
121 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
122 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
125 // Determine system directory.
128 // Directories are searched in this order:
129 // 1) -sysdir command line parameter
130 // 2) LYX_DIR_14x environment variable
131 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
132 // 4) <path of binary>/../share/<name of binary>/
133 // 4a) repeat 4 after following the Symlink if <path of
134 // binary> is a symbolic link.
135 // 5) hardcoded lyx_dir
136 // The directory is checked for the presence of the file
137 // "chkconfig.ltx", and if that is present, the directory
138 // is accepted as the system directory.
139 // If no chkconfig.ltx file is found, a warning is given,
140 // and the hardcoded lyx_dir is used.
142 // If we had a command line switch, system_lyxdir_ is already set
144 if (!system_lyxdir_.empty())
145 searchpath = MakeAbsPath(system_lyxdir_) + ';';
147 string const lyxdir = GetEnvPath("LYX_DIR_14x");
149 if (!lyxdir.empty()) {
150 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
151 searchpath += lyxdir + ';';
154 string fullbinpath = binpath;
155 FileInfo file(fullbinname, true);
157 lyxerr[Debug::INIT] << "binary is a link" << endl;
159 if (LyXReadLink(fullbinname, link, true)) {
160 // Path of binary/../share/name of binary/
161 searchpath += NormalizePath(AddPath(binpath,
163 + OnlyFilename(binname));
166 binpath = MakeAbsPath(OnlyPath(fullbinpath));
172 // Path of binary/../share/name of binary/
173 searchpath += NormalizePath(AddPath(binpath, "../share/") +
174 OnlyFilename(binname)) + ';';
177 FileInfo file(fullbinpath, true);
178 followlink = file.isLink();
180 lyxerr[Debug::INIT] << " directory " << fullbinpath
181 << " is a link" << endl;
183 if (LyXReadLink(fullbinpath, link, true)) {
185 binpath = MakeAbsPath(OnlyPath(fullbinpath));
191 } while (followlink);
193 // <absolute top srcdir>/lib
194 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
196 searchpath += lyx_dir();
198 lyxerr[Debug::INIT] << "System directory search path: "
199 << searchpath << endl;
201 string const filename = "chkconfig.ltx";
202 string const temp = FileOpenSearch(searchpath, filename, string());
203 system_lyxdir_ = OnlyPath(temp);
205 // Reduce "path/../path" stuff out of system directory
206 system_lyxdir_ = NormalizePath(system_lyxdir_);
208 bool path_shown = false;
210 // Warn if environment variable is set, but unusable
211 if (!lyxdir.empty()) {
212 if (system_lyxdir_ != NormalizePath(lyxdir)) {
213 lyxerr <<_("LYX_DIR_14x environment variable no good.")
215 << _("System directory set to: ")
216 << system_lyxdir_ << endl;
221 // Warn the user if we couldn't find "chkconfig.ltx"
222 if (system_lyxdir_ == "./") {
223 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
224 <<_("Try the '-sysdir' command line parameter or ")
225 <<_("set the environment variable LYX_DIR_14x to the "
226 "LyX system directory ")
227 << _("containing the file `chkconfig.ltx'.") << endl;
229 FileInfo fi(lyx_dir());
231 lyxerr << "Couldn't even find the default LYX_DIR." << endl
232 << "Giving up." << endl;
235 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
238 lyxerr << _("Expect problems.") << endl;
240 system_lyxdir_ = lyx_dir();
245 lyxerr[Debug::INIT] << "System directory: '"
246 << system_lyxdir_ << '\'' << endl;
249 // Determine user lyx-dir
252 // Directories are searched in this order:
253 // 1) -userdir command line parameter
254 // 2) LYX_USERDIR_14x environment variable
255 // 3) $HOME/.<name of binary>
257 // If we had a command line switch, user_lyxdir_ is already set
258 bool explicit_userdir = true;
259 if (user_lyxdir_.empty()) {
261 // LYX_USERDIR_14x environment variable
262 user_lyxdir_ = GetEnvPath("LYX_USERDIR_14x");
265 if (user_lyxdir_.empty())
266 user_lyxdir_ = AddPath(GetEnvPath("HOME"),
267 string(".") + PACKAGE);
268 explicit_userdir = false;
271 lyxerr[Debug::INIT] << "User LyX directory: '"
272 << user_lyxdir_ << '\'' << endl;
273 return explicit_userdir;
276 } // namespace support