packaging tweaks for OS X
[ardour.git] / gtk2_ardour / main.cc
index 6af714a02f1b423e08c8eec972386f8f4514c5c8..284192ede24933fce2e26e3434d3e0b75c94e06f 100644 (file)
@@ -21,6 +21,7 @@
 #include <signal.h>
 #include <cerrno>
 #include <fstream>
+#include <vector>
 
 #include <sigc++/bind.h>
 #include <gtkmm/settings.h>
@@ -165,43 +166,26 @@ fixup_bundle_environment (int, char* [])
        }
        setenv ("PATH", path.c_str(), 1);
 
-       path = dir_path;
-       path += "/../Resources";
-       path += dir_path;
-       path += "/../Surfaces";
-       path += dir_path;
-       path += "/../Panners";
+       export_search_path (dir_path, "ARDOUR_DLL_PATH", "/../lib");
 
-       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);
+       /* inside an OS X .app bundle, there is no difference
+          between DATA and CONFIG locations, since OS X doesn't
+          attempt to do anything to expose the notion of
+          machine-independent shared data.
+       */
 
-       path = dir_path;
-       path += "/../Resources";
-       setenv ("ARDOUR_INSTANT_XML_PATH", path.c_str(), 1);
+       export_search_path (dir_path, "ARDOUR_DATA_PATH", "/../Resources");
+       export_search_path (dir_path, "ARDOUR_CONFIG_PATH", "/../Resources");
+       export_search_path (dir_path, "ARDOUR_INSTANT_XML_PATH", "/../Resources");
 
        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";
-
+       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
@@ -289,6 +273,10 @@ fixup_bundle_environment (int, char* [])
 void
 fixup_bundle_environment (int /*argc*/, char* argv[])
 {
+       /* THIS IS FOR LINUX - its just about the only place where its
+        * acceptable to build paths directly using '/'.
+        */
+
        if (!getenv ("ARDOUR_BUNDLED")) {
                return;
        }
@@ -299,48 +287,17 @@ fixup_bundle_environment (int /*argc*/, char* argv[])
        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, "ARDOUR_DLL_PATH", "/lib");
+       export_search_path (dir_path, "ARDOUR_CONFIG_PATH", "/etc");
+       export_search_path (dir_path, "ARDOUR_INSTANT_XML_PATH", "/share");
+       export_search_path (dir_path, "ARDOUR_DATA_PATH", "/share");
 
        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/export");
 
        path = dir_path;
        path += "/lib/clearlooks";
@@ -359,6 +316,22 @@ fixup_bundle_environment (int /*argc*/, char* argv[])
                setenv ("GTK_LOCALEDIR", localedir, 1);
        }
 
+       /* Tell fontconfig where to find fonts.conf. Use the system version
+          if it exists, otherwise use the stuff we included in the bundle
+       */
+
+       if (Glib::file_test ("/etc/fonts/fonts.conf", Glib::FILE_TEST_EXISTS)) {
+               setenv ("FONTCONFIG_FILE", "/etc/fonts/fonts.conf", 1);
+               setenv ("FONTCONFIG_PATH", "/etc/fonts", 1);
+       } else {
+               /* use the one included in the bundle */
+               
+               path = Glib::build_filename (dir_path, "etc/fonts/fonts.conf");
+               setenv ("FONTCONFIG_FILE", path.c_str(), 1);
+               path = Glib::build_filename (dir_path, "etc/fonts");
+               setenv ("FONTCONFIG_PATH", "/etc/fonts", 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 ...
@@ -370,32 +343,32 @@ fixup_bundle_environment (int /*argc*/, char* argv[])
        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.
-               */
+               return;
+       } 
 
-               mpath = Glib::build_filename (userconfigdir, "gdk-pixbuf.loaders");
-               setenv ("GDK_PIXBUF_MODULE_FILE", mpath.c_str(), 1);
+       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
@@ -527,7 +500,7 @@ int main (int argc, char *argv[])
        }
 
        if (no_splash) {
-               cerr << _("Copyright (C) 1999-2011 Paul Davis") << endl
+               cerr << _("Copyright (C) 1999-2012 Paul Davis") << endl
                     << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
                     << endl
                     << string_compose (_("%1 comes with ABSOLUTELY NO WARRANTY"), PROGRAM_NAME) << endl