diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-04-06 20:55:37 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-04-06 20:55:37 +0300 |
commit | 5174c255b230d6cb1284550014acd0769194d2f4 (patch) | |
tree | fe1d4f586487a1bbb5c33d7dd17a137e15c4287c /environment.py | |
parent | 629d55e3c9004f2260fce7233f1ceef8033d7afd (diff) | |
download | meson-5174c255b230d6cb1284550014acd0769194d2f4.zip meson-5174c255b230d6cb1284550014acd0769194d2f4.tar.gz meson-5174c255b230d6cb1284550014acd0769194d2f4.tar.bz2 |
Basic support for Objective C.
Diffstat (limited to 'environment.py')
-rwxr-xr-x | environment.py | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/environment.py b/environment.py index 6a04fcf..d800056 100755 --- a/environment.py +++ b/environment.py @@ -75,7 +75,7 @@ class CCompiler(): if suffix == 'c' or suffix == 'h': return True return False - + def get_pic_flags(self): return ['-fPIC'] @@ -91,11 +91,11 @@ class CCompiler(): pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name]) pc.wait() if pc.returncode != 0: - raise RuntimeError('Compiler %s can not compile programs.' % self.name_string()) + raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string()) pe = subprocess.Popen(binary_name) pe.wait() if pe.returncode != 0: - raise RuntimeError('Executables created by C compiler %s are not runnable.' % self.name_string()) + raise EnvironmentException('Executables created by C compiler %s are not runnable.' % self.name_string()) class CXXCompiler(CCompiler): def __init__(self, exelist): @@ -118,11 +118,36 @@ class CXXCompiler(CCompiler): pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name]) pc.wait() if pc.returncode != 0: - raise RuntimeError('Compiler %s can not compile programs.' % self.name_string()) + raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string()) pe = subprocess.Popen(binary_name) pe.wait() if pe.returncode != 0: - raise RuntimeError('Executables created by C++ compiler %s are not runnable.' % self.name_string()) + raise EnvironmentException('Executables created by C++ compiler %s are not runnable.' % self.name_string()) + +class ObjCCompiler(CCompiler): + def __init__(self, exelist): + CCompiler.__init__(self, exelist) + + def can_compile(self, filename): + suffix = filename.split('.')[-1] + if suffix == 'm' or suffix == 'h': + return True + return False + + def sanity_check(self, work_dir): + source_name = os.path.join(work_dir, 'sanitycheckobjc.m') + binary_name = os.path.join(work_dir, 'sanitycheckobjc') + ofile = open(source_name, 'w') + ofile.write('#import<stdio.h>\nint main(int argc, char **argv) { return 0; }\n') + ofile.close() + pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name]) + pc.wait() + if pc.returncode != 0: + raise EnvironmentException('ObjC compiler %s can not compile programs.' % self.name_string()) + pe = subprocess.Popen(binary_name) + pe.wait() + if pe.returncode != 0: + raise EnvironmentException('Executables created by ObjC compiler %s are not runnable.' % self.name_string()) class GnuCCompiler(CCompiler): std_warn_flags = ['-Wall', '-Winvalid-pch'] @@ -140,6 +165,19 @@ class GnuCCompiler(CCompiler): def get_pch_suffix(self): return 'gch' +class GnuObjCCompiler(ObjCCompiler): + std_warn_flags = ['-Wall', '-Winvalid-pch'] + std_opt_flags = ['-O2'] + + def get_std_warn_flags(self): + return GnuObjCCompiler.std_warn_flags + + def get_std_opt_flags(self): + return GnuObjCCompiler.std_opt_flags + + def get_pch_suffix(self): + return 'gch' + class ClangCCompiler(CCompiler): std_warn_flags = ['-Wall', '-Winvalid-pch'] std_opt_flags = ['-O2'] @@ -264,6 +302,7 @@ class Environment(): self.default_c = ['cc'] self.default_cxx = ['c++'] + self.default_objc = ['cc'] self.default_static_linker = ['ar'] if is_windows(): @@ -349,6 +388,19 @@ class Environment(): return ClangCXXCompiler(exelist) raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') + def detect_objc_compiler(self): + exelist = self.get_objc_compiler_exelist() + try: + p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE) + except OSError: + raise EnvironmentException('Could not execute ObjC compiler "%s"' % ' '.join(exelist)) + out = p.communicate()[0] + out = out.decode() + if (out.startswith('cc ') or out.startswith('gcc')) and \ + 'Free Software Foundation' in out: + return GnuObjCCompiler(exelist) + raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') + def detect_static_linker(self): exelist = self.get_static_linker_exelist() try: @@ -381,7 +433,14 @@ class Environment(): if evar in os.environ: return os.environ[evar].split() return ccachelist + self.default_cxx - + + def get_objc_compiler_exelist(self): + ccachelist = self.detect_ccache() + evar = 'OBJCC' + if evar in os.environ: + return os.environ[evar].split() + return ccachelist + self.default_objc + def get_static_linker_exelist(self): evar = 'AR' if evar in os.environ: |