aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers.py34
-rw-r--r--mesonbuild/interpreter.py8
2 files changed, 42 insertions, 0 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index e474d2e..9ddaa56 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -1058,6 +1058,40 @@ void bar() {
'''
return self.compiles(templ % (prefix, typename), env, extra_args, dependencies)
+ def symbols_have_underscore_prefix(self, env):
+ '''
+ Check if the compiler prefixes an underscore to global C symbols
+ '''
+ symbol_name = b'meson_uscore_prefix'
+ code = '''#ifdef __cplusplus
+ extern "C" {
+ #endif
+ void ''' + symbol_name.decode() + ''' () {}
+ #ifdef __cplusplus
+ }
+ #endif
+ '''
+ args = self.get_cross_extra_flags(env, compile=True, link=False)
+ args += self.get_compiler_check_args()
+ n = 'symbols_have_underscore_prefix'
+ with self.compile(code, args, compile_only=True) as p:
+ if p.returncode != 0:
+ m = 'BUG: Unable to compile {!r} check: {}'
+ raise RuntimeError(m.format(n, p.stdo))
+ if not os.path.isfile(p.output_name):
+ m = 'BUG: Can\'t find compiled test code for {!r} check'
+ raise RuntimeError(m.format(n))
+ with open(p.output_name, 'rb') as o:
+ for line in o:
+ # Check if the underscore form of the symbol is somewhere
+ # in the output file.
+ if b'_' + symbol_name in line:
+ return True
+ # Else, check if the non-underscored form is present
+ elif symbol_name in line:
+ return False
+ raise RuntimeError('BUG: {!r} check failed unexpectedly'.format(n))
+
def find_library(self, libname, env, extra_dirs):
# First try if we can just add the library as -l.
code = '''int main(int argc, char **argv) {
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 9454302..cff98b1 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -623,6 +623,7 @@ class CompilerHolder(InterpreterObject):
'has_argument' : self.has_argument_method,
'first_supported_argument' : self.first_supported_argument_method,
'unittest_args' : self.unittest_args_method,
+ 'symbols_have_underscore_prefix': self.symbols_have_underscore_prefix_method,
})
def version_method(self, args, kwargs):
@@ -698,6 +699,13 @@ class CompilerHolder(InterpreterObject):
def get_id_method(self, args, kwargs):
return self.compiler.get_id()
+ def symbols_have_underscore_prefix_method(self, args, kwargs):
+ '''
+ Check if the compiler prefixes _ (underscore) to global C symbols
+ See: https://en.wikipedia.org/wiki/Name_mangling#C
+ '''
+ return self.compiler.symbols_have_underscore_prefix(self.environment)
+
def unittest_args_method(self, args, kwargs):
# At time, only D compilers have this feature.
if not hasattr(self.compiler, 'get_unittest_args'):