aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-09-05 15:03:20 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-09-05 15:03:20 +0300
commitad5795ed2e2afcd32d89fae68a8682fb647dd194 (patch)
tree89895a897d1531b0010122e85542592cef180a3f
parent2c5688445bfc8a98972d380c17227ec9da0588ae (diff)
downloadmeson-ad5795ed2e2afcd32d89fae68a8682fb647dd194.zip
meson-ad5795ed2e2afcd32d89fae68a8682fb647dd194.tar.gz
meson-ad5795ed2e2afcd32d89fae68a8682fb647dd194.tar.bz2
Converted sizeof check to work also when cross compiling.
-rw-r--r--compilers.py44
-rw-r--r--cross/iphone.txt4
-rw-r--r--cross/ubuntu-armhf.txt4
3 files changed, 24 insertions, 28 deletions
diff --git a/compilers.py b/compilers.py
index 1e778d3..56b2c8a 100644
--- a/compilers.py
+++ b/compilers.py
@@ -261,8 +261,7 @@ int someSymbolHereJustForFun;
'''
return self.compiles(templ % hname)
- def compiles(self, code):
- mlog.debug('Running compile test:\n\n', code)
+ def compiles(self, code, extra_args = []):
suflen = len(self.default_suffix)
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd)
@@ -270,8 +269,12 @@ int someSymbolHereJustForFun;
ofile.write(code)
ofile.close()
commands = self.get_exelist()
+ commands += extra_args
commands += self.get_compile_only_args()
commands.append(srcname)
+ mlog.debug('Running compile test.')
+ mlog.debug('Command line: ', ' '.join(commands))
+ mlog.debug('Code:\n', code)
p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stde, stdo) = p.communicate()
stde = stde.decode()
@@ -325,7 +328,24 @@ int someSymbolHereJustForFun;
os.remove(exename)
return RunResult(True, pe.returncode, so, se)
+ def cross_sizeof(self, element, prefix, env):
+ templ = '''%s
+int temparray[%d-sizeof(%s)];
+'''
+ extra_args = []
+ try:
+ extra_args = env.cross_info.config['properties'][self.language + '_args']
+ except KeyError:
+ pass
+ for i in range(1, 1024):
+ code = templ % (prefix, i, element)
+ if self.compiles(code, extra_args):
+ return i
+ raise EnvironmentException('Cross checking sizeof overflowed.')
+
def sizeof(self, element, prefix, env):
+ if self.is_cross:
+ return self.cross_sizeof(element, prefix, env)
templ = '''#include<stdio.h>
%s
@@ -334,23 +354,7 @@ int main(int argc, char **argv) {
return 0;
};
'''
- varname = 'sizeof ' + element
- varname = varname.replace(' ', '_')
- if self.is_cross:
- val = env.cross_info.config['properties'][varname]
- if val is not None:
- if isinstance(val, int):
- return val
- raise EnvironmentException('Cross variable {0} is not an integer.'.format(varname))
- cross_failed = False
- try:
- res = self.run(templ % (prefix, element))
- except CrossNoRunException:
- cross_failed = True
- if cross_failed:
- message = '''Can not determine size of {0} because cross compiled binaries are not runnable.
-Please define the corresponding variable {1} in your cross compilation definition file.'''.format(element, varname)
- raise EnvironmentException(message)
+ res = self.run(templ % (prefix, element))
if not res.compiled:
raise EnvironmentException('Could not compile sizeof test.')
if res.returncode != 0:
@@ -414,7 +418,7 @@ int main(int argc, char **argv) {
if val is not None:
if isinstance(val, bool):
return val
- raise EnvironmentException('Cross variable {0} is not an boolean.'.format(varname))
+ raise EnvironmentException('Cross variable {0} is not a boolean.'.format(varname))
return self.compiles(templ % (prefix, funcname))
def has_member(self, typename, membername, prefix):
diff --git a/cross/iphone.txt b/cross/iphone.txt
index 9fa4474..b37a931 100644
--- a/cross/iphone.txt
+++ b/cross/iphone.txt
@@ -16,10 +16,6 @@ cpp_args = ['-arch', 'armv7', '-miphoneos-version-min=8.0', '-isysroot', '/Appli
c_link_args = ['-arch', 'armv7', '-miphoneos-version-min=8.0', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk']
cpp_link_args = ['-arch', 'armv7', '-miphoneos-version-min=8.0', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk']
-sizeof_int = 4
-sizeof_wchar_t = 4
-sizeof_void* = 4
-
alignment_char = 1
alignment_void* = 4
alignment_double = 4 # Don't know if this is correct...
diff --git a/cross/ubuntu-armhf.txt b/cross/ubuntu-armhf.txt
index 196f2bf..e8bd912 100644
--- a/cross/ubuntu-armhf.txt
+++ b/cross/ubuntu-armhf.txt
@@ -10,10 +10,6 @@ pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config'
[properties]
root = '/usr/arm-linux-gnueabihf'
-sizeof_int = 4
-sizeof_wchar_t = 4
-sizeof_void* = 4
-
alignment_char = 1
alignment_void* = 4
alignment_double = 4 # Don't know if this is correct...