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"
36 /* The absolute path to the system-level lyx support files.
39 string const & lyx_dir()
41 static string const ld = "%LYX_DIR%";
46 /* The absolute path to the top of the lyx build tree.
49 string const & lyx_top_srcdir()
51 static string const lts = "%TOP_SRCDIR%";
56 /* The absolute path to the system-level lyx locale directory.
59 string const & lyx_localedir()
61 static string const ll = "%LOCALEDIR%";
71 string const & build_lyxdir()
73 static string const bl = "%BUILDDIR%";
81 // Determine path of binary
84 string binpath = os::binpath();
85 string binname = os::binname();
86 string fullbinname = MakeAbsPath(binname, binpath);
88 if (binpath.empty()) {
89 lyxerr << _("Warning: could not determine path of binary.")
91 << _("If you have problems, try starting LyX with an absolute path.")
94 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
95 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
98 // Determine system directory.
101 // Directories are searched in this order:
102 // 1) -sysdir command line parameter
103 // 2) LYX_DIR_14x environment variable
104 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
105 // 4) <path of binary>/../share/<name of binary>/
106 // 4a) repeat 4 after following the Symlink if <path of
107 // binary> is a symbolic link.
108 // 5) hardcoded lyx_dir
109 // The directory is checked for the presence of the file
110 // "chkconfig.ltx", and if that is present, the directory
111 // is accepted as the system directory.
112 // If no chkconfig.ltx file is found, a warning is given,
113 // and the hardcoded lyx_dir is used.
115 // If we had a command line switch, system_lyxdir is already set
117 if (!system_lyxdir.empty())
118 searchpath = MakeAbsPath(system_lyxdir) + ';';
120 string const lyxdir = GetEnvPath("LYX_DIR_14x");
122 if (!lyxdir.empty()) {
123 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
124 searchpath += lyxdir + ';';
127 string fullbinpath = binpath;
128 FileInfo file(fullbinname, true);
130 lyxerr[Debug::INIT] << "binary is a link" << endl;
132 if (LyXReadLink(fullbinname, link, true)) {
133 // Path of binary/../share/name of binary/
134 searchpath += NormalizePath(AddPath(binpath,
136 + OnlyFilename(binname));
139 binpath = MakeAbsPath(OnlyPath(fullbinpath));
145 // Path of binary/../share/name of binary/
146 searchpath += NormalizePath(AddPath(binpath, "../share/") +
147 OnlyFilename(binname)) + ';';
150 FileInfo file(fullbinpath, true);
151 followlink = file.isLink();
153 lyxerr[Debug::INIT] << " directory " << fullbinpath
154 << " is a link" << endl;
156 if (LyXReadLink(fullbinpath, link, true)) {
158 binpath = MakeAbsPath(OnlyPath(fullbinpath));
164 } while (followlink);
166 // <absolute top srcdir>/lib
167 searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
169 searchpath += lyx_dir();
171 lyxerr[Debug::INIT] << "System directory search path: "
172 << searchpath << endl;
174 string const filename = "chkconfig.ltx";
175 string const temp = FileOpenSearch(searchpath, filename, string());
176 system_lyxdir = OnlyPath(temp);
178 // Reduce "path/../path" stuff out of system directory
179 system_lyxdir = NormalizePath(system_lyxdir);
181 bool path_shown = false;
183 // Warn if environment variable is set, but unusable
184 if (!lyxdir.empty()) {
185 if (system_lyxdir != NormalizePath(lyxdir)) {
186 lyxerr <<_("LYX_DIR_14x environment variable no good.")
188 << _("System directory set to: ")
189 << system_lyxdir << endl;
194 // Warn the user if we couldn't find "chkconfig.ltx"
195 if (system_lyxdir == "./") {
196 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
197 <<_("Try the '-sysdir' command line parameter or ")
198 <<_("set the environment variable LYX_DIR_14x to the "
199 "LyX system directory ")
200 << _("containing the file `chkconfig.ltx'.") << endl;
202 FileInfo fi(lyx_dir());
204 lyxerr << "Couldn't even find the default LYX_DIR." << endl
205 << "Giving up." << endl;
208 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
211 lyxerr << _("Expect problems.") << endl;
213 system_lyxdir = lyx_dir();
218 lyxerr[Debug::INIT] << "System directory: '"
219 << system_lyxdir << '\'' << endl;
222 // Determine user lyx-dir
225 // Directories are searched in this order:
226 // 1) -userdir command line parameter
227 // 2) LYX_USERDIR_14x environment variable
228 // 3) $HOME/.<name of binary>
230 // If we had a command line switch, user_lyxdir is already set
231 bool explicit_userdir = true;
232 if (user_lyxdir.empty()) {
234 // LYX_USERDIR_14x environment variable
235 user_lyxdir = GetEnvPath("LYX_USERDIR_14x");
238 if (user_lyxdir.empty())
239 user_lyxdir = AddPath(GetEnvPath("HOME"),
240 string(".") + PACKAGE);
241 explicit_userdir = false;
244 lyxerr[Debug::INIT] << "User LyX directory: '"
245 << user_lyxdir << '\'' << endl;
246 return explicit_userdir;
249 } // namespace support