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