Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

gallium.py 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. """gallium
  2. Frontend-tool for Gallium3D architecture.
  3. """
  4. #
  5. # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
  6. # All Rights Reserved.
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining a
  9. # copy of this software and associated documentation files (the
  10. # "Software"), to deal in the Software without restriction, including
  11. # without limitation the rights to use, copy, modify, merge, publish,
  12. # distribute, sub license, and/or sell copies of the Software, and to
  13. # permit persons to whom the Software is furnished to do so, subject to
  14. # the following conditions:
  15. #
  16. # The above copyright notice and this permission notice (including the
  17. # next paragraph) shall be included in all copies or substantial portions
  18. # of the Software.
  19. #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. # IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. #
  28. import os.path
  29. import SCons.Action
  30. import SCons.Builder
  31. def quietCommandLines(env):
  32. # Quiet command lines
  33. # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
  34. env['CCCOMSTR'] = "Compiling $SOURCE ..."
  35. env['CXXCOMSTR'] = "Compiling $SOURCE ..."
  36. env['ARCOMSTR'] = "Archiving $TARGET ..."
  37. env['RANLIBCOMSTR'] = ""
  38. env['LINKCOMSTR'] = "Linking $TARGET ..."
  39. def createConvenienceLibBuilder(env):
  40. """This is a utility function that creates the ConvenienceLibrary
  41. Builder in an Environment if it is not there already.
  42. If it is already there, we return the existing one.
  43. Based on the stock StaticLibrary and SharedLibrary builders.
  44. """
  45. try:
  46. convenience_lib = env['BUILDERS']['ConvenienceLibrary']
  47. except KeyError:
  48. action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
  49. if env.Detect('ranlib'):
  50. ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
  51. action_list.append(ranlib_action)
  52. convenience_lib = SCons.Builder.Builder(action = action_list,
  53. emitter = '$LIBEMITTER',
  54. prefix = '$LIBPREFIX',
  55. suffix = '$LIBSUFFIX',
  56. src_suffix = '$SHOBJSUFFIX',
  57. src_builder = 'SharedObject')
  58. env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
  59. env['BUILDERS']['Library'] = convenience_lib
  60. return convenience_lib
  61. def generate(env):
  62. """Common environment generation code"""
  63. # FIXME: this is already too late
  64. #if env.get('quiet', False):
  65. # quietCommandLines(env)
  66. # shortcuts
  67. debug = env['debug']
  68. machine = env['machine']
  69. platform = env['platform']
  70. x86 = env['machine'] == 'x86'
  71. gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
  72. msvc = env['platform'] in ('windows', 'winddk', 'wince')
  73. # Tool
  74. if platform == 'winddk':
  75. env.Tool('winddk')
  76. elif platform == 'wince':
  77. env.Tool('wcesdk')
  78. else:
  79. env.Tool('default')
  80. # Put build output in a separate dir, which depends on the current
  81. # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
  82. build_topdir = 'build'
  83. build_subdir = env['platform']
  84. if env['dri']:
  85. build_subdir += "-dri"
  86. if env['llvm']:
  87. build_subdir += "-llvm"
  88. if env['machine'] != 'generic':
  89. build_subdir += '-' + env['machine']
  90. if env['debug']:
  91. build_subdir += "-debug"
  92. if env['profile']:
  93. build_subdir += "-profile"
  94. build_dir = os.path.join(build_topdir, build_subdir)
  95. # Place the .sconsign file in the build dir too, to avoid issues with
  96. # different scons versions building the same source file
  97. env['build'] = build_dir
  98. env.SConsignFile(os.path.join(build_dir, '.sconsign'))
  99. # C preprocessor options
  100. cppdefines = []
  101. if debug:
  102. cppdefines += ['DEBUG']
  103. else:
  104. cppdefines += ['NDEBUG']
  105. if env['profile']:
  106. cppdefines += ['PROFILE']
  107. if platform == 'windows':
  108. cppdefines += [
  109. 'WIN32',
  110. '_WINDOWS',
  111. '_UNICODE',
  112. 'UNICODE',
  113. # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
  114. 'WIN32_LEAN_AND_MEAN',
  115. 'VC_EXTRALEAN',
  116. '_CRT_SECURE_NO_DEPRECATE',
  117. ]
  118. if debug:
  119. cppdefines += ['_DEBUG']
  120. if platform == 'winddk':
  121. # Mimic WINDDK's builtin flags. See also:
  122. # - WINDDK's bin/makefile.new i386mk.inc for more info.
  123. # - buildchk_wxp_x86.log files, generated by the WINDDK's build
  124. # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  125. cppdefines += [
  126. ('_X86_', '1'),
  127. ('i386', '1'),
  128. 'STD_CALL',
  129. ('CONDITION_HANDLING', '1'),
  130. ('NT_INST', '0'),
  131. ('WIN32', '100'),
  132. ('_NT1X_', '100'),
  133. ('WINNT', '1'),
  134. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  135. ('WINVER', '0x0501'),
  136. ('_WIN32_IE', '0x0603'),
  137. ('WIN32_LEAN_AND_MEAN', '1'),
  138. ('DEVL', '1'),
  139. ('__BUILDMACHINE__', 'WinDDK'),
  140. ('FPO', '0'),
  141. ]
  142. if debug:
  143. cppdefines += [('DBG', 1)]
  144. if platform == 'wince':
  145. cppdefines += [
  146. '_CRT_SECURE_NO_DEPRECATE',
  147. '_USE_32BIT_TIME_T',
  148. 'UNICODE',
  149. '_UNICODE',
  150. ('UNDER_CE', '600'),
  151. ('_WIN32_WCE', '0x600'),
  152. 'WINCEOEM',
  153. 'WINCEINTERNAL',
  154. 'WIN32',
  155. 'STRICT',
  156. 'x86',
  157. '_X86_',
  158. 'INTERNATIONAL',
  159. ('INTLMSG_CODEPAGE', '1252'),
  160. ]
  161. if platform == 'windows':
  162. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
  163. if platform == 'winddk':
  164. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
  165. if platform == 'wince':
  166. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
  167. env.Append(CPPDEFINES = cppdefines)
  168. # C preprocessor includes
  169. if platform == 'winddk':
  170. env.Append(CPPPATH = [
  171. env['SDK_INC_PATH'],
  172. env['DDK_INC_PATH'],
  173. env['WDM_INC_PATH'],
  174. env['CRT_INC_PATH'],
  175. ])
  176. # C compiler options
  177. cflags = []
  178. if gcc:
  179. if debug:
  180. cflags += ['-O0', '-g3']
  181. else:
  182. cflags += ['-O3', '-g3']
  183. if env['profile']:
  184. cflags += ['-pg']
  185. if env['machine'] == 'x86':
  186. cflags += ['-m32']
  187. if env['machine'] == 'x86_64':
  188. cflags += ['-m64']
  189. cflags += [
  190. '-Wall',
  191. '-Wmissing-prototypes',
  192. '-Wno-long-long',
  193. '-ffast-math',
  194. '-pedantic',
  195. '-fmessage-length=0', # be nice to Eclipse
  196. ]
  197. if msvc:
  198. # See also:
  199. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  200. # - cl /?
  201. if debug:
  202. cflags += [
  203. '/Od', # disable optimizations
  204. '/Oi', # enable intrinsic functions
  205. '/Oy-', # disable frame pointer omission
  206. ]
  207. else:
  208. cflags += [
  209. '/Ox', # maximum optimizations
  210. '/Oi', # enable intrinsic functions
  211. '/Os', # favor code space
  212. ]
  213. if env['profile']:
  214. cflags += [
  215. '/Gh', # enable _penter hook function
  216. '/GH', # enable _pexit hook function
  217. ]
  218. cflags += [
  219. '/W3', # warning level
  220. #'/Wp64', # enable 64 bit porting warnings
  221. ]
  222. if platform == 'windows':
  223. cflags += [
  224. # TODO
  225. ]
  226. if platform == 'winddk':
  227. cflags += [
  228. '/Zl', # omit default library name in .OBJ
  229. '/Zp8', # 8bytes struct member alignment
  230. '/Gy', # separate functions for linker
  231. '/Gm-', # disable minimal rebuild
  232. '/WX', # treat warnings as errors
  233. '/Gz', # __stdcall Calling convention
  234. '/GX-', # disable C++ EH
  235. '/GR-', # disable C++ RTTI
  236. '/GF', # enable read-only string pooling
  237. '/G6', # optimize for PPro, P-II, P-III
  238. '/Ze', # enable extensions
  239. '/Gi-', # disable incremental compilation
  240. '/QIfdiv-', # disable Pentium FDIV fix
  241. '/hotpatch', # prepares an image for hotpatching.
  242. #'/Z7', #enable old-style debug info
  243. ]
  244. if platform == 'wince':
  245. # See also C:\WINCE600\public\common\oak\misc\makefile.def
  246. cflags += [
  247. '/GF', # enable read-only string pooling
  248. '/GR-', # disable C++ RTTI
  249. '/GS', # enable security checks
  250. # Allow disabling language conformance to maintain backward compat
  251. #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
  252. #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
  253. #'/wd4867',
  254. #'/wd4430',
  255. #'/MT',
  256. #'/U_MT',
  257. ]
  258. # Automatic pdb generation
  259. # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
  260. env.EnsureSConsVersion(0, 98, 0)
  261. env['PDB'] = '${TARGET.base}.pdb'
  262. env.Append(CFLAGS = cflags)
  263. env.Append(CXXFLAGS = cflags)
  264. # Assembler options
  265. if gcc:
  266. if env['machine'] == 'x86':
  267. env.Append(ASFLAGS = ['-m32'])
  268. if env['machine'] == 'x86_64':
  269. env.Append(ASFLAGS = ['-m64'])
  270. # Linker options
  271. linkflags = []
  272. if gcc:
  273. if env['machine'] == 'x86':
  274. linkflags += ['-m32']
  275. if env['machine'] == 'x86_64':
  276. linkflags += ['-m64']
  277. if platform == 'winddk':
  278. # See also:
  279. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  280. linkflags += [
  281. '/merge:_PAGE=PAGE',
  282. '/merge:_TEXT=.text',
  283. '/section:INIT,d',
  284. '/opt:ref',
  285. '/opt:icf',
  286. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  287. '/incremental:no',
  288. '/fullbuild',
  289. '/release',
  290. '/nodefaultlib',
  291. '/wx',
  292. '/debug',
  293. '/debugtype:cv',
  294. '/version:5.1',
  295. '/osversion:5.1',
  296. '/functionpadmin:5',
  297. '/safeseh',
  298. '/pdbcompress',
  299. '/stack:0x40000,0x1000',
  300. '/driver',
  301. '/align:0x80',
  302. '/subsystem:native,5.01',
  303. '/base:0x10000',
  304. '/entry:DrvEnableDriver',
  305. ]
  306. env.Append(LINKFLAGS = linkflags)
  307. # Convenience Library Builder
  308. createConvenienceLibBuilder(env)
  309. # for debugging
  310. #print env.Dump()
  311. def exists(env):
  312. return 1