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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. exe_paths.append( os.path.join(WINDDKdir, 'bin') )
  58. exe_paths.append( os.path.join(WINDDKdir, 'bin', 'x86') )
  59. include_paths.append( os.path.join(WINDDKdir, 'inc', 'wxp') )
  60. lib_paths.append( os.path.join(WINDDKdir, 'lib') )
  61. target_os = 'wxp'
  62. target_cpu = 'i386'
  63. env['SDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc', target_os)
  64. env['CRT_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'crt')
  65. env['DDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'ddk', target_os)
  66. env['WDM_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'ddk', 'wdm', target_os)
  67. env['SDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
  68. env['CRT_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', 'crt', target_cpu)
  69. env['DDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
  70. env['WDM_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
  71. include_path = string.join( include_paths, os.pathsep )
  72. lib_path = string.join(lib_paths, os.pathsep )
  73. exe_path = string.join(exe_paths, os.pathsep )
  74. return (include_path, lib_path, exe_path)
  75. def set_winddk_flags(env):
  76. """Mimic WINDDK's builtin flags.
  77. See also:
  78. - WINDDK's bin/makefile.new i386mk.inc for more info.
  79. - buildchk_wxp_x86.log files, generated by the WINDDK's build
  80. - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  81. """
  82. cppdefines = [
  83. ('_X86_', '1'),
  84. ('i386', '1'),
  85. 'STD_CALL',
  86. ('CONDITION_HANDLING', '1'),
  87. ('NT_INST', '0'),
  88. ('WIN32', '100'),
  89. ('_NT1X_', '100'),
  90. ('WINNT', '1'),
  91. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  92. ('WINVER', '0x0501'),
  93. ('_WIN32_IE', '0x0603'),
  94. ('WIN32_LEAN_AND_MEAN', '1'),
  95. ('DEVL', '1'),
  96. ('__BUILDMACHINE__', 'WinDDK'),
  97. ('FPO', '0'),
  98. ]
  99. if env.get('DEBUG', False):
  100. cppdefines += [
  101. ('DBG', 1),
  102. ]
  103. env.Append(CPPDEFINES = cppdefines)
  104. # See also:
  105. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  106. # - cl /?
  107. cflags = [
  108. '/Zl', # omit default library name in .OBJ
  109. '/Zp8', # 8bytes struct member alignment
  110. '/Gy', # separate functions for linker
  111. '/Gm-', # disable minimal rebuild
  112. '/W3', # warning level
  113. '/WX', # treat warnings as errors
  114. '/Gz', # __stdcall Calling convention
  115. '/GX-', # disable C++ EH
  116. '/GR-', # disable C++ RTTI
  117. '/GF', # enable read-only string pooling
  118. '/GS', # enable security checks
  119. '/G6', # optimize for PPro, P-II, P-III
  120. '/Ze', # enable extensions
  121. #'/Gi-', # ???
  122. '/QIfdiv-', # disable Pentium FDIV fix
  123. #'/hotpatch', # ???
  124. #'/Z7', #enable old-style debug info
  125. ]
  126. if env.get('debug', False):
  127. cflags += [
  128. '/Od', # disable optimizations
  129. '/Oi', # enable intrinsic functions
  130. '/Oy-', # disable frame pointer omission
  131. ]
  132. else:
  133. cflags += [
  134. '/Ox', # maximum optimizations
  135. '/Oi', # enable intrinsic functions
  136. '/Os', # favor code space
  137. ]
  138. env.Append(CFLAGS = cflags)
  139. env.Append(CXXFLAGS = cflags)
  140. # See also:
  141. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  142. env.Append(LINKFLAGS = [
  143. '/merge:_PAGE=PAGE',
  144. '/merge:_TEXT=.text',
  145. '/section:INIT,d',
  146. '/opt:ref',
  147. '/opt:icf',
  148. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  149. '/incremental:no',
  150. '/fullbuild',
  151. '/release',
  152. '/nodefaultlib',
  153. '/wx',
  154. '/debug',
  155. '/debugtype:cv',
  156. '/version:5.1',
  157. '/osversion:5.1',
  158. '/functionpadmin:5',
  159. '/safeseh',
  160. '/pdbcompress',
  161. '/stack:0x40000,0x1000',
  162. '/driver',
  163. '/align:0x80',
  164. '/subsystem:native,5.01',
  165. '/base:0x10000',
  166. '/entry:DrvEnableDriver',
  167. ])
  168. def validate_vars(env):
  169. """Validate the PCH and PCHSTOP construction variables."""
  170. if env.has_key('PCH') and env['PCH']:
  171. if not env.has_key('PCHSTOP'):
  172. raise SCons.Errors.UserError, "The PCHSTOP construction must be defined if PCH is defined."
  173. if not SCons.Util.is_String(env['PCHSTOP']):
  174. raise SCons.Errors.UserError, "The PCHSTOP construction variable must be a string: %r"%env['PCHSTOP']
  175. def pch_emitter(target, source, env):
  176. """Adds the object file target."""
  177. validate_vars(env)
  178. pch = None
  179. obj = None
  180. for t in target:
  181. if SCons.Util.splitext(str(t))[1] == '.pch':
  182. pch = t
  183. if SCons.Util.splitext(str(t))[1] == '.obj':
  184. obj = t
  185. if not obj:
  186. obj = SCons.Util.splitext(str(pch))[0]+'.obj'
  187. target = [pch, obj] # pch must be first, and obj second for the PCHCOM to work
  188. return (target, source)
  189. def object_emitter(target, source, env, parent_emitter):
  190. """Sets up the PCH dependencies for an object file."""
  191. validate_vars(env)
  192. parent_emitter(target, source, env)
  193. if env.has_key('PCH') and env['PCH']:
  194. env.Depends(target, env['PCH'])
  195. return (target, source)
  196. def static_object_emitter(target, source, env):
  197. return object_emitter(target, source, env,
  198. SCons.Defaults.StaticObjectEmitter)
  199. def shared_object_emitter(target, source, env):
  200. return object_emitter(target, source, env,
  201. SCons.Defaults.SharedObjectEmitter)
  202. pch_action = SCons.Action.Action('$PCHCOM', '$PCHCOMSTR')
  203. pch_builder = SCons.Builder.Builder(action=pch_action, suffix='.pch',
  204. emitter=pch_emitter,
  205. source_scanner=SCons.Tool.SourceFileScanner)
  206. res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
  207. res_builder = SCons.Builder.Builder(action=res_action,
  208. src_suffix='.rc',
  209. suffix='.res',
  210. src_builder=[],
  211. source_scanner=SCons.Tool.SourceFileScanner)
  212. SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
  213. def generate(env):
  214. """Add Builders and construction variables for MSVC++ to an Environment."""
  215. static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
  216. for suffix in CSuffixes:
  217. static_obj.add_action(suffix, SCons.Defaults.CAction)
  218. shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
  219. static_obj.add_emitter(suffix, static_object_emitter)
  220. shared_obj.add_emitter(suffix, shared_object_emitter)
  221. for suffix in CXXSuffixes:
  222. static_obj.add_action(suffix, SCons.Defaults.CXXAction)
  223. shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
  224. static_obj.add_emitter(suffix, static_object_emitter)
  225. shared_obj.add_emitter(suffix, shared_object_emitter)
  226. env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}'])
  227. env['CCPCHFLAGS'] = SCons.Util.CLVar(['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'])
  228. env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET $CCPCHFLAGS $CCPDBFLAGS'
  229. env['CC'] = 'cl'
  230. env['CCFLAGS'] = SCons.Util.CLVar('/nologo')
  231. env['CFLAGS'] = SCons.Util.CLVar('')
  232. env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
  233. env['SHCC'] = '$CC'
  234. env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
  235. env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS')
  236. env['SHCCCOM'] = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
  237. env['CXX'] = '$CC'
  238. env['CXXFLAGS'] = SCons.Util.CLVar('$CCFLAGS $( /TP $)')
  239. env['CXXCOM'] = '$CXX $CXXFLAGS $CCCOMFLAGS'
  240. env['SHCXX'] = '$CXX'
  241. env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
  242. env['SHCXXCOM'] = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
  243. env['CPPDEFPREFIX'] = '/D'
  244. env['CPPDEFSUFFIX'] = ''
  245. env['INCPREFIX'] = '/I'
  246. env['INCSUFFIX'] = ''
  247. # env.Append(OBJEMITTER = [static_object_emitter])
  248. # env.Append(SHOBJEMITTER = [shared_object_emitter])
  249. env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
  250. env['RC'] = 'rc'
  251. env['RCFLAGS'] = SCons.Util.CLVar('')
  252. env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES'
  253. env['BUILDERS']['RES'] = res_builder
  254. env['OBJPREFIX'] = ''
  255. env['OBJSUFFIX'] = '.obj'
  256. env['SHOBJPREFIX'] = '$OBJPREFIX'
  257. env['SHOBJSUFFIX'] = '$OBJSUFFIX'
  258. env['CFILESUFFIX'] = '.c'
  259. env['CXXFILESUFFIX'] = '.cc'
  260. env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Yd") or ""}'])
  261. env['PCHCOM'] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo${TARGETS[1]} /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS'
  262. env['BUILDERS']['PCH'] = pch_builder
  263. env['AR'] = 'lib'
  264. env['ARFLAGS'] = SCons.Util.CLVar('/nologo')
  265. env['ARCOM'] = "${TEMPFILE('$AR $ARFLAGS /OUT:$TARGET $SOURCES')}"
  266. env['LIBPREFIX'] = ''
  267. env['LIBSUFFIX'] = '.lib'
  268. SCons.Tool.mslink.generate(env)
  269. set_winddk_flags(env)
  270. if not env.has_key('ENV'):
  271. env['ENV'] = {}
  272. try:
  273. include_path, lib_path, exe_path = get_winddk_paths(env)
  274. # since other tools can set these, we just make sure that the
  275. # relevant stuff from WINDDK is in there somewhere.
  276. env.PrependENVPath('INCLUDE', include_path)
  277. env.PrependENVPath('LIB', lib_path)
  278. env.PrependENVPath('PATH', exe_path)
  279. except (SCons.Util.RegError, SCons.Errors.InternalError):
  280. pass
  281. def exists(env):
  282. return env.Detect('cl')
  283. # vim:set sw=4 et: