OSDN Git Service

Merge commit 'origin/gallium-0.2' into gallium-0.2
[android-x86/external-mesa.git] / scons / gallium.py
index 3631607..fc1ed08 100644 (file)
@@ -163,6 +163,25 @@ 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"""
 
@@ -170,28 +189,28 @@ def generate(env):
     #if env.get('quiet', False):
     #    quietCommandLines(env)
 
+    # Toolchain
+    platform = env['platform']
+    if env['toolchain'] == 'default':
+        if platform == 'winddk':
+            env['toolchain'] = 'winddk'
+        elif platform == 'wince':
+            env['toolchain'] = 'wcesdk'
+    env.Tool(env['toolchain'])
+
     # shortcuts
     debug = env['debug']
     machine = env['machine']
     platform = env['platform']
     x86 = env['machine'] == 'x86'
-    gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
-    msvc = env['platform'] in ('windows', 'winddk', 'wince')
-
-    # Tool
-    if platform == 'winddk':
-        env.Tool('winddk')
-    elif platform == 'wince':
-        env.Tool('wcesdk')
-    else:
-        env.Tool('default')
+    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'
 
     # 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':
@@ -205,6 +224,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 = []
@@ -218,8 +242,10 @@ 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',
@@ -274,6 +300,7 @@ def generate(env):
         cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
     if platform == 'wince':
         cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
+        cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
     env.Append(CPPDEFINES = cppdefines)
 
     # C preprocessor includes
@@ -308,7 +335,7 @@ def generate(env):
             '-Wmissing-prototypes',
             '-Wno-long-long',
             '-ffast-math',
-            '-pedantic',
+            '-std=gnu99',
             '-fmessage-length=0', # be nice to Eclipse
         ]
     if msvc:
@@ -386,6 +413,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':