scons: Faithfully mimic every WINDDK builtin compiler/linker option.
diff --git a/SConstruct b/SConstruct
index 6088128..4785e39 100644
--- a/SConstruct
+++ b/SConstruct
@@ -113,17 +113,9 @@
 	env.Append(CXXFLAGS = '-fmessage-length=0')
 
 if msvc:
-	env.Append(CFLAGS = '/W3')
-	if debug:
-		cflags = [
-			'/Od', # disable optimizations
-			'/Oy-', # disable frame pointer omission
-		]
-	else:
-		cflags = [
-			'/Ox', # maximum optimizations
-			'/Os', # favor code space
-		]
+	cflags = [
+		#'/Wp64', # enable 64 bit porting warnings
+	]
 	env.Append(CFLAGS = cflags)
 	env.Append(CXXFLAGS = cflags)
 	# Put debugging information in a separate .pdb file for each object file as
@@ -132,14 +124,7 @@
 
 # Defines
 if debug:
-	if gcc:
-		env.Append(CPPDEFINES = ['DEBUG'])
-	if msvc:
-		env.Append(CPPDEFINES = [
-			('DBG', '1'),
-			('DEBUG', '1'),
-			('_DEBUG', '1'),
-		])
+	env.Append(CPPDEFINES = ['DEBUG'])
 else:
 	env.Append(CPPDEFINES = ['NDEBUG'])
 
@@ -217,6 +202,9 @@
 		'Xfixes',
 	])
 
+# for debugging
+#print env.Dump()
+
 Export('env')
 
 
diff --git a/winddk.py b/winddk.py
index d29399f..c112329 100644
--- a/winddk.py
+++ b/winddk.py
@@ -89,6 +89,105 @@
     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']:
@@ -215,47 +314,7 @@
 
     SCons.Tool.mslink.generate(env)
 
-    # See also:
-    # - WINDDK's bin/makefile.new i386mk.inc for more info.
-    # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
-    env.Append(CPPDEFINES = [
-        'WIN32', 
-        '_WINDOWS', 
-        ('i386', '1'), 
-        ('_X86_', '1'), 
-        'STD_CALL', 
-        ('CONDITION_HANDLING', '1'),
-        ('NT_INST', '0'), 
-        ('_NT1X_', '100'),
-        ('WINNT', '1'),
-        ('_WIN32_WINNT', '0x0500'), # minimum required OS version
-        ('WIN32_LEAN_AND_MEAN', '1'),
-        ('DEVL', '1'),
-        ('FPO', '1'),
-    ])
-    cflags = [
-        '/GF', # Enable String Pooling
-        '/GX-', # Disable C++ Exceptions
-        '/Zp8', # 8bytes struct member alignment
-        #'/GS-', # No Buffer Security Check
-        '/GR-', # Disable Run-Time Type Info
-        '/Gz', # __stdcall Calling convention
-    ]
-    env.Append(CFLAGS = cflags)
-    env.Append(CXXFLAGS = cflags)
-    
-    env.Append(LINKFLAGS = [
-        '/DEBUG',
-        '/NODEFAULTLIB',
-        '/SUBSYSTEM:NATIVE',
-        '/INCREMENTAL:NO',
-        #'/DRIVER', 
-    
-        #'-subsystem:native,4.00',
-        '-base:0x10000',
-        
-        '-entry:DrvEnableDriver',
-    ])
+    set_winddk_flags(env)
     
     if not env.has_key('ENV'):
         env['ENV'] = {}
@@ -275,3 +334,4 @@
 def exists(env):
     return env.Detect('cl')
 
+# vim:set sw=4 et: