aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-09-22 22:04:18 +0300
committerGitHub <noreply@github.com>2017-09-22 22:04:18 +0300
commitbea6b1a6f64d93a0f4dc129d209cbc49b5e39df4 (patch)
tree539c2e3956f5b05e820472d3748e99f0c9c4d68a /mesonbuild/compilers
parentbe0aa7fd740d5808975868e32649c464e031f526 (diff)
parent177283d203a6c9f4355a90ca12c0105298a23a74 (diff)
downloadmeson-bea6b1a6f64d93a0f4dc129d209cbc49b5e39df4.zip
meson-bea6b1a6f64d93a0f4dc129d209cbc49b5e39df4.tar.gz
meson-bea6b1a6f64d93a0f4dc129d209cbc49b5e39df4.tar.bz2
Merge pull request #2187 from centricular/fix-pcap-dependency
Fix pcap dependency, str.strip() now takes an argument, add cc.get_return_value()
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 98b2fbc..c17726a 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -482,6 +482,34 @@ class CCompiler(Compiler):
# minus the extra newline at the end
return p.stdo.split(delim + '\n')[-1][:-1]
+ def get_return_value(self, fname, rtype, prefix, env, extra_args, dependencies):
+ if rtype == 'string':
+ fmt = '%s'
+ cast = '(char*)'
+ elif rtype == 'int':
+ fmt = '%lli'
+ cast = '(long long int)'
+ else:
+ raise AssertionError('BUG: Unknown return type {!r}'.format(rtype))
+ fargs = {'prefix': prefix, 'f': fname, 'cast': cast, 'fmt': fmt}
+ code = '''{prefix}
+ #include <stdio.h>
+ int main(int argc, char *argv[]) {{
+ printf ("{fmt}", {cast} {f}());
+ }}'''.format(**fargs)
+ res = self.run(code, env, extra_args, dependencies)
+ if not res.compiled:
+ m = 'Could not get return value of {}()'
+ raise EnvironmentException(m.format(fname))
+ if rtype == 'string':
+ return res.stdout
+ elif rtype == 'int':
+ try:
+ return int(res.stdout.strip())
+ except:
+ m = 'Return value of {}() is not an int'
+ raise EnvironmentException(m.format(fname))
+
@staticmethod
def _no_prototype_templ():
"""