|
|
@ -258,7 +258,7 @@ class CLikeCompiler: |
|
|
|
raise mesonlib.EnvironmentException('Executables created by {0} compiler {1} are not runnable.'.format(self.language, self.name_string())) |
|
|
|
raise mesonlib.EnvironmentException('Executables created by {0} compiler {1} are not runnable.'.format(self.language, self.name_string())) |
|
|
|
|
|
|
|
|
|
|
|
def sanity_check(self, work_dir, environment): |
|
|
|
def sanity_check(self, work_dir, environment): |
|
|
|
code = 'int main() { int class=0; return class; }\n' |
|
|
|
code = 'int main(void) { int class=0; return class; }\n' |
|
|
|
return self.sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code) |
|
|
|
return self.sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code) |
|
|
|
|
|
|
|
|
|
|
|
def check_header(self, hname, prefix, env, *, extra_args=None, dependencies=None): |
|
|
|
def check_header(self, hname, prefix, env, *, extra_args=None, dependencies=None): |
|
|
@ -285,7 +285,7 @@ class CLikeCompiler: |
|
|
|
fargs = {'prefix': prefix, 'header': hname, 'symbol': symbol} |
|
|
|
fargs = {'prefix': prefix, 'header': hname, 'symbol': symbol} |
|
|
|
t = '''{prefix} |
|
|
|
t = '''{prefix} |
|
|
|
#include <{header}> |
|
|
|
#include <{header}> |
|
|
|
int main () {{ |
|
|
|
int main(void) {{ |
|
|
|
/* If it's not defined as a macro, try to use as a symbol */ |
|
|
|
/* If it's not defined as a macro, try to use as a symbol */ |
|
|
|
#ifndef {symbol} |
|
|
|
#ifndef {symbol} |
|
|
|
{symbol}; |
|
|
|
{symbol}; |
|
|
@ -398,7 +398,7 @@ class CLikeCompiler: |
|
|
|
fargs = {'prefix': prefix, 'expression': expression} |
|
|
|
fargs = {'prefix': prefix, 'expression': expression} |
|
|
|
t = '''#include <stdio.h> |
|
|
|
t = '''#include <stdio.h> |
|
|
|
{prefix} |
|
|
|
{prefix} |
|
|
|
int main() {{ static int a[1-2*!({expression})]; a[0]=0; return 0; }}''' |
|
|
|
int main(void) {{ static int a[1-2*!({expression})]; a[0]=0; return 0; }}''' |
|
|
|
return self.compiles(t.format(**fargs), env, extra_args=extra_args, |
|
|
|
return self.compiles(t.format(**fargs), env, extra_args=extra_args, |
|
|
|
dependencies=dependencies)[0] |
|
|
|
dependencies=dependencies)[0] |
|
|
|
|
|
|
|
|
|
|
@ -458,7 +458,7 @@ class CLikeCompiler: |
|
|
|
fargs = {'prefix': prefix, 'expression': expression} |
|
|
|
fargs = {'prefix': prefix, 'expression': expression} |
|
|
|
t = '''#include<stdio.h> |
|
|
|
t = '''#include<stdio.h> |
|
|
|
{prefix} |
|
|
|
{prefix} |
|
|
|
int main() {{ |
|
|
|
int main(void) {{ |
|
|
|
printf("%ld\\n", (long)({expression})); |
|
|
|
printf("%ld\\n", (long)({expression})); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}};''' |
|
|
|
}};''' |
|
|
@ -476,7 +476,7 @@ class CLikeCompiler: |
|
|
|
fargs = {'prefix': prefix, 'type': typename} |
|
|
|
fargs = {'prefix': prefix, 'type': typename} |
|
|
|
t = '''#include <stdio.h> |
|
|
|
t = '''#include <stdio.h> |
|
|
|
{prefix} |
|
|
|
{prefix} |
|
|
|
int main() {{ |
|
|
|
int main(void) {{ |
|
|
|
{type} something; |
|
|
|
{type} something; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}}''' |
|
|
|
}}''' |
|
|
@ -494,7 +494,7 @@ class CLikeCompiler: |
|
|
|
dependencies=dependencies) |
|
|
|
dependencies=dependencies) |
|
|
|
t = '''#include<stdio.h> |
|
|
|
t = '''#include<stdio.h> |
|
|
|
{prefix} |
|
|
|
{prefix} |
|
|
|
int main() {{ |
|
|
|
int main(void) {{ |
|
|
|
printf("%ld\\n", (long)(sizeof({type}))); |
|
|
|
printf("%ld\\n", (long)(sizeof({type}))); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}};''' |
|
|
|
}};''' |
|
|
@ -512,7 +512,7 @@ class CLikeCompiler: |
|
|
|
fargs = {'prefix': prefix, 'type': typename} |
|
|
|
fargs = {'prefix': prefix, 'type': typename} |
|
|
|
t = '''#include <stdio.h> |
|
|
|
t = '''#include <stdio.h> |
|
|
|
{prefix} |
|
|
|
{prefix} |
|
|
|
int main() {{ |
|
|
|
int main(void) {{ |
|
|
|
{type} something; |
|
|
|
{type} something; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}}''' |
|
|
|
}}''' |
|
|
@ -541,7 +541,7 @@ class CLikeCompiler: |
|
|
|
char c; |
|
|
|
char c; |
|
|
|
{type} target; |
|
|
|
{type} target; |
|
|
|
}}; |
|
|
|
}}; |
|
|
|
int main() {{ |
|
|
|
int main(void) {{ |
|
|
|
printf("%d", (int)offsetof(struct tmp, target)); |
|
|
|
printf("%d", (int)offsetof(struct tmp, target)); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}}''' |
|
|
|
}}''' |
|
|
@ -591,7 +591,7 @@ class CLikeCompiler: |
|
|
|
fargs = {'prefix': prefix, 'f': fname, 'cast': cast, 'fmt': fmt} |
|
|
|
fargs = {'prefix': prefix, 'f': fname, 'cast': cast, 'fmt': fmt} |
|
|
|
code = '''{prefix} |
|
|
|
code = '''{prefix} |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
int main() {{ |
|
|
|
int main(void) {{ |
|
|
|
printf ("{fmt}", {cast} {f}()); |
|
|
|
printf ("{fmt}", {cast} {f}()); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}}'''.format(**fargs) |
|
|
|
}}'''.format(**fargs) |
|
|
@ -634,11 +634,11 @@ class CLikeCompiler: |
|
|
|
#ifdef __cplusplus |
|
|
|
#ifdef __cplusplus |
|
|
|
extern "C" |
|
|
|
extern "C" |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
char {func} (); |
|
|
|
char {func} (void); |
|
|
|
''' |
|
|
|
''' |
|
|
|
# The actual function call |
|
|
|
# The actual function call |
|
|
|
main = ''' |
|
|
|
main = ''' |
|
|
|
int main () {{ |
|
|
|
int main(void) {{ |
|
|
|
return {func} (); |
|
|
|
return {func} (); |
|
|
|
}}''' |
|
|
|
}}''' |
|
|
|
return head, main |
|
|
|
return head, main |
|
|
@ -657,7 +657,7 @@ class CLikeCompiler: |
|
|
|
# Just taking the address or comparing it to void is not enough because |
|
|
|
# Just taking the address or comparing it to void is not enough because |
|
|
|
# compilers are smart enough to optimize it away. The resulting binary |
|
|
|
# compilers are smart enough to optimize it away. The resulting binary |
|
|
|
# is not run so we don't care what the return value is. |
|
|
|
# is not run so we don't care what the return value is. |
|
|
|
main = '''\nint main() {{ |
|
|
|
main = '''\nint main(void) {{ |
|
|
|
void *a = (void*) &{func}; |
|
|
|
void *a = (void*) &{func}; |
|
|
|
long b = (long) a; |
|
|
|
long b = (long) a; |
|
|
|
return (int) b; |
|
|
|
return (int) b; |
|
|
@ -729,7 +729,7 @@ class CLikeCompiler: |
|
|
|
# can just directly use the __has_builtin() macro. |
|
|
|
# can just directly use the __has_builtin() macro. |
|
|
|
fargs['no_includes'] = '#include' not in prefix |
|
|
|
fargs['no_includes'] = '#include' not in prefix |
|
|
|
t = '''{prefix} |
|
|
|
t = '''{prefix} |
|
|
|
int main() {{ |
|
|
|
int main(void) {{ |
|
|
|
#ifdef __has_builtin |
|
|
|
#ifdef __has_builtin |
|
|
|
#if !__has_builtin(__builtin_{func}) |
|
|
|
#if !__has_builtin(__builtin_{func}) |
|
|
|
#error "__builtin_{func} not found" |
|
|
|
#error "__builtin_{func} not found" |
|
|
@ -761,7 +761,7 @@ class CLikeCompiler: |
|
|
|
members += '{}.{};\n'.format(fargs['name'], member) |
|
|
|
members += '{}.{};\n'.format(fargs['name'], member) |
|
|
|
fargs['members'] = members |
|
|
|
fargs['members'] = members |
|
|
|
t = '''{prefix} |
|
|
|
t = '''{prefix} |
|
|
|
void bar() {{ |
|
|
|
void bar(void) {{ |
|
|
|
{type} {name}; |
|
|
|
{type} {name}; |
|
|
|
{members} |
|
|
|
{members} |
|
|
|
}};''' |
|
|
|
}};''' |
|
|
@ -771,7 +771,7 @@ class CLikeCompiler: |
|
|
|
def has_type(self, typename, prefix, env, extra_args, dependencies=None): |
|
|
|
def has_type(self, typename, prefix, env, extra_args, dependencies=None): |
|
|
|
fargs = {'prefix': prefix, 'type': typename} |
|
|
|
fargs = {'prefix': prefix, 'type': typename} |
|
|
|
t = '''{prefix} |
|
|
|
t = '''{prefix} |
|
|
|
void bar() {{ |
|
|
|
void bar(void) {{ |
|
|
|
sizeof({type}); |
|
|
|
sizeof({type}); |
|
|
|
}};''' |
|
|
|
}};''' |
|
|
|
return self.compiles(t.format(**fargs), env, extra_args=extra_args, |
|
|
|
return self.compiles(t.format(**fargs), env, extra_args=extra_args, |
|
|
@ -785,7 +785,7 @@ class CLikeCompiler: |
|
|
|
code = '''#ifdef __cplusplus |
|
|
|
code = '''#ifdef __cplusplus |
|
|
|
extern "C" { |
|
|
|
extern "C" { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
void ''' + symbol_name.decode() + ''' () {} |
|
|
|
void ''' + symbol_name.decode() + ''' (void) {} |
|
|
|
#ifdef __cplusplus |
|
|
|
#ifdef __cplusplus |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -993,7 +993,7 @@ class CLikeCompiler: |
|
|
|
return value[:] |
|
|
|
return value[:] |
|
|
|
|
|
|
|
|
|
|
|
def find_library(self, libname, env, extra_dirs, libtype: LibType = LibType.PREFER_SHARED): |
|
|
|
def find_library(self, libname, env, extra_dirs, libtype: LibType = LibType.PREFER_SHARED): |
|
|
|
code = 'int main() { return 0; }' |
|
|
|
code = 'int main(void) { return 0; }' |
|
|
|
return self.find_library_impl(libname, env, extra_dirs, code, libtype) |
|
|
|
return self.find_library_impl(libname, env, extra_dirs, code, libtype) |
|
|
|
|
|
|
|
|
|
|
|
def find_framework_paths(self, env): |
|
|
|
def find_framework_paths(self, env): |
|
|
@ -1023,7 +1023,7 @@ class CLikeCompiler: |
|
|
|
return paths |
|
|
|
return paths |
|
|
|
|
|
|
|
|
|
|
|
def find_framework_real(self, name, env, extra_dirs, allow_system): |
|
|
|
def find_framework_real(self, name, env, extra_dirs, allow_system): |
|
|
|
code = 'int main() { return 0; }' |
|
|
|
code = 'int main(void) { return 0; }' |
|
|
|
link_args = [] |
|
|
|
link_args = [] |
|
|
|
for d in extra_dirs: |
|
|
|
for d in extra_dirs: |
|
|
|
link_args += ['-F' + d] |
|
|
|
link_args += ['-F' + d] |
|
|
@ -1102,7 +1102,7 @@ class CLikeCompiler: |
|
|
|
# false positive. |
|
|
|
# false positive. |
|
|
|
args = self.linker.fatal_warnings() + args |
|
|
|
args = self.linker.fatal_warnings() + args |
|
|
|
args = self.linker_to_compiler_args(args) |
|
|
|
args = self.linker_to_compiler_args(args) |
|
|
|
code = 'int main() { return 0; }' |
|
|
|
code = 'int main(void) { return 0; }' |
|
|
|
return self.has_arguments(args, env, code, mode='link') |
|
|
|
return self.has_arguments(args, env, code, mode='link') |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
|