aboutsummaryrefslogtreecommitdiff
path: root/environment.py
diff options
context:
space:
mode:
Diffstat (limited to 'environment.py')
-rwxr-xr-xenvironment.py71
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: