Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

winddk.py 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. """winddk
  2. Tool-specific initialization for Microsoft Windows DDK.
  3. Based on engine.SCons.Tool.msvc.
  4. There normally shouldn't be any need to import this module directly.
  5. It will usually be imported through the generic SCons.Tool.Tool()
  6. selection method.
  7. """
  8. #
  9. # Copyright (c) 2001-2007 The SCons Foundation
  10. # Copyright (c) 2008 Tungsten Graphics, Inc.
  11. #
  12. # Permission is hereby granted, free of charge, to any person obtaining
  13. # a copy of this software and associated documentation files (the
  14. # "Software"), to deal in the Software without restriction, including
  15. # without limitation the rights to use, copy, modify, merge, publish,
  16. # distribute, sublicense, and/or sell copies of the Software, and to
  17. # permit persons to whom the Software is furnished to do so, subject to
  18. # the following conditions:
  19. #
  20. # The above copyright notice and this permission notice shall be included
  21. # in all copies or substantial portions of the Software.
  22. #
  23. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  24. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  25. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. #
  31. import os.path
  32. import re
  33. import string
  34. import SCons.Action
  35. import SCons.Builder
  36. import SCons.Errors
  37. import SCons.Platform.win32
  38. import SCons.Tool
  39. import SCons.Tool.mslib
  40. import SCons.Tool.mslink
  41. import SCons.Util
  42. import SCons.Warnings
  43. CSuffixes = ['.c', '.C']
  44. CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
  45. def get_winddk_paths(env, version=None):
  46. """Return a 3-tuple of (INCLUDE, LIB, PATH) as the values
  47. of those three environment variables that should be set
  48. in order to execute the MSVC tools properly."""
  49. WINDDKdir = None
  50. exe_paths = []
  51. lib_paths = []
  52. include_paths = []
  53. if 'BASEDIR' in os.environ:
  54. WINDDKdir = os.environ['BASEDIR']
  55. else:
  56. #WINDDKdir = "C:\\WINDDK\\3790.1830"
  57. WINDDKdir = "C:/WINDDK/3790.1830"
  58. exe_paths.append( os.path.join(WINDDKdir, 'bin') )
  59. exe_paths.append( os.path.join(WINDDKdir, 'bin/x86') )
  60. include_paths.append( os.path.join(WINDDKdir, 'inc/wxp') )
  61. lib_paths.append( os.path.join(WINDDKdir, 'lib') )
  62. target_os = 'wxp'
  63. target_cpu = 'i386'
  64. env['SDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc', target_os)
  65. env['CRT_INC_PATH'] = os.path.join(WINDDKdir, 'inc/crt')
  66. env['DDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc/ddk', target_os)
  67. env['WDM_INC_PATH'] = os.path.join(WINDDKdir, 'inc/ddk/wdm', target_os)
  68. env['SDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
  69. env['CRT_LIB_PATH'] = os.path.join(WINDDKdir, 'lib/crt', target_cpu)
  70. env['DDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
  71. env['WDM_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
  72. include_path = string.join( include_paths, os.pathsep )
  73. lib_path = string.join(lib_paths, os.pathsep )
  74. exe_path = string.join(exe_paths, os.pathsep )
  75. return (include_path, lib_path, exe_path)
  76. def validate_vars(env):
  77. """Validate the PCH and PCHSTOP construction variables."""
  78. if env.has_key('PCH') and env['PCH']:
  79. if not env.has_key('PCHSTOP'):
  80. raise SCons.Errors.UserError, "The PCHSTOP construction must be defined if PCH is defined."
  81. if not SCons.Util.is_String(env['PCHSTOP']):
  82. raise SCons.Errors.UserError, "The PCHSTOP construction variable must be a string: %r"%env['PCHSTOP']
  83. def pch_emitter(target, source, env):
  84. """Adds the object file target."""
  85. validate_vars(env)
  86. pch = None
  87. obj = None
  88. for t in target:
  89. if SCons.Util.splitext(str(t))[1] == '.pch':
  90. pch = t
  91. if SCons.Util.splitext(str(t))[1] == '.obj':
  92. obj = t
  93. if not obj:
  94. obj = SCons.Util.splitext(str(pch))[0]+'.obj'
  95. target = [pch, obj] # pch must be first, and obj second for the PCHCOM to work
  96. return (target, source)
  97. def object_emitter(target, source, env, parent_emitter):
  98. """Sets up the PCH dependencies for an object file."""
  99. validate_vars(env)
  100. parent_emitter(target, source, env)
  101. if env.has_key('PCH') and env['PCH']:
  102. env.Depends(target, env['PCH'])
  103. return (target, source)
  104. def static_object_emitter(target, source, env):
  105. return object_emitter(target, source, env,
  106. SCons.Defaults.StaticObjectEmitter)
  107. def shared_object_emitter(target, source, env):
  108. return object_emitter(target, source, env,
  109. SCons.Defaults.SharedObjectEmitter)
  110. pch_action = SCons.Action.Action('$PCHCOM', '$PCHCOMSTR')
  111. pch_builder = SCons.Builder.Builder(action=pch_action, suffix='.pch',
  112. emitter=pch_emitter,
  113. source_scanner=SCons.Tool.SourceFileScanner)
  114. res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
  115. res_builder = SCons.Builder.Builder(action=res_action,
  116. src_suffix='.rc',
  117. suffix='.res',
  118. src_builder=[],
  119. source_scanner=SCons.Tool.SourceFileScanner)
  120. SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
  121. def generate(env):
  122. """Add Builders and construction variables for MSVC++ to an Environment."""
  123. static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
  124. for suffix in CSuffixes:
  125. static_obj.add_action(suffix, SCons.Defaults.CAction)
  126. shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
  127. static_obj.add_emitter(suffix, static_object_emitter)
  128. shared_obj.add_emitter(suffix, shared_object_emitter)
  129. for suffix in CXXSuffixes:
  130. static_obj.add_action(suffix, SCons.Defaults.CXXAction)
  131. shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
  132. static_obj.add_emitter(suffix, static_object_emitter)
  133. shared_obj.add_emitter(suffix, shared_object_emitter)
  134. env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}'])
  135. env['CCPCHFLAGS'] = SCons.Util.CLVar(['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'])
  136. env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET $CCPCHFLAGS $CCPDBFLAGS'
  137. env['CC'] = 'cl'
  138. env['CCFLAGS'] = SCons.Util.CLVar('/nologo')
  139. env['CFLAGS'] = SCons.Util.CLVar('')
  140. env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
  141. env['SHCC'] = '$CC'
  142. env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
  143. env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS')
  144. env['SHCCCOM'] = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
  145. env['CXX'] = '$CC'
  146. env['CXXFLAGS'] = SCons.Util.CLVar('$CCFLAGS $( /TP $)')
  147. env['CXXCOM'] = '$CXX $CXXFLAGS $CCCOMFLAGS'
  148. env['SHCXX'] = '$CXX'
  149. env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
  150. env['SHCXXCOM'] = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
  151. env['CPPDEFPREFIX'] = '/D'
  152. env['CPPDEFSUFFIX'] = ''
  153. env['INCPREFIX'] = '/I'
  154. env['INCSUFFIX'] = ''
  155. # env.Append(OBJEMITTER = [static_object_emitter])
  156. # env.Append(SHOBJEMITTER = [shared_object_emitter])
  157. env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
  158. env['RC'] = 'rc'
  159. env['RCFLAGS'] = SCons.Util.CLVar('')
  160. env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES'
  161. env['BUILDERS']['RES'] = res_builder
  162. env['OBJPREFIX'] = ''
  163. env['OBJSUFFIX'] = '.obj'
  164. env['SHOBJPREFIX'] = '$OBJPREFIX'
  165. env['SHOBJSUFFIX'] = '$OBJSUFFIX'
  166. try:
  167. include_path, lib_path, exe_path = get_winddk_paths(env)
  168. # since other tools can set these, we just make sure that the
  169. # relevant stuff from MSVS is in there somewhere.
  170. env.PrependENVPath('INCLUDE', include_path)
  171. env.PrependENVPath('LIB', lib_path)
  172. env.PrependENVPath('PATH', exe_path)
  173. except (SCons.Util.RegError, SCons.Errors.InternalError):
  174. pass
  175. env['CFILESUFFIX'] = '.c'
  176. env['CXXFILESUFFIX'] = '.cc'
  177. env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Yd") or ""}'])
  178. env['PCHCOM'] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo${TARGETS[1]} /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS'
  179. env['BUILDERS']['PCH'] = pch_builder
  180. env['AR'] = 'lib'
  181. env['ARFLAGS'] = SCons.Util.CLVar('/nologo')
  182. env['ARCOM'] = "${TEMPFILE('$AR $ARFLAGS /OUT:$TARGET $SOURCES')}"
  183. env['LIBPREFIX'] = ''
  184. env['LIBSUFFIX'] = '.lib'
  185. SCons.Tool.mslink.generate(env)
  186. # See also:
  187. # - WINDDK's bin/makefile.new i386mk.inc for more info.
  188. # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  189. env.Append(CPPDEFINES = [
  190. 'WIN32',
  191. '_WINDOWS',
  192. ('i386', '1'),
  193. ('_X86_', '1'),
  194. 'STD_CALL',
  195. ('CONDITION_HANDLING', '1'),
  196. ('NT_INST', '0'),
  197. ('_NT1X_', '100'),
  198. ('WINNT', '1'),
  199. ('_WIN32_WINNT', '0x0500'), # minimum required OS version
  200. ('WIN32_LEAN_AND_MEAN', '1'),
  201. ('DEVL', '1'),
  202. ('FPO', '1'),
  203. ])
  204. cflags = [
  205. '/GF', # Enable String Pooling
  206. '/GX-', # Disable C++ Exceptions
  207. '/Zp8', # 8bytes struct member alignment
  208. #'/GS-', # No Buffer Security Check
  209. '/GR-', # Disable Run-Time Type Info
  210. '/Gz', # __stdcall Calling convention
  211. ]
  212. env.Append(CFLAGS = cflags)
  213. env.Append(CXXFLAGS = cflags)
  214. env.Append(LINKFLAGS = [
  215. '/DEBUG',
  216. '/NODEFAULTLIB',
  217. '/SUBSYSTEM:NATIVE',
  218. '/INCREMENTAL:NO',
  219. #'/DRIVER',
  220. #'-subsystem:native,4.00',
  221. '-base:0x10000',
  222. '-entry:DrvEnableDriver',
  223. ])
  224. if not env.has_key('ENV'):
  225. env['ENV'] = {}
  226. if not env['ENV'].has_key('SystemRoot'): # required for dlls in the winsxs folders
  227. env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root()
  228. def exists(env):
  229. return env.Detect('cl')