OSDN Git Service

Merge branch 'mesa_7_5_branch'
[android-x86/external-mesa.git] / scons / gallium.py
index 6dbce62..6e924da 100644 (file)
@@ -42,11 +42,18 @@ import SCons.Scanner
 def quietCommandLines(env):
     # Quiet command lines
     # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
-    env['CCCOMSTR'] = "Compiling $SOURCE ..."
-    env['CXXCOMSTR'] = "Compiling $SOURCE ..."
-    env['ARCOMSTR'] = "Archiving $TARGET ..."
-    env['RANLIBCOMSTR'] = ""
-    env['LINKCOMSTR'] = "Linking $TARGET ..."
+    env['ASCOMSTR'] = "  Assembling $SOURCE ..."
+    env['ASPPCOMSTR'] = "  Assembling $SOURCE ..."
+    env['CCCOMSTR'] = "  Compiling $SOURCE ..."
+    env['SHCCCOMSTR'] = "  Compiling $SOURCE ..."
+    env['CXXCOMSTR'] = "  Compiling $SOURCE ..."
+    env['SHCXXCOMSTR'] = "  Compiling $SOURCE ..."
+    env['ARCOMSTR'] = "  Archiving $TARGET ..."
+    env['RANLIBCOMSTR'] = "  Indexing $TARGET ..."
+    env['LINKCOMSTR'] = "  Linking $TARGET ..."
+    env['SHLINKCOMSTR'] = "  Linking $TARGET ..."
+    env['LDMODULECOMSTR'] = "  Linking $TARGET ..."
+    env['SWIGCOMSTR'] = "  Generating $TARGET ..."
 
 
 def createConvenienceLibBuilder(env):
@@ -163,12 +170,30 @@ def createInstallMethods(env):
     env.AddMethod(install_shared_library, 'InstallSharedLibrary')
 
 
+def num_jobs():
+    try:
+        return int(os.environ['NUMBER_OF_PROCESSORS'])
+    except (ValueError, KeyError):
+        pass
+
+    try:
+        return os.sysconf('SC_NPROCESSORS_ONLN')
+    except (ValueError, OSError, AttributeError):
+        pass
+
+    try:
+        return int(os.popen2("sysctl -n hw.ncpu")[1].read())
+    except ValueError:
+        pass
+
+    return 1
+
+
 def generate(env):
     """Common environment generation code"""
 
-    # FIXME: this is already too late
-    #if env.get('quiet', False):
-    #    quietCommandLines(env)
+    if env.get('quiet', True):
+        quietCommandLines(env)
 
     # Toolchain
     platform = env['platform']
@@ -179,21 +204,22 @@ def generate(env):
             env['toolchain'] = 'wcesdk'
     env.Tool(env['toolchain'])
 
+    env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
+    env['msvc'] = env['CC'] == 'cl'
+
     # shortcuts
     debug = env['debug']
     machine = env['machine']
     platform = env['platform']
     x86 = env['machine'] == 'x86'
     ppc = env['machine'] == 'ppc'
-    gcc = env['platform'] in ('linux', 'freebsd', 'darwin') or env['toolchain'] == 'crossmingw'
-    msvc = env['platform'] in ('windows', 'winddk', 'wince') and env['toolchain'] != 'crossmingw'
+    gcc = env['gcc']
+    msvc = env['msvc']
 
     # Put build output in a separate dir, which depends on the current
     # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
     build_topdir = 'build'
     build_subdir = env['platform']
-    if env['dri']:
-        build_subdir += "-dri"
     if env['llvm']:
         build_subdir += "-llvm"
     if env['machine'] != 'generic':
@@ -207,6 +233,11 @@ def generate(env):
     # different scons versions building the same source file
     env['build'] = build_dir
     env.SConsignFile(os.path.join(build_dir, '.sconsign'))
+    env.CacheDir('build/cache')
+
+    # Parallel build
+    if env.GetOption('num_jobs') <= 1:
+        env.SetOption('num_jobs', num_jobs())
 
     # C preprocessor options
     cppdefines = []
@@ -220,25 +251,31 @@ def generate(env):
         cppdefines += [
             'WIN32',
             '_WINDOWS',
-            '_UNICODE',
-            'UNICODE',
+            #'_UNICODE',
+            #'UNICODE',
             ('_WIN32_WINNT', '0x0501'), # minimum required OS version
             ('WINVER', '0x0501'),
             # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
             'WIN32_LEAN_AND_MEAN',
-            'VC_EXTRALEAN',
-            '_CRT_SECURE_NO_DEPRECATE',
         ]
+        if msvc and env['toolchain'] != 'winddk':
+            cppdefines += [
+                'VC_EXTRALEAN',
+                '_CRT_SECURE_NO_DEPRECATE',
+            ]
         if debug:
             cppdefines += ['_DEBUG']
-    if platform == 'winddk':
+    if env['toolchain'] == 'winddk':
         # Mimic WINDDK's builtin flags. See also:
         # - WINDDK's bin/makefile.new i386mk.inc for more info.
         # - buildchk_wxp_x86.log files, generated by the WINDDK's build
         # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
+        if machine == 'x86':
+            cppdefines += ['_X86_', 'i386']
+        if machine == 'x86_64':
+            cppdefines += ['_AMD64_', 'AMD64']
+    if platform == 'winddk':
         cppdefines += [
-            ('_X86_', '1'),
-            ('i386', '1'),
             'STD_CALL',
             ('CONDITION_HANDLING', '1'),
             ('NT_INST', '0'),
@@ -281,20 +318,13 @@ def generate(env):
         cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
     env.Append(CPPDEFINES = cppdefines)
 
-    # C preprocessor includes
-    if platform == 'winddk':
-        env.Append(CPPPATH = [
-            env['SDK_INC_PATH'],
-            env['DDK_INC_PATH'],
-            env['WDM_INC_PATH'],
-            env['CRT_INC_PATH'],
-        ])
-
     # C compiler options
     cflags = []
     if gcc:
         if debug:
             cflags += ['-O0', '-g3']
+        elif env['toolchain'] == 'crossmingw':
+            cflags += ['-O0', '-g3'] # mingw 4.2.1 optimizer is broken
         else:
             cflags += ['-O3', '-g3']
         if env['profile']:
@@ -308,12 +338,17 @@ def generate(env):
             ]
         if env['machine'] == 'x86_64':
             cflags += ['-m64']
+        # See also:
+        # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
         cflags += [
+            '-Werror=declaration-after-statement',
             '-Wall',
             '-Wmissing-prototypes',
+            '-Wmissing-field-initializers',
+            '-Wpointer-arith',
             '-Wno-long-long',
             '-ffast-math',
-            '-pedantic',
+            '-std=gnu99',
             '-fmessage-length=0', # be nice to Eclipse
         ]
     if msvc:
@@ -325,13 +360,12 @@ def generate(env):
               '/Od', # disable optimizations
               '/Oi', # enable intrinsic functions
               '/Oy-', # disable frame pointer omission
+              '/GL-', # disable whole program optimization
             ]
         else:
             cflags += [
-              '/Ox', # maximum optimizations
-              '/Oi', # enable intrinsic functions
-              '/Ot', # favor code speed
-              #'/fp:fast', # fast floating point 
+                '/O2', # optimize for speed
+                #'/fp:fast', # fast floating point 
             ]
         if env['profile']:
             cflags += [
@@ -391,6 +425,16 @@ def generate(env):
     env.Append(CFLAGS = cflags)
     env.Append(CXXFLAGS = cflags)
 
+    if env['platform'] == 'windows' and msvc:
+        # Choose the appropriate MSVC CRT
+        # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
+        if env['debug']:
+            env.Append(CCFLAGS = ['/MTd'])
+            env.Append(SHCCFLAGS = ['/LDd'])
+        else:
+            env.Append(CCFLAGS = ['/MT'])
+            env.Append(SHCCFLAGS = ['/LD'])
+    
     # Assembler options
     if gcc:
         if env['machine'] == 'x86':
@@ -405,10 +449,15 @@ def generate(env):
             linkflags += ['-m32']
         if env['machine'] == 'x86_64':
             linkflags += ['-m64']
-    if platform == 'winddk':
+    if platform == 'windows' and msvc:
         # See also:
         # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
         linkflags += [
+            '/fixed:no',
+            '/incremental:no',
+        ]
+    if platform == 'winddk':
+        linkflags += [
             '/merge:_PAGE=PAGE',
             '/merge:_TEXT=.text',
             '/section:INIT,d',
@@ -435,7 +484,7 @@ def generate(env):
 
             '/entry:DrvEnableDriver',
         ]
-        if env['profile']:
+        if env['debug'] or env['profile']:
             linkflags += [
                 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
             ]