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