]> git.cworth.org Git - apitrace/commitdiff
cli: use $LIB to handle multilib automagically on glibc
authorAlexander Monakov <amonakov@ispras.ru>
Wed, 16 Oct 2013 16:51:47 +0000 (20:51 +0400)
committerAlexander Monakov <amonakov@ispras.ru>
Wed, 16 Oct 2013 16:51:47 +0000 (20:51 +0400)
cli/cli_resources.cpp

index a4797e11d414e0b41a35ec2d43c65e74d5714550..d6d0a55d6d5038fe773c41a163934f93f88bf3bf 100644 (file)
 
 #include "cli_resources.hpp"
 
+#ifdef __GLIBC__
+
+#include <dlfcn.h>
+
+static bool
+tryLib(const os::String &path, bool verbose)
+{
+    void *handle = dlopen(path.str(), RTLD_LAZY);
+    bool exists = (handle != NULL);
+    if (verbose) {
+        if (exists) {
+            std::cerr << "info: found " << path.str() << "\n";
+        } else {
+            std::cerr << "info: did not find " << dlerror() << "\n";
+        }
+    }
+    if (exists)
+        dlclose(handle);
+    return exists;
+}
+#endif
 
 static bool
 tryPath(const os::String &path, bool verbose)
@@ -93,6 +114,17 @@ findWrapper(const char *wrapperFilename, bool verbose)
         return wrapperPath;
     }
 
+#ifdef __GLIBC__
+    // We want to take advantage of $LIB dynamic string token expansion in
+    // glibc dynamic linker to handle multilib layout for us
+    wrapperPath = processDir;
+    wrapperPath.join("../$LIB/apitrace/wrappers");
+    wrapperPath.join(wrapperFilename);
+    if (tryLib(wrapperPath, verbose)) {
+        return wrapperPath;
+    }
+#endif
+
     // Try relative install directory
     wrapperPath = processDir;
 #if defined(_WIN32)