-static void export_search_path (const string& base_dir, const char* varname, const char* dir)
-{
- string path;
- const char * cstr = getenv (varname);
-
- if (cstr) {
- path = cstr;
- path += ':';
- } else {
- path = "";
- }
- path += base_dir;
- path += dir;
-
- setenv (varname, path.c_str(), 1);
-}
-
-#ifdef __APPLE__
-
-#include <mach-o/dyld.h>
-#include <sys/param.h>
-
-extern void set_language_preference (); // cocoacarbon.mm
-
-void
-fixup_bundle_environment (int, char* [])
-{
- if (!getenv ("ARDOUR_BUNDLED")) {
- return;
- }
-
- EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true, "PREBUNDLE_ENV"));
-
- set_language_preference ();
-
- char execpath[MAXPATHLEN+1];
- uint32_t pathsz = sizeof (execpath);
-
- _NSGetExecutablePath (execpath, &pathsz);
-
- std::string dir_path = Glib::path_get_dirname (execpath);
- std::string path;
- const char *cstr = getenv ("PATH");
-
- /* ensure that we find any bundled executables (e.g. JACK),
- and find them before any instances of the same name
- elsewhere in PATH
- */
-
- path = dir_path;
-
- /* JACK is often in /usr/local/bin and since Info.plist refuses to
- set PATH, we have to force this in order to discover a running
- instance of JACK ...
- */
-
- path += ':';
- path += "/usr/local/bin";
-
- if (cstr) {
- path += ':';
- path += cstr;
- }
- setenv ("PATH", path.c_str(), 1);
-
- path = dir_path;
- path += "/../Resources";
- path += dir_path;
- path += "/../Surfaces";
- path += dir_path;
- path += "/../Panners";
-
- setenv ("ARDOUR_MODULE_PATH", path.c_str(), 1);
-
- path = user_config_directory().to_string();
- path += ':';
- path += dir_path;
- path += "/../Resources/icons:";
- path += dir_path;
- path += "/../Resources/pixmaps:";
- path += dir_path;
- path += "/../Resources/share:";
- path += dir_path;
- path += "/../Resources";
-
- setenv ("ARDOUR_PATH", path.c_str(), 1);
- setenv ("ARDOUR_CONFIG_PATH", path.c_str(), 1);
-
- path = dir_path;
- path += "/../Resources";
- setenv ("ARDOUR_INSTANT_XML_PATH", path.c_str(), 1);
-
- export_search_path (dir_path, "LADSPA_PATH", "/../Plugins");
- export_search_path (dir_path, "VAMP_PATH", "/../Frameworks");
- export_search_path (dir_path, "ARDOUR_PANNER_PATH", "/../Panners");
- export_search_path (dir_path, "ARDOUR_SURFACES_PATH", "/../Surfaces");
- export_search_path (dir_path, "ARDOUR_MIDIMAPS_PATH", "/../MidiMaps");
- export_search_path (dir_path, "ARDOUR_EXPORT_FORMATS_PATH", "/../ExportFormats");
-
- path = dir_path;
- path += "/../Frameworks/clearlooks";
-
- setenv ("GTK_PATH", path.c_str(), 1);
-
- /* unset GTK_RC_FILES so that we only load the RC files that we define
- */
-
- unsetenv ("GTK_RC_FILES");
-
- if (!ARDOUR::translations_are_disabled ()) {
-
- path = dir_path;
- path += "/../Resources/locale";
-
- localedir = strdup (path.c_str());
- setenv ("GTK_LOCALEDIR", localedir, 1);
- }
-
- /* write a pango.rc file and tell pango to use it. we'd love
- to put this into the PROGRAM_NAME.app bundle and leave it there,
- but the user may not have write permission. so ...
-
- we also have to make sure that the user ardour directory
- actually exists ...
- */
-
- try {
- sys::create_directories (user_config_directory ());
- }
- catch (const sys::filesystem_error& ex) {
- error << _("Could not create user configuration directory") << endmsg;
- }
-
- sys::path pangopath = user_config_directory();
- pangopath /= "pango.rc";
- path = pangopath.to_string();
-
- std::ofstream pangorc (path.c_str());
- if (!pangorc) {
- error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
- return;
- } else {
- pangorc << "[Pango]\nModuleFiles=";
-
- pangopath = dir_path;
- pangopath /= "..";
- pangopath /= "Resources";
- pangopath /= "pango.modules";
-
- pangorc << pangopath.to_string() << endl;
-
- pangorc.close ();
-
- setenv ("PANGO_RC_FILE", path.c_str(), 1);
- }
-
- // gettext charset aliases
-
- setenv ("CHARSETALIASDIR", path.c_str(), 1);
-
- // font config
-
- path = dir_path;
- path += "/../Resources/fonts.conf";
-
- setenv ("FONTCONFIG_FILE", path.c_str(), 1);
-
- // GDK Pixbuf loader module file
-
- path = dir_path;
- path += "/../Resources/gdk-pixbuf.loaders";
-
- setenv ("GDK_PIXBUF_MODULE_FILE", path.c_str(), 1);
-
- if (getenv ("ARDOUR_WITH_JACK")) {
- // JACK driver dir
-
- path = dir_path;
- path += "/../Frameworks";
-
- setenv ("JACK_DRIVER_DIR", path.c_str(), 1);
- }
-}
-
-#else
-
-void
-fixup_bundle_environment (int /*argc*/, char* argv[])
-{
- if (!getenv ("ARDOUR_BUNDLED")) {
- return;
- }
-
- EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true, "PREBUNDLE_ENV"));
-
- Glib::ustring dir_path = Glib::path_get_dirname (Glib::path_get_dirname (argv[0]));
- Glib::ustring path;
- Glib::ustring userconfigdir = user_config_directory().to_string();
-
- /* ensure that we find any bundled executables (e.g. JACK),
- and find them before any instances of the same name
- elsewhere in PATH
- */
-
- /* note that this function is POSIX/Linux specific, so using / as
- a dir separator in this context is just fine.
- */
-
- path = dir_path;
- path += "/etc:";
- path += dir_path;
- path += "/lib/surfaces:";
- path += dir_path;
- path += "/lib/panners:";
-
- setenv ("ARDOUR_MODULE_PATH", path.c_str(), 1);
-
- path = userconfigdir;
- path += ':';
- path += dir_path;
- path += "/etc/icons:";
- path += dir_path;
- path += "/etc/pixmaps:";
- path += dir_path;
- path += "/share:";
- path += dir_path;
- path += "/etc";
-
- setenv ("ARDOUR_PATH", path.c_str(), 1);
- setenv ("ARDOUR_CONFIG_PATH", path.c_str(), 1);
-
- path = dir_path;
- path += "/etc";
- setenv ("ARDOUR_INSTANT_XML_PATH", path.c_str(), 1);
-
- export_search_path (dir_path, "LADSPA_PATH", "/../plugins");
- export_search_path (dir_path, "VAMP_PATH", "/lib");
- export_search_path (dir_path, "ARDOUR_PANNER_PATH", "/lib/panners");
- export_search_path (dir_path, "ARDOUR_SURFACES_PATH", "/lib/surfaces");
- export_search_path (dir_path, "ARDOUR_MIDIMAPS_PATH", "/share/midi_maps");
- export_search_path (dir_path, "ARDOUR_EXPORT_FORMATS_PATH", "/share/exports");
-
- path = dir_path;
- path += "/lib/clearlooks";
- setenv ("GTK_PATH", path.c_str(), 1);
-
- /* unset GTK_RC_FILES so that we only load the RC files that we define
- */
-
- unsetenv ("GTK_RC_FILES");
-
- if (!ARDOUR::translations_are_disabled ()) {
- path = dir_path;
- path += "/share/locale";
-
- localedir = strdup (path.c_str());
- setenv ("GTK_LOCALEDIR", localedir, 1);
- }
-
- /* write a pango.rc file and tell pango to use it. we'd love
- to put this into the Ardour.app bundle and leave it there,
- but the user may not have write permission. so ...
-
- we also have to make sure that the user ardour directory
- actually exists ...
- */
-
- if (g_mkdir_with_parents (userconfigdir.c_str(), 0755) < 0) {
- error << string_compose (_("cannot create user ardour folder %1 (%2)"), userconfigdir, strerror (errno))
- << endmsg;
- } else {
-
- Glib::ustring mpath;
-
- path = Glib::build_filename (userconfigdir, "pango.rc");
-
- std::ofstream pangorc (path.c_str());
- if (!pangorc) {
- error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
- } else {
- mpath = Glib::build_filename (userconfigdir, "pango.modules");
-
- pangorc << "[Pango]\nModuleFiles=";
- pangorc << mpath << endl;
- pangorc.close ();
- }
-
- setenv ("PANGO_RC_FILE", path.c_str(), 1);
-
- /* similar for GDK pixbuf loaders, but there's no RC file required
- to specify where it lives.
- */
-
- mpath = Glib::build_filename (userconfigdir, "gdk-pixbuf.loaders");
- setenv ("GDK_PIXBUF_MODULE_FILE", mpath.c_str(), 1);
- }
-}
-
-#endif
-