gallium: fix polygon stipple
[mesa.git] / winddk.py
index af4335dbb010cd99a429b0f7c678ff33fa3baf75..c112329cd69f7ddf0a5089068564e4e8007cac96 100644 (file)
--- a/winddk.py
+++ b/winddk.py
@@ -1,6 +1,8 @@
-"""engine.SCons.Tool.msvc
+"""winddk
 
-Tool-specific initialization for Microsoft Visual C/C++.
+Tool-specific initialization for Microsoft Windows DDK.
+
+Based on engine.SCons.Tool.msvc.
 
 There normally shouldn't be any need to import this module directly.
 It will usually be imported through the generic SCons.Tool.Tool()
@@ -9,7 +11,8 @@ selection method.
 """
 
 #
-# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 The SCons Foundation
+# Copyright (c) 2001-2007 The SCons Foundation
+# Copyright (c) 2008 Tungsten Graphics, Inc.
 #
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
@@ -31,8 +34,6 @@ selection method.
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #
 
-__revision__ = "src/engine/SCons/Tool/msvc.py 2523 2007/12/12 09:37:41 knight"
-
 import os.path
 import re
 import string
@@ -66,15 +67,127 @@ def get_winddk_paths(env, version=None):
         WINDDKdir = "C:\\WINDDK\\3790.1830"
 
     exe_paths.append( os.path.join(WINDDKdir, 'bin') )
-    exe_paths.append( os.path.join(WINDDKdir, 'bin\\x86') )
-    include_paths.append( os.path.join(WINDDKdir, 'inc\\wxp') )
+    exe_paths.append( os.path.join(WINDDKdir, 'bin', 'x86') )
+    include_paths.append( os.path.join(WINDDKdir, 'inc', 'wxp') )
     lib_paths.append( os.path.join(WINDDKdir, 'lib') )
 
+    target_os = 'wxp'
+    target_cpu = 'i386'
+    
+    env['SDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc', target_os) 
+    env['CRT_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'crt') 
+    env['DDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'ddk', target_os) 
+    env['WDM_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'ddk', 'wdm', target_os) 
+
+    env['SDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu) 
+    env['CRT_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', 'crt', target_cpu) 
+    env['DDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
+    env['WDM_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
+                                     
     include_path = string.join( include_paths, os.pathsep )
     lib_path = string.join(lib_paths, os.pathsep )
     exe_path = string.join(exe_paths, os.pathsep )
     return (include_path, lib_path, exe_path)
 
+def set_winddk_flags(env):
+    """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/
+    """
+    
+    cppdefines = [
+        ('_X86_', '1'), 
+        ('i386', '1'), 
+        'STD_CALL', 
+        ('CONDITION_HANDLING', '1'),
+        ('NT_INST', '0'), 
+        ('WIN32', '100'),
+        ('_NT1X_', '100'),
+        ('WINNT', '1'),
+        ('_WIN32_WINNT', '0x0501'), # minimum required OS version
+        ('WINVER', '0x0501'),
+        ('_WIN32_IE', '0x0603'),
+        ('WIN32_LEAN_AND_MEAN', '1'),
+        ('DEVL', '1'),
+        ('__BUILDMACHINE__', 'WinDDK'),
+        ('FPO', '0'),
+    ]
+    if env.get('DEBUG', False):
+         cppdefines += [
+              ('DBG', 1),
+         ]
+    env.Append(CPPDEFINES = cppdefines)
+
+    # See also:
+    # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
+    # - cl /?
+    cflags = [
+        '/Zl', # omit default library name in .OBJ
+        '/Zp8', # 8bytes struct member alignment
+        '/Gy', # separate functions for linker
+        '/Gm-', # disable minimal rebuild
+        '/W3', # warning level
+        '/WX', # treat warnings as errors
+        '/Gz', # __stdcall Calling convention
+        '/GX-', # disable C++ EH
+        '/GR-', # disable C++ RTTI
+        '/GF', # enable read-only string pooling
+        '/GS', # enable security checks
+        '/G6', # optimize for PPro, P-II, P-III
+        '/Ze', # enable extensions
+        #'/Gi-', # ???
+        '/QIfdiv-', # disable Pentium FDIV fix
+        #'/hotpatch', # ???
+        #'/Z7', #enable old-style debug info
+    ]
+    if env.get('debug', False):
+        cflags += [
+          '/Od', # disable optimizations
+          '/Oi', # enable intrinsic functions
+          '/Oy-', # disable frame pointer omission
+        ]
+    else:
+        cflags += [
+          '/Ox', # maximum optimizations
+          '/Oi', # enable intrinsic functions
+          '/Os', # favor code space
+        ]
+    env.Append(CFLAGS = cflags)
+    env.Append(CXXFLAGS = cflags)
+    
+    # See also:
+    # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
+    env.Append(LINKFLAGS = [
+        '/merge:_PAGE=PAGE',
+        '/merge:_TEXT=.text',
+        '/section:INIT,d',
+        '/opt:ref',
+        '/opt:icf',
+        '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
+        '/incremental:no',
+        '/fullbuild',
+        '/release',
+        '/nodefaultlib',
+        '/wx',
+        '/debug',
+        '/debugtype:cv',
+        '/version:5.1',
+        '/osversion:5.1',
+        '/functionpadmin:5',
+        '/safeseh',
+        '/pdbcompress',
+        '/stack:0x40000,0x1000',
+        '/driver', 
+        '/align:0x80',
+        '/subsystem:native,5.01',
+        '/base:0x10000',
+        
+        '/entry:DrvEnableDriver',
+    ])
+
 def validate_vars(env):
     """Validate the PCH and PCHSTOP construction variables."""
     if env.has_key('PCH') and env['PCH']:
@@ -186,17 +299,6 @@ def generate(env):
     env['SHOBJPREFIX']    = '$OBJPREFIX'
     env['SHOBJSUFFIX']    = '$OBJSUFFIX'
 
-    try:
-        include_path, lib_path, exe_path = get_winddk_paths(env)
-
-        # since other tools can set these, we just make sure that the
-        # relevant stuff from MSVS is in there somewhere.
-        env.PrependENVPath('INCLUDE', include_path)
-        env.PrependENVPath('LIB', lib_path)
-        env.PrependENVPath('PATH', exe_path)
-    except (SCons.Util.RegError, SCons.Errors.InternalError):
-        pass
-
     env['CFILESUFFIX'] = '.c'
     env['CXXFILESUFFIX'] = '.cc'
 
@@ -212,11 +314,24 @@ def generate(env):
 
     SCons.Tool.mslink.generate(env)
 
+    set_winddk_flags(env)
+    
     if not env.has_key('ENV'):
         env['ENV'] = {}
-    if not env['ENV'].has_key('SystemRoot'):    # required for dlls in the winsxs folders
-        env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root()
+    
+    try:
+        include_path, lib_path, exe_path = get_winddk_paths(env)
+
+        # since other tools can set these, we just make sure that the
+        # relevant stuff from WINDDK is in there somewhere.
+        env.PrependENVPath('INCLUDE', include_path)
+        env.PrependENVPath('LIB', lib_path)
+        env.PrependENVPath('PATH', exe_path)
+    except (SCons.Util.RegError, SCons.Errors.InternalError):
+        pass
+
 
 def exists(env):
     return env.Detect('cl')
 
+# vim:set sw=4 et: