i965: Add annotation data structure and support code.
[mesa.git] / scons / gallium.py
index e873c658ad0270f0fc9c0bc9789dd64bbd16a1f9..5109ebffee0f10888972b8cdef91a2435fb48aba 100755 (executable)
@@ -36,6 +36,8 @@ import os.path
 import re
 import subprocess
 import platform as _platform
+import sys
+import tempfile
 
 import SCons.Action
 import SCons.Builder
@@ -104,17 +106,26 @@ def num_jobs():
     return 1
 
 
-def get_cc_version(env):
-    # Get the first line of `$CC --version`
-    pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
+def check_cc(env, cc, expr, cpp_opt = '-E'):
+    # Invoke C-preprocessor to determine whether the specified expression is
+    # true or not.
+
+    sys.stdout.write('Checking for %s ... ' % cc)
+
+    source = tempfile.NamedTemporaryFile(suffix='.c', delete=False)
+    source.write('#if !(%s)\n#error\n#endif\n' % expr)
+    source.close()
+
+    pipe = SCons.Action._subproc(env, [env['CC'], cpp_opt, source.name],
                                  stdin = 'devnull',
                                  stderr = 'devnull',
-                                 stdout = subprocess.PIPE)
-    if pipe.wait() != 0:
-        return ''
+                                 stdout = 'devnull')
+    result = pipe.wait() == 0
 
-    line = pipe.stdout.readline()
-    return line
+    os.unlink(source.name)
+
+    sys.stdout.write(' %s\n' % ['no', 'yes'][int(bool(result))])
+    return result
 
 
 def generate(env):
@@ -132,8 +143,12 @@ def generate(env):
     if os.environ.has_key('CC'):
         env['CC'] = os.environ['CC']
         # Update CCVERSION to match
-        line = get_cc_version(env)
-        if line:
+        pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
+                                     stdin = 'devnull',
+                                     stderr = 'devnull',
+                                     stdout = subprocess.PIPE)
+        if pipe.wait() == 0:
+            line = pipe.stdout.readline()
             match = re.search(r'[0-9]+(\.[0-9]+)+', line)
             if match:
                 env['CCVERSION'] = match.group(0)
@@ -146,16 +161,18 @@ def generate(env):
     if os.environ.has_key('LDFLAGS'):
         env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
 
-    # Detect gcc/clang not by executable name, but through `--version` option,
-    # to avoid drawing wrong conclusions when using tools that overrice CC/CXX
-    # like scan-build.
-    cc_version = get_cc_version(env)
-    cc_version_words = cc_version.split()
-
-    env['gcc'] = 'gcc' in cc_version_words
-    env['msvc'] = env['CC'] == 'cl'
+    # Detect gcc/clang not by executable name, but through pre-defined macros
+    # as autoconf does, to avoid drawing wrong conclusions when using tools
+    # that overrice CC/CXX like scan-build.
+    env['gcc'] = 0
+    env['clang'] = 0
+    env['msvc'] = 0
+    if _platform.system() == 'Windows':
+        env['msvc'] = check_cc(env, 'MSVC', 'defined(_MSC_VER)', '/E')
+    if not env['msvc']:
+        env['gcc'] = check_cc(env, 'GCC', 'defined(__GNUC__) && !defined(__clang__)')
+        env['clang'] = check_cc(env, 'Clang', '__clang__')
     env['suncc'] = env['platform'] == 'sunos' and os.path.basename(env['CC']) == 'cc'
-    env['clang'] = 'clang' in cc_version_words
     env['icc'] = 'icc' == os.path.basename(env['CC'])
 
     if env['msvc'] and env['toolchain'] == 'default' and env['machine'] == 'x86_64':
@@ -416,6 +433,12 @@ def generate(env):
         # See also:
         # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
         # - cl /?
+        if 'MSVC_VERSION' not in env or distutils.version.LooseVersion(env['MSVC_VERSION']) < distutils.version.LooseVersion('12.0'):
+            # Use bundled stdbool.h and stdint.h headers for older MSVC
+            # versions.  stdint.h was introduced in MSVC 2010, but stdbool.h
+            # was only introduced in MSVC 2013.
+            top_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+            env.Append(CPPPATH = [os.path.join(top_dir, 'include/c99')])
         if env['build'] == 'debug':
             ccflags += [
               '/Od', # disable optimizations
@@ -438,7 +461,9 @@ def generate(env):
             ]
         ccflags += [
             '/W3', # warning level
-            #'/Wp64', # enable 64 bit porting warnings
+            '/wd4244', # conversion from 'type1' to 'type2', possible loss of data
+            '/wd4305', # truncation from 'type1' to 'type2'
+            '/wd4800', # forcing value to bool 'true' or 'false' (performance warning)
             '/wd4996', # disable deprecated POSIX name warnings
         ]
         if env['machine'] == 'x86':