]> git.lyx.org Git - lyx.git/blob - src/support/Package.cpp
2f3bad68f1891966c733ab0718c03cdce59b63b7
[lyx.git] / src / support / Package.cpp
1 // -*- C++ -*-
2 /**
3  * \file package.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/Package.h"
15
16 #include "debug.h"
17 #include "gettext.h"
18
19 #include "support/environment.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22 #include "support/ExceptionMessage.h"
23 #include "support/os.h"
24
25 #if defined (USE_WINDOWS_PACKAGING)
26 # include "support/os_win32.h"
27 #endif
28
29 #include <boost/filesystem/operations.hpp>
30 #include <boost/tuple/tuple.hpp>
31
32 #include <list>
33 #include <utility>
34
35 #if !defined (USE_WINDOWS_PACKAGING) && \
36     !defined (USE_MACOSX_PACKAGING) && \
37     !defined (USE_POSIX_PACKAGING)
38 #error USE_FOO_PACKAGING must be defined for FOO = WINDOWS, MACOSX or POSIX.
39 #endif
40
41 #if defined (USE_MACOSX_PACKAGING)
42 # include <CoreServices/CoreServices.h> // FSFindFolder, FSRefMakePath
43 #endif
44
45 using std::string;
46
47 namespace fs = boost::filesystem;
48
49 namespace lyx {
50 namespace support {
51
52 namespace {
53
54 Package package_;
55 bool initialised_ = false;
56
57 } // namespace anon
58
59
60 void init_package(string const & command_line_arg0,
61                   string const & command_line_system_support_dir,
62                   string const & command_line_user_support_dir,
63                   exe_build_dir_to_top_build_dir top_build_dir_location)
64 {
65         // Can do so only once.
66         if (initialised_)
67                 return;
68
69         package_ = Package(command_line_arg0,
70                            command_line_system_support_dir,
71                            command_line_user_support_dir,
72                            top_build_dir_location);
73         initialised_ = true;
74 }
75
76
77 Package const & package()
78 {
79         // Commented out because package().locale_dir() can be called
80         // from the message translation code in Messages.cpp before
81         // init_package() is called. Lars is on the case...
82         // BOOST_ASSERT(initialised_);
83         return package_;
84 }
85
86
87 namespace {
88
89 FileName const abs_path_from_binary_name(string const & exe);
90
91 std::pair<FileName, FileName> const
92 get_build_dirs(FileName const & abs_binary,
93                exe_build_dir_to_top_build_dir top_build_dir_location);
94
95 FileName const get_document_dir(FileName const & home_dir);
96
97 FileName const get_home_dir();
98
99 FileName const get_locale_dir(FileName const & system_support_dir);
100
101 FileName const get_system_support_dir(FileName const & abs_binary,
102                                     string const & command_line_system_support_dir);
103
104 FileName const get_temp_dir();
105
106 FileName const get_default_user_support_dir(FileName const & home_dir);
107
108 std::pair<FileName, bool> const
109 get_user_support_dir(FileName const & default_user_support_dir,
110                      string const & command_line_user_support_dir);
111
112
113 string const & with_version_suffix();
114
115 } // namespace anon
116
117
118 Package::Package(string const & command_line_arg0,
119                  string const & command_line_system_support_dir,
120                  string const & command_line_user_support_dir,
121                  exe_build_dir_to_top_build_dir top_build_dir_location)
122         : explicit_user_support_dir_(false)
123 {
124         home_dir_ = get_home_dir();
125         system_temp_dir_ = get_temp_dir();
126         temp_dir_ = system_temp_dir_;
127         document_dir_ = get_document_dir(home_dir_);
128
129         FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
130         string const bdir = onlyPath(abs_binary.absFilename());
131         // We may be using libtools
132         if (suffixIs(bdir, ".libs/"))
133                 binary_dir_ = FileName(addPath(bdir, "../"));
134         else
135                 binary_dir_ = FileName(bdir);
136
137         // Is LyX being run in-place from the build tree?
138         boost::tie(build_support_dir_, system_support_dir_) =
139                 get_build_dirs(abs_binary, top_build_dir_location);
140
141         if (build_support_dir_.empty())
142                 system_support_dir_ =
143                         get_system_support_dir(abs_binary,
144                                                command_line_system_support_dir);
145
146         locale_dir_ = get_locale_dir(system_support_dir_);
147
148         FileName const default_user_support_dir =
149                 get_default_user_support_dir(home_dir_);
150         boost::tie(user_support_dir_, explicit_user_support_dir_) =
151                 get_user_support_dir(default_user_support_dir,
152                                      command_line_user_support_dir);
153
154         FileName const configure_script(addName(system_support().absFilename(), "configure.py"));
155         configure_command_ = os::python() + ' ' +
156                         quoteName(configure_script.toFilesystemEncoding()) +
157                         with_version_suffix();
158
159         lyxerr[Debug::INIT]
160                 << "<package>\n"
161                 << "\tbinary_dir " << binary_dir().absFilename() << '\n'
162                 << "\tsystem_support " << system_support().absFilename() << '\n'
163                 << "\tbuild_support " << build_support().absFilename() << '\n'
164                 << "\tuser_support " << user_support().absFilename() << '\n'
165                 << "\tlocale_dir " << locale_dir().absFilename() << '\n'
166                 << "\tdocument_dir " << document_dir().absFilename() << '\n'
167                 << "\ttemp_dir " << temp_dir().absFilename() << '\n'
168                 << "\thome_dir " << home_dir().absFilename() << '\n'
169                 << "</package>\n" << std::endl;
170 }
171
172
173 namespace {
174
175 // These next functions contain the stuff that is substituted at
176 // configuration-time.
177 FileName const hardcoded_localedir()
178 {
179         // FIXME UNICODE
180         // The build system needs to make sure that this is in utf8 encoding.
181         return FileName(LYX_ABS_INSTALLED_LOCALEDIR);
182 }
183
184
185 FileName const hardcoded_system_support_dir()
186 {
187         // FIXME UNICODE
188         // The build system needs to make sure that this is in utf8 encoding.
189         return FileName(LYX_ABS_INSTALLED_DATADIR);
190 }
191
192
193 string const & with_version_suffix()
194 {
195         static string const program_suffix = PROGRAM_SUFFIX;
196         static string const with_version_suffix =
197                 " --with-version-suffix=" PROGRAM_SUFFIX;
198         return program_suffix.empty() ? program_suffix : with_version_suffix;
199 }
200
201 } // namespace anon
202
203
204 FileName const & Package::top_srcdir()
205 {
206         // FIXME UNICODE
207         // The build system needs to make sure that this is in utf8 encoding.
208         static FileName const dir(LYX_ABS_TOP_SRCDIR);
209         return dir;
210 }
211
212
213 namespace {
214
215 bool check_command_line_dir(string const & dir,
216                             string const & file,
217                             string const & command_line_switch);
218
219 FileName const extract_env_var_dir(string const & env_var);
220
221 bool check_env_var_dir(FileName const & dir,
222                        string const & env_var);
223
224 bool check_env_var_dir(FileName const & dir,
225                        string const & file,
226                        string const & env_var);
227
228 string const relative_locale_dir();
229
230 string const relative_system_support_dir();
231
232
233 /**
234  * Convert \p name to internal path and strip a trailing slash, since it
235  * comes from user input (commandline or environment).
236  * \p name is encoded in utf8.
237  */
238 string const fix_dir_name(string const & name)
239 {
240         return rtrim(os::internal_path(name), "/");
241 }
242
243
244 FileName const
245 get_build_support_dir(string const & binary_dir,
246                       exe_build_dir_to_top_build_dir top_build_dir_location)
247 {
248         string indirection;
249         switch (top_build_dir_location) {
250         case top_build_dir_is_one_level_up:
251                 indirection = "../lib";
252                 break;
253         case top_build_dir_is_two_levels_up:
254                 indirection = "../../lib";
255                 break;
256         }
257         return FileName(normalizePath(addPath(binary_dir, indirection)));
258 }
259
260
261 std::pair<FileName, FileName> const
262 get_build_dirs(FileName const & abs_binary,
263                exe_build_dir_to_top_build_dir top_build_dir_location)
264 {
265         string const check_text = "Checking whether LyX is run in place...";
266
267         // We're looking for "Makefile" in a directory
268         //   binary_dir/../lib
269         // We're also looking for "chkconfig.ltx" in a directory
270         //   top_srcdir()/lib
271         // If both are found, then we're running LyX in-place.
272
273         // Note that the name of the lyx binary may be a symbolic link.
274         // If that is the case, then we follow the links too.
275         FileName binary = abs_binary;
276         while (true) {
277                 // Try and find "lyxrc.defaults".
278                 string binary_dir = onlyPath(binary.absFilename());
279                 // We may be using libtools with static linking.
280                 if (suffixIs(binary_dir, ".libs/"))
281                         binary_dir = addPath(binary_dir, "../");
282                 FileName const build_support_dir =
283                         get_build_support_dir(binary_dir, top_build_dir_location);
284                 if (!fileSearch(build_support_dir.absFilename(), "Makefile").empty()) {
285                         // Try and find "chkconfig.ltx".
286                         string const system_support_dir =
287                                 addPath(Package::top_srcdir().absFilename(), "lib");
288
289                         if (!fileSearch(system_support_dir, "chkconfig.ltx").empty()) {
290                                 lyxerr[Debug::INIT] << check_text << " yes"
291                                                     << std::endl;
292                                 return std::make_pair(build_support_dir, system_support_dir);
293                         }
294                 }
295
296                 // Check whether binary is a symbolic link.
297                 // If so, resolve it and repeat the exercise.
298                 if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
299                         break;
300
301                 FileName link;
302                 if (readLink(binary, link)) {
303                         binary = link;
304                 } else {
305                         // Unable to resolve the link.
306                         break;
307                 }
308         }
309
310         lyxerr[Debug::INIT] << check_text << " no" << std::endl;
311         return std::make_pair(FileName(), FileName());
312 }
313
314
315 // Specification of document_dir_ may be reset by LyXRC,
316 // but the default is fixed for a given OS.
317 FileName const get_document_dir(FileName const & home_dir)
318 {
319 #if defined (USE_WINDOWS_PACKAGING)
320         (void)home_dir; // Silence warning about unused variable.
321         os::GetFolderPath win32_folder_path;
322         return FileName(win32_folder_path(os::GetFolderPath::PERSONAL));
323 #else // Posix-like.
324         return home_dir;
325 #endif
326 }
327
328
329 // The specification of home_dir_ is fixed for a given OS.
330 // A typical example on Windows: "C:/Documents and Settings/USERNAME"
331 // and on a Posix-like machine: "/home/USERNAME".
332 FileName const get_home_dir()
333 {
334 #if defined (USE_WINDOWS_PACKAGING)
335         string const home_dir = getEnv("USERPROFILE");
336 #else // Posix-like.
337         string const home_dir = getEnv("HOME");
338 #endif
339
340         return FileName(fix_dir_name(home_dir));
341 }
342
343
344 // Several sources are probed to ascertain the locale directory.
345 // The only requirement is that the result is indeed a directory.
346 FileName const get_locale_dir(FileName const & system_support_dir)
347 {
348         // 1. Use the "LYX_LOCALEDIR" environment variable.
349         FileName const path_env = extract_env_var_dir("LYX_LOCALEDIR");
350         if (!path_env.empty() && check_env_var_dir(path_env, "LYX_LOCALEDIR"))
351                 return path_env;
352
353         // 2. Search for system_support_dir / <relative locale dir>
354         // The <relative locale dir> is OS-dependent. (On Unix, it will
355         // be "../locale/".)
356         FileName path(normalizePath(addPath(system_support_dir.absFilename(),
357                                             relative_locale_dir())));
358
359         if (path.exists() && fs::is_directory(path.toFilesystemEncoding()))
360                 return path;
361
362         // 3. Fall back to the hard-coded LOCALEDIR.
363         path = hardcoded_localedir();
364         if (path.exists() && fs::is_directory(path.toFilesystemEncoding()))
365                 return path;
366
367         return FileName();
368 }
369
370
371 // Specification of temp_dir_ may be reset by LyXRC,
372 // but the default is fixed for a given OS.
373 FileName const get_temp_dir()
374 {
375 #if defined (USE_WINDOWS_PACKAGING)
376         // Typical example: C:/TEMP/.
377         char path[MAX_PATH];
378         GetTempPath(MAX_PATH, path);
379         return FileName(os::internal_path(to_utf8(from_local8bit(path))));
380 #else // Posix-like.
381         return FileName("/tmp");
382 #endif
383 }
384
385
386 // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
387 FileName const abs_path_from_command_line(string const & command_line)
388 {
389         if (command_line.empty())
390                 return FileName();
391
392         string const path = fix_dir_name(command_line);
393         return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path);
394 }
395
396
397 // Does the grunt work for abs_path_from_binary_name()
398 FileName const get_binary_path(string const & exe)
399 {
400 #if defined (USE_WINDOWS_PACKAGING)
401         // The executable may have been invoked either with or
402         // without the .exe extension.
403         // Ensure that it is present.
404         string const as_internal_path = os::internal_path(exe);
405         string const exe_path = suffixIs(as_internal_path, ".exe") ?
406                 as_internal_path : as_internal_path + ".exe";
407 #else
408         string const exe_path = os::internal_path(exe);
409 #endif
410         if (os::is_absolute_path(exe_path))
411                 return FileName(exe_path);
412
413         // Two possibilities present themselves.
414         // 1. The binary is relative to the CWD.
415         FileName const abs_exe_path = makeAbsPath(exe_path);
416         if (abs_exe_path.exists())
417                 return abs_exe_path;
418
419         // 2. exe must be the name of the binary only and it
420         // can be found on the PATH.
421         string const exe_name = onlyFilename(exe_path);
422         if (exe_name != exe_path)
423                 return FileName();
424
425         std::vector<string> const path = getEnvPath("PATH");
426         std::vector<string>::const_iterator it = path.begin();
427         std::vector<string>::const_iterator const end = path.end();
428         for (; it != end; ++it) {
429                 // This will do nothing if *it is already absolute.
430                 string const exe_dir = makeAbsPath(*it).absFilename();
431
432                 FileName const exe_path(addName(exe_dir, exe_name));
433                 if (exe_path.exists())
434                         return exe_path;
435         }
436
437         // Didn't find anything.
438         return FileName();
439 }
440
441
442 // Extracts the absolute path to the binary name received as argv[0].
443 FileName const abs_path_from_binary_name(string const & exe)
444 {
445         FileName const abs_binary = get_binary_path(exe);
446         if (abs_binary.empty()) {
447                 // FIXME UNICODE
448                 throw ExceptionMessage(ErrorException,
449                         _("LyX binary not found"),
450                         bformat(_("Unable to determine the path to the LyX binary from the command line %1$s"),
451                                 from_utf8(exe)));
452         }
453         return abs_binary;
454 }
455
456
457 // A plethora of directories is searched to ascertain the system
458 // lyxdir which is defined as the first directory to contain
459 // "chkconfig.ltx".
460 FileName const
461 get_system_support_dir(FileName const & abs_binary,
462                   string const & command_line_system_support_dir)
463 {
464         string const chkconfig_ltx = "chkconfig.ltx";
465
466         // searched_dirs is used for diagnostic purposes only in the case
467         // that "chkconfig.ltx" is not found.
468         std::list<FileName> searched_dirs;
469
470         // 1. Use the -sysdir command line parameter.
471         FileName path = abs_path_from_command_line(command_line_system_support_dir);
472         if (!path.empty()) {
473                 searched_dirs.push_back(path);
474                 if (check_command_line_dir(path.absFilename(), chkconfig_ltx, "-sysdir"))
475                         return path;
476         }
477
478         // 2. Use the "LYX_DIR_15x" environment variable.
479         path = extract_env_var_dir("LYX_DIR_15x");
480         if (!path.empty()) {
481                 searched_dirs.push_back(path);
482                 if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_15x"))
483                         return path;
484         }
485
486         // 3. Search relative to the lyx binary.
487         // We're looking for "chkconfig.ltx" in a directory
488         //   OnlyPath(abs_binary) / <relative dir> / PACKAGE /
489         // PACKAGE is hardcoded in config.h. Eg "lyx" or "lyx-1.3.6cvs".
490         // <relative dir> is OS-dependent; on Unix, it will be "../share/".
491         string const relative_lyxdir = relative_system_support_dir();
492
493         // One subtlety to be aware of. The name of the lyx binary may be
494         // a symbolic link. If that is the case, then we follow the links too.
495         FileName binary = abs_binary;
496         while (true) {
497                 // Try and find "chkconfig.ltx".
498                 string const binary_dir = onlyPath(binary.absFilename());
499
500                 FileName const lyxdir(
501                         normalizePath(addPath(binary_dir, relative_lyxdir)));
502                 searched_dirs.push_back(lyxdir);
503
504                 if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
505                         // Success! "chkconfig.ltx" has been found.
506                         return lyxdir;
507                 }
508
509                 // Check whether binary is a symbolic link.
510                 // If so, resolve it and repeat the exercise.
511                 if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
512                         break;
513
514                 FileName link;
515                 if (readLink(binary, link)) {
516                         binary = link;
517                 } else {
518                         // Unable to resolve the link.
519                         break;
520                 }
521         }
522
523         // 4. Repeat the exercise on the directory itself.
524         FileName binary_dir(onlyPath(abs_binary.absFilename()));
525         while (true) {
526                 // This time test whether the directory is a symbolic link
527                 // *before* looking for "chkconfig.ltx".
528                 // (We've looked relative to the original already.)
529                 if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
530                         break;
531
532                 FileName link;
533                 if (readLink(binary_dir, link)) {
534                         binary_dir = link;
535                 } else {
536                         // Unable to resolve the link.
537                         break;
538                 }
539
540                 // Try and find "chkconfig.ltx".
541                 FileName const lyxdir(
542                         normalizePath(addPath(binary_dir.absFilename(), relative_lyxdir)));
543                 searched_dirs.push_back(lyxdir);
544
545                 if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
546                         // Success! "chkconfig.ltx" has been found.
547                         return lyxdir;
548                 }
549         }
550
551         // 5. In desparation, try the hard-coded system support dir.
552         path = hardcoded_system_support_dir();
553         if (!fileSearch(path.absFilename(), chkconfig_ltx).empty())
554                 return path;
555
556         // Everything has failed :-(
557         // So inform the user and exit.
558         string searched_dirs_str;
559         typedef std::list<FileName>::const_iterator iterator;
560         iterator const begin = searched_dirs.begin();
561         iterator const end = searched_dirs.end();
562         for (iterator it = begin; it != end; ++it) {
563                 if (it != begin)
564                         searched_dirs_str += "\n\t";
565                 searched_dirs_str += it->absFilename();
566         }
567
568         // FIXME UNICODE
569         throw ExceptionMessage(ErrorException, _("No system directory"),
570                 bformat(_("Unable to determine the system directory "
571                                          "having searched\n"
572                                          "\t%1$s\n"
573                                          "Use the '-sysdir' command line parameter or "
574                                          "set the environment variable LYX_DIR_15x to "
575                                          "the LyX system directory containing the file "
576                                          "`chkconfig.ltx'."),
577                           from_utf8(searched_dirs_str)));
578
579         // Keep the compiler happy.
580         return FileName();
581 }
582
583
584 // Returns the absolute path to the user lyxdir, together with a flag
585 // indicating whether this directory was specified explicitly (as -userdir
586 // or through an environment variable) or whether it was deduced.
587 std::pair<FileName, bool> const
588 get_user_support_dir(FileName const & default_user_support_dir,
589                      string const & command_line_user_support_dir)
590 {
591         bool explicit_userdir = true;
592
593         // 1. Use the -userdir command line parameter.
594         FileName path =
595                 abs_path_from_command_line(command_line_user_support_dir);
596         if (!path.empty())
597                 return std::make_pair(path, explicit_userdir);
598
599         // 2. Use the LYX_USERDIR_15x environment variable.
600         path = extract_env_var_dir("LYX_USERDIR_15x");
601         if (!path.empty())
602                 return std::make_pair(path, explicit_userdir);
603
604         // 3. Use the OS-dependent default_user_support_dir
605         explicit_userdir = false;
606         return std::make_pair(default_user_support_dir, explicit_userdir);
607 }
608
609
610 // $HOME/.lyx on POSIX but on Win32 it will be something like
611 // "C:/Documents and Settings/USERNAME/Application Data/LyX"
612 FileName const get_default_user_support_dir(FileName const & home_dir)
613 {
614 #if defined (USE_WINDOWS_PACKAGING)
615         (void)home_dir; // Silence warning about unused variable.
616
617         os::GetFolderPath win32_folder_path;
618         return FileName(addPath(win32_folder_path(os::GetFolderPath::APPDATA), PACKAGE));
619
620 #elif defined (USE_MACOSX_PACKAGING)
621         (void)home_dir; // Silence warning about unused variable.
622
623         FSRef fsref;
624         OSErr const error_code =
625                 FSFindFolder(kUserDomain, kApplicationSupportFolderType,
626                              kDontCreateFolder, &fsref);
627         if (error_code != 0)
628                 return FileName();
629
630         // FSRefMakePath returns the result in utf8
631         char store[PATH_MAX + 1];
632         OSStatus const status_code =
633                 FSRefMakePath(&fsref,
634                               reinterpret_cast<UInt8*>(store), PATH_MAX);
635         if (status_code != 0)
636                 return FileName();
637
638         return FileName(addPath(reinterpret_cast<char const *>(store), PACKAGE));
639
640 #else // USE_POSIX_PACKAGING
641         return FileName(addPath(home_dir.absFilename(), string(".") + PACKAGE));
642 #endif
643 }
644
645
646 // Check that directory @c dir contains @c file.
647 // Else emit a warning about an invalid @c command_line_switch.
648 bool check_command_line_dir(string const & dir,
649                             string const & file,
650                             string const & command_line_switch)
651 {
652         FileName const abs_path = fileSearch(dir, file);
653         if (abs_path.empty()) {
654                 // FIXME UNICODE
655                 throw ExceptionMessage(WarningException, _("File not found"), bformat(
656                         _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
657                         from_utf8(command_line_switch), from_utf8(dir),
658                         from_utf8(file)));
659         }
660
661         return !abs_path.empty();
662 }
663
664
665 // The environment variable @c env_var expands to a (single) file path.
666 FileName const extract_env_var_dir(string const & env_var)
667 {
668         string const dir = fix_dir_name(getEnv(env_var));
669         return dir.empty() ? FileName() : makeAbsPath(dir);
670 }
671
672
673 // Check that directory @c dir contains @c file.
674 // Else emit a warning about an invalid @c env_var.
675 bool check_env_var_dir(FileName const & dir,
676                        string const & file,
677                        string const & env_var)
678 {
679         FileName const abs_path = fileSearch(dir.absFilename(), file);
680         if (abs_path.empty()) {
681                 // FIXME UNICODE
682                 throw ExceptionMessage(WarningException, _("File not found"), bformat(
683                         _("Invalid %1$s environment variable.\n"
684                                 "Directory %2$s does not contain %3$s."),
685                         from_utf8(env_var), from_utf8(dir.absFilename()),
686                         from_utf8(file)));
687         }
688
689         return !abs_path.empty();
690 }
691
692
693 // Check that directory @c dir is indeed a directory.
694 // Else emit a warning about an invalid @c env_var.
695 bool check_env_var_dir(FileName const & dir,
696                        string const & env_var)
697 {
698         bool const success = dir.exists() && dir.isDirectory();
699
700         if (!success) {
701                 // Put this string on a single line so that the gettext
702                 // search mechanism in po/Makefile.in.in will register
703                 // Package.cpp.in as a file containing strings that need
704                 // translation.
705                 // FIXME UNICODE
706                 docstring const fmt =
707                         _("Invalid %1$s environment variable.\n%2$s is not a directory.");
708
709                 throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
710                         fmt, from_utf8(env_var), from_utf8(dir.absFilename())));
711         }
712
713         return success;
714 }
715
716
717 // The locale directory relative to the LyX system directory.
718 string const relative_locale_dir()
719 {
720 #if defined (USE_WINDOWS_PACKAGING) || defined (USE_MACOSX_PACKAGING)
721         return "locale/";
722 #else
723         return "../locale/";
724 #endif
725 }
726
727
728 // The system lyxdir is relative to the directory containing the LyX binary.
729 string const relative_system_support_dir()
730 {
731         string result;
732
733 #if defined (USE_WINDOWS_PACKAGING) || defined (USE_MACOSX_PACKAGING)
734         result = "../Resources/";
735 #else // Posix-like.
736         result = addPath("../share/", PACKAGE);
737 #endif
738
739         return result;
740 }
741
742 } // namespace anon
743
744 } // namespace support
745 } // namespace lyx