Index: code/branches/buildsystem3/src/core/ArgumentCompletionFunctions.cc
===================================================================
--- code/branches/buildsystem3/src/core/ArgumentCompletionFunctions.cc	(revision 2692)
+++ code/branches/buildsystem3/src/core/ArgumentCompletionFunctions.cc	(revision 2702)
@@ -27,10 +27,10 @@
  */
 
+#include "ArgumentCompletionFunctions.h"
+
 #include <iostream>
 #include <map>
-
 #include <boost/filesystem.hpp>
 
-#include "ArgumentCompletionFunctions.h"
 #include "CoreIncludes.h"
 #include "Identifier.h"
@@ -68,5 +68,5 @@
                     std::string dir = startdirectory.string();
                     if (dir.size() > 0 && dir[dir.size() - 1] == ':')
-                        startdirectory = dir + "/";
+                        startdirectory = dir + CP_SLASH;
                 }
 #endif
@@ -78,5 +78,5 @@
                 {
                     if (boost::filesystem::is_directory(*file))
-                        dirlist.push_back(ArgumentCompletionListElement((*file).string() + "/", getLowercase((*file).string()) + "/", (*file).leaf() + "/"));
+                        dirlist.push_back(ArgumentCompletionListElement((*file).string() + CP_SLASH, getLowercase((*file).string()) + "/", (*file).leaf() + "/"));
                     else
                         filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).leaf()));
Index: code/branches/buildsystem3/src/core/CommandLine.cc
===================================================================
--- code/branches/buildsystem3/src/core/CommandLine.cc	(revision 2692)
+++ code/branches/buildsystem3/src/core/CommandLine.cc	(revision 2702)
@@ -302,6 +302,5 @@
 
         std::string filename = CommandLine::getValue("optionsFile").getString();
-        boost::filesystem::path folder(Core::getConfigPath());
-        boost::filesystem::path filepath(folder/filename);
+        boost::filesystem::path filepath(Core::getConfigPath() / filename);
 
         // look for additional arguments in given file or start.ini as default
Index: code/branches/buildsystem3/src/core/ConfigFileManager.cc
===================================================================
--- code/branches/buildsystem3/src/core/ConfigFileManager.cc	(revision 2692)
+++ code/branches/buildsystem3/src/core/ConfigFileManager.cc	(revision 2702)
@@ -227,11 +227,9 @@
 
         // Get default file if necessary and available
-        boost::filesystem::path filepath(Core::getConfigPath());
-        filepath /= this->filename_;
+        boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
         if (!boost::filesystem::exists(filepath))
         {
             // Try to get default one from the media folder
-            boost::filesystem::path defaultFilepath(Core::getMediaPath());
-            defaultFilepath = defaultFilepath / "defaultConfig" / this->filename_;
+            boost::filesystem::path defaultFilepath(Core::getMediaPath() / "defaultConfig" / this->filename_);
             if (boost::filesystem::exists(defaultFilepath))
             {
@@ -345,6 +343,5 @@
     void ConfigFile::save() const
     {
-        boost::filesystem::path filepath(Core::getConfigPath());
-        filepath /= this->filename_;
+        boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
 
         std::ofstream file;
Index: code/branches/buildsystem3/src/core/Core.cc
===================================================================
--- code/branches/buildsystem3/src/core/Core.cc	(revision 2692)
+++ code/branches/buildsystem3/src/core/Core.cc	(revision 2702)
@@ -33,8 +33,22 @@
 
 #include "Core.h"
+
 #include <cassert>
 #include <fstream>
+#include <cstdlib>
+#include <cstdio>
 #include <boost/filesystem.hpp>
 
+#ifdef ORXONOX_PLATFORM_WINDOWS
+#  include <windows.h>
+#elif defined(ORXONOX_PLATFORM_APPLE)
+#  include <sys/param.h>
+#  include <mach-o/dyld.h>
+#else /* Linux */
+#  include <sys/types.h>
+#  include <unistd.h>
+#endif
+
+#include "SpecialConfig.h"
 #include "util/Exception.h"
 #include "Language.h"
@@ -46,4 +60,11 @@
 namespace orxonox
 {
+    //! Path to the parent directory of the ones above if program was installed with relativ pahts
+    static boost::filesystem::path rootPath_g;
+    static boost::filesystem::path executablePath_g;            //!< Path to the executable
+    static boost::filesystem::path mediaPath_g;                 //!< Path to the media file folder
+    static boost::filesystem::path configPath_g;                //!< Path to the config file folder
+    static boost::filesystem::path logPath_g;                   //!< Path to the log file folder
+
     bool Core::bShowsGraphics_s = false;
     bool Core::bHasServer_s     = false;
@@ -53,9 +74,5 @@
 
     bool Core::isDevBuild_s     = false;
-    std::string Core::configPath_s(ORXONOX_CONFIG_INSTALL_PATH); // from OrxonoxConfig.h
-    std::string Core::logPath_s   (ORXONOX_LOG_INSTALL_PATH);    // from OrxonoxConfig.h
-    std::string Core::mediaPath_s (ORXONOX_MEDIA_INSTALL_PATH);  // from OrxonoxConfig.h
-
-    Core* Core::singletonRef_s = 0;
+    Core* Core::singletonRef_s  = 0;
 
     SetCommandLineArgument(mediaPath, "").information("PATH");
@@ -76,11 +93,11 @@
 
         // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used
-        OutputHandler::getOutStream().setLogPath(Core::logPath_s);
+        OutputHandler::getOutStream().setLogPath(Core::getLogPathString());
 
         // Possible media path override by the command line
         if (!CommandLine::getArgument("mediaPath")->hasDefaultValue())
         {
-            std::string mediaPath = CommandLine::getValue("mediaPath");
-            Core::tsetMediaPath(mediaPath);
+            //std::string mediaPath = CommandLine::getValue("mediaPath");
+            Core::tsetMediaPath(CommandLine::getValue("mediaPath"));
         }
     }
@@ -119,12 +136,6 @@
         SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator);
 
-        // Media path (towards config and log path) is ini-configurable
-        const char* defaultMediaPath = ORXONOX_MEDIA_INSTALL_PATH;
-        if (Core::isDevBuild())
-            defaultMediaPath = ORXONOX_MEDIA_DEV_PATH;
-
-        SetConfigValue(mediaPath_s, defaultMediaPath)
+        SetConfigValue(mediaPathString_, Core::getMediaPathPOSIXString())
             .description("Relative path to the game data.").callback(this, &Core::mediaPathChanged);
-
     }
 
@@ -162,14 +173,5 @@
     void Core::mediaPathChanged()
     {
-        if (mediaPath_s != "" && mediaPath_s[mediaPath_s.size() - 1] != '/')
-        {
-            ModifyConfigValue(mediaPath_s, set, mediaPath_s + "/");
-        }
-
-        if (mediaPath_s == "")
-        {
-            ModifyConfigValue(mediaPath_s, set, "/");
-            COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl;
-        }
+        mediaPath_g = boost::filesystem::path(this->mediaPathString_);
     }
 
@@ -248,12 +250,45 @@
     void Core::_tsetMediaPath(const std::string& path)
     {
-        if (*path.end() != '/' && *path.end() != '\\')
-        {
-            ModifyConfigValue(mediaPath_s, tset, path + "/");
-        }
-        else
-        {
-            ModifyConfigValue(mediaPath_s, tset, path);
-        }
+        ModifyConfigValue(mediaPathString_, tset, path);
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getMediaPath()
+    {
+        return mediaPath_g;
+    }
+    /*static*/ std::string Core::getMediaPathString()
+    {
+        return mediaPath_g.directory_string() + CP_SLASH;
+    }
+    /*static*/ std::string Core::getMediaPathPOSIXString()
+    {
+        return mediaPath_g.string() + '/';
+        
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getConfigPath()
+    {
+        return configPath_g;
+    }
+    /*static*/ std::string Core::getConfigPathString()
+    {
+        return configPath_g.directory_string() + CP_SLASH;
+    }
+    /*static*/ std::string Core::getConfigPathPOSIXString()
+    {
+        return configPath_g.string() + '/';
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getLogPath()
+    {
+        return logPath_g;
+    }
+    /*static*/ std::string Core::getLogPathString()
+    {
+        return logPath_g.directory_string() + CP_SLASH;
+    }
+    /*static*/ std::string Core::getLogPathPOSIXString()
+    {
+        return logPath_g.string() + '/';
     }
 
@@ -271,5 +306,76 @@
     /**
     @brief
-        Checks for "orxonox_dev_build.keep_me" in the working diretory.
+        Performs the rather lower level operations just after
+        int main() has been called.
+    @remarks
+        This gets called AFTER pre-main stuff like AddFactory,
+        SetConsoleCommand, etc.
+    */
+    /*static*/ void Core::postMainInitialisation()
+    {
+        // set location of the executable
+        Core::setExecutablePath();
+
+        // Determine whether we have an installed or a binary dir run
+        // The latter occurs when simply running from the build directory
+        Core::checkDevBuild();
+
+        // Make sure the directories we write in exist or else make them
+        Core::createDirectories();
+    }
+
+    /**
+    @brief
+        Compares the executable path with the working directory
+    */
+    /*static*/ void Core::setExecutablePath()
+    {
+#ifdef ORXONOX_PLATFORM_WINDOWS
+        // get executable module
+        TCHAR buffer[1024];
+        if (GetModuleFileName(NULL, buffer, 1024) == 0)
+            ThrowException(General, "Could not retrieve executable path.");
+
+#elif defined(ORXONOX_PLATFORM_APPLE)
+        char buffer[1024];
+        unsigned long path_len = 1023;
+        if (_NSGetExecutablePath(buffer, &path_len))
+            ThrowException(General, "Could not retrieve executable path.");
+
+#else /* Linux */
+        /* written by Nicolai Haehnle <prefect_@gmx.net> */
+
+        /* Get our PID and build the name of the link in /proc */
+        char linkname[64]; /* /proc/<pid>/exe */
+        if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)
+        {
+            /* This should only happen on large word systems. I'm not sure
+               what the proper response is here.
+               Since it really is an assert-like condition, aborting the
+               program seems to be in order. */
+            assert(false);
+        }
+
+        /* Now read the symbolic link */
+        char buffer[1024];
+        int ret;
+        ret = readlink(linkname, buffer, 1024);
+        /* In case of an error, leave the handling up to the caller */
+        if (ret == -1)
+            ThrowException(General, "Could not retrieve executable path.");
+
+        /* Ensure proper NUL termination */
+        buf[ret] = 0;
+#endif
+
+        executablePath_g = boost::filesystem::path(buffer);
+#ifndef ORXONOX_PLATFORM_APPLE
+        executablePath_g = executablePath_g.branch_path(); // remove executable name
+#endif
+    }
+
+    /**
+    @brief
+        Checks for "orxonox_dev_build.keep_me" in the executable diretory.
         If found it means that this is not an installed run, hence we
         don't write the logs and config files to ~/.orxonox
@@ -277,14 +383,46 @@
     /*static*/ void Core::checkDevBuild()
     {
-        std::ifstream probe;
-        probe.open("orxonox_dev_build.keep_me");
-        if (probe)
-        {
+        if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me"))
+        {
+            COUT(1) << "Running from the build tree." << std::endl;
             Core::isDevBuild_s = true;
-            // Constants are taken from OrxonoxConfig.h
-            Core::configPath_s = ORXONOX_CONFIG_DEV_PATH;
-            Core::logPath_s    = ORXONOX_LOG_DEV_PATH;
-            Core::mediaPath_s  = ORXONOX_MEDIA_DEV_PATH;
-            probe.close();
+            mediaPath_g  = ORXONOX_MEDIA_DEV_PATH;
+            configPath_g = ORXONOX_CONFIG_DEV_PATH;
+            logPath_g    = ORXONOX_LOG_DEV_PATH;
+        }
+        else
+        {
+#ifdef INSTALL_COPYABLE // --> relative paths
+            // Also set the root path
+            boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
+            rootPath_g = executablePath_g;
+            while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) || rootPath_g.empty())
+                rootPath_g = rootPath_g.branch_path();
+            if (rootPath_g.empty())
+                ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
+
+            // Using paths relative to the install prefix, complete them
+            mediaPath_g  = rootPath_g / ORXONOX_MEDIA_INSTALL_PATH;
+            configPath_g = rootPath_g / ORXONOX_CONFIG_INSTALL_PATH;
+            logPath_g    = rootPath_g / ORXONOX_LOG_INSTALL_PATH;
+#else
+            // There is no root path, so don't set it at all
+
+            mediaPath_g  = ORXONOX_MEDIA_INSTALL_PATH;
+
+            // Get user directory
+#  ifdef ORXONOX_PLATFORM_UNIX /* Apple? */
+            char* userDataPathPtr(getenv("HOME"));
+#  else
+            char* userDataPathPtr(getenv("APPDATA"));
+#  endif
+            if (userDataPathPtr == NULL)
+                ThrowException(General, "Could not retrieve user data path.");
+            boost::filesystem::path userDataPath(userDataPathPtr);
+            userDataPath /= ".orxonox";
+
+            configPath_g = userDataPath / ORXONOX_CONFIG_INSTALL_PATH;
+            logPath_g    = userDataPath / ORXONOX_LOG_INSTALL_PATH;
+#endif
         }
     }
@@ -299,7 +437,7 @@
         std::vector<std::pair<boost::filesystem::path, std::string> > directories;
         directories.push_back(std::pair<boost::filesystem::path, std::string>
-            (boost::filesystem::path(Core::configPath_s), "config"));
+            (boost::filesystem::path(configPath_g), "config"));
         directories.push_back(std::pair<boost::filesystem::path, std::string>
-            (boost::filesystem::path(Core::logPath_s),    "log"));
+            (boost::filesystem::path(logPath_g),    "log"));
 
         for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin();
Index: code/branches/buildsystem3/src/core/Core.h
===================================================================
--- code/branches/buildsystem3/src/core/Core.h	(revision 2692)
+++ code/branches/buildsystem3/src/core/Core.h	(revision 2702)
@@ -44,6 +44,13 @@
 #include "util/OutputHandler.h"
 
-// Only allow main to access setDevBuild, so we need a forward declaration
+// Only allow main to access postMainInitialisation, so we need a forward declaration
 int main(int, char**);
+// boost::filesystem header has quite a large tail, use forward declaration
+namespace boost { namespace filesystem
+{
+    struct path_traits;
+    template<class String, class Traits> class basic_path;
+    typedef basic_path< std::string, path_traits> path;
+} }
 
 namespace orxonox
@@ -70,7 +77,13 @@
             static void tsetMediaPath(const std::string& path)
             { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); }
-            static const std::string& getMediaPath()  { return mediaPath_s; }
-            static const std::string& getConfigPath() { return configPath_s; }
-            static const std::string& getLogPath()    { return logPath_s; }
+            static const boost::filesystem::path& getMediaPath();
+            static const boost::filesystem::path& getConfigPath();
+            static const boost::filesystem::path& getLogPath();
+            static std::string getMediaPathString();
+            static std::string getConfigPathString();
+            static std::string getLogPathString();
+            static std::string getMediaPathPOSIXString();
+            static std::string getConfigPathPOSIXString();
+            static std::string getLogPathPOSIXString();
 
             // fast access global variables.
@@ -95,6 +108,8 @@
             void _tsetMediaPath(const std::string& path);
 
+            static void postMainInitialisation();
+            static void checkDevBuild();
+            static void setExecutablePath();
             static void createDirectories();
-            static void checkDevBuild();
 
             int softDebugLevel_;                            //!< The debug level
@@ -104,4 +119,5 @@
             std::string language_;                          //!< The language
             bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
+            std::string mediaPathString_;                   //!< Path to the data/media file folder as string
 
             static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
@@ -112,7 +128,4 @@
 
             static bool isDevBuild_s;                       //!< True for builds in the build directory (not installed)
-            static std::string configPath_s;                //!< Path to the config file folder
-            static std::string logPath_s;                   //!< Path to the log file folder
-            static std::string mediaPath_s;                 //!< Path to the data/media file folder
 
             static Core* singletonRef_s;
Index: code/branches/buildsystem3/src/core/Language.cc
===================================================================
--- code/branches/buildsystem3/src/core/Language.cc	(revision 2692)
+++ code/branches/buildsystem3/src/core/Language.cc	(revision 2702)
@@ -206,6 +206,5 @@
         COUT(4) << "Read default language file." << std::endl;
 
-        boost::filesystem::path folder(Core::getConfigPath());
-        boost::filesystem::path filepath(folder/getFilename(this->defaultLanguage_));
+        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
 
         // This creates the file if it's not existing
@@ -258,6 +257,5 @@
         COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl;
 
-        boost::filesystem::path folder(Core::getConfigPath());
-        boost::filesystem::path filepath(folder/getFilename(Core::getLanguage()));
+        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage()));
 
         // Open the file
@@ -315,6 +313,5 @@
         COUT(4) << "Language: Write default language file." << std::endl;
 
-        boost::filesystem::path folder(Core::getConfigPath());
-        boost::filesystem::path filepath(folder/getFilename(this->defaultLanguage_));
+        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
 
         // Open the file
Index: code/branches/buildsystem3/src/core/LuaBind.cc
===================================================================
--- code/branches/buildsystem3/src/core/LuaBind.cc	(revision 2692)
+++ code/branches/buildsystem3/src/core/LuaBind.cc	(revision 2702)
@@ -53,5 +53,5 @@
     LuaBind::singletonRef_s = this;
 
-    this->includePath_ = Core::getMediaPath();
+    this->includePath_ = Core::getMediaPathPOSIXString();
 
     luaState_ = lua_open();
Index: code/branches/buildsystem3/src/core/TclBind.cc
===================================================================
--- code/branches/buildsystem3/src/core/TclBind.cc	(revision 2692)
+++ code/branches/buildsystem3/src/core/TclBind.cc	(revision 2702)
@@ -62,5 +62,6 @@
     void TclBind::setDataPath(const std::string& datapath)
     {
-        this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/";
+        // String has POSIX slashes
+        this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/';
         this->bSetTclLibPath_ = true;
 
