From 4cbee7f0c19b9512f2e59e3fd9a637eea96d3509 Mon Sep 17 00:00:00 2001
From: Andrea Shepard <andrea@persephoneslair.org>
Date: Wed, 9 Nov 2016 00:03:24 +0000
Subject: [PATCH] Use --system-libs with llvm-config only when safe and needed

---
 src/SConscript | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/SConscript b/src/SConscript
index 6ba2cf56..507b15db 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1,5 +1,8 @@
 # -*- python -*-
 import os.path
+from distutils.version import LooseVersion
+import subprocess
+
 Import('env testruns')
 
 dist_headers = [
@@ -90,8 +93,16 @@ env.Install("$pkgconfigpath", "../../../libhammer.pc")
 testenv = env.Clone()
 testenv.Append(LIBS=['hammer'], LIBPATH=['.'])
 testenv.ParseConfig('pkg-config --cflags --libs glib-2.0')
-testenv.ParseConfig('%s --cflags --ldflags --libs core executionengine mcjit analysis x86codegen x86info' % \
-                    env["LLVM_CONFIG"])
+testenv_llvm_config_version = subprocess.Popen('%s --version' % env["LLVM_CONFIG"], \
+                                               shell=True, \
+                                               stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate()
+if LooseVersion(testenv_llvm_config_version[0]) < LooseVersion("3.9"):
+    testenv_llvm_system_libs_flag = "--system-libs"
+else:
+    testenv_llvm_system_libs_flag = ""
+
+testenv.ParseConfig('%s --cflags --ldflags --libs %s core executionengine mcjit analysis x86codegen x86info' % \
+                    (env["LLVM_CONFIG"], testenv_llvm_system_libs_flag))
 testenv.Append(LIBS=['stdc++'], LIBPATH=['.'])
 ctestexec = testenv.Program('test_suite', ctests + ['test_suite.c'], LINKFLAGS="--coverage" if testenv.GetOption("coverage") else None)
 ctest = Alias('testc', [ctestexec], "".join(["env LD_LIBRARY_PATH=", os.path.dirname(ctestexec[0].path), " ", ctestexec[0].path]))
-- 
GitLab