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

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