aboutsummaryrefslogtreecommitdiff
path: root/environment.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2012-12-24 00:11:24 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2012-12-24 00:11:24 +0200
commitc3c9a31a5a51ea2b2c7b560262a5af0d372d52ab (patch)
treeaff16ba953acbceeeeea43f73248b89977d9c1d2 /environment.py
parent3bdaceac35847a212cd2180261f8b5b4cecc5056 (diff)
downloadmeson-c3c9a31a5a51ea2b2c7b560262a5af0d372d52ab.zip
meson-c3c9a31a5a51ea2b2c7b560262a5af0d372d52ab.tar.gz
meson-c3c9a31a5a51ea2b2c7b560262a5af0d372d52ab.tar.bz2
Beginnings of environment detector.
Diffstat (limited to 'environment.py')
-rwxr-xr-xenvironment.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/environment.py b/environment.py
new file mode 100755
index 0000000..5dcd8be
--- /dev/null
+++ b/environment.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python3 -tt
+
+# Copyright 2012 Jussi Pakkanen
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import subprocess
+
+class EnvironmentException(Exception):
+ def __init(self, text):
+ Exception.__init__(self, text)
+
+def detect_c_compiler(exename):
+ p = subprocess.Popen([exename, '--version'], stdout=subprocess.PIPE)
+ (out, err) = p.communicate()
+ out = out.decode()
+ if (out.startswith('cc ') or out.startswith('gcc')) and \
+ 'Free Software Foundation' in out:
+ return GnuCCompiler(exename)
+ raise EnvironmentException('Unknown compiler ' + exename)
+
+class CCompiler():
+ def __init__(self, exename):
+ self.exename = exename
+
+ def get_std_warn_flags(self):
+ return []
+
+class GnuCCompiler(CCompiler):
+ std_warn_flags = ['-Wall']
+ def __init__(self, exename):
+ CCompiler.__init__(self, exename)
+
+ def get_std_warn_flags(self):
+ return GnuCCompiler.std_warn_flags
+
+if __name__ == '__main__':
+ gnuc = detect_c_compiler('/usr/bin/cc')
+ \ No newline at end of file