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.

gallium.py 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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
  29. import os.path
  30. import re
  31. import SCons.Action
  32. import SCons.Builder
  33. import SCons.Scanner
  34. def quietCommandLines(env):
  35. # Quiet command lines
  36. # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
  37. env['CCCOMSTR'] = "Compiling $SOURCE ..."
  38. env['CXXCOMSTR'] = "Compiling $SOURCE ..."
  39. env['ARCOMSTR'] = "Archiving $TARGET ..."
  40. env['RANLIBCOMSTR'] = ""
  41. env['LINKCOMSTR'] = "Linking $TARGET ..."
  42. def createConvenienceLibBuilder(env):
  43. """This is a utility function that creates the ConvenienceLibrary
  44. Builder in an Environment if it is not there already.
  45. If it is already there, we return the existing one.
  46. Based on the stock StaticLibrary and SharedLibrary builders.
  47. """
  48. try:
  49. convenience_lib = env['BUILDERS']['ConvenienceLibrary']
  50. except KeyError:
  51. action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
  52. if env.Detect('ranlib'):
  53. ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
  54. action_list.append(ranlib_action)
  55. convenience_lib = SCons.Builder.Builder(action = action_list,
  56. emitter = '$LIBEMITTER',
  57. prefix = '$LIBPREFIX',
  58. suffix = '$LIBSUFFIX',
  59. src_suffix = '$SHOBJSUFFIX',
  60. src_builder = 'SharedObject')
  61. env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
  62. return convenience_lib
  63. # TODO: handle import statements with multiple modules
  64. # TODO: handle from import statements
  65. import_re = re.compile(r'^import\s+(\S+)$', re.M)
  66. def python_scan(node, env, path):
  67. # http://www.scons.org/doc/0.98.5/HTML/scons-user/c2781.html#AEN2789
  68. contents = node.get_contents()
  69. source_dir = node.get_dir()
  70. imports = import_re.findall(contents)
  71. results = []
  72. for imp in imports:
  73. for dir in path:
  74. file = os.path.join(str(dir), imp.replace('.', os.sep) + '.py')
  75. if os.path.exists(file):
  76. results.append(env.File(file))
  77. break
  78. file = os.path.join(str(dir), imp.replace('.', os.sep), '__init__.py')
  79. if os.path.exists(file):
  80. results.append(env.File(file))
  81. break
  82. return results
  83. python_scanner = SCons.Scanner.Scanner(function = python_scan, skeys = ['.py'])
  84. def code_generate(env, script, target, source, command):
  85. """Method to simplify code generation via python scripts.
  86. http://www.scons.org/wiki/UsingCodeGenerators
  87. http://www.scons.org/doc/0.98.5/HTML/scons-user/c2768.html
  88. """
  89. # We're generating code using Python scripts, so we have to be
  90. # careful with our scons elements. This entry represents
  91. # the generator file *in the source directory*.
  92. script_src = env.File(script).srcnode()
  93. # This command creates generated code *in the build directory*.
  94. command = command.replace('$SCRIPT', script_src.path)
  95. code = env.Command(target, source, command)
  96. # Explicitly mark that the generated code depends on the generator,
  97. # and on implicitly imported python modules
  98. path = (script_src.get_dir(),)
  99. deps = [script_src]
  100. deps += script_src.get_implicit_deps(env, python_scanner, path)
  101. env.Depends(code, deps)
  102. # Running the Python script causes .pyc files to be generated in the
  103. # source directory. When we clean up, they should go too. So add side
  104. # effects for .pyc files
  105. for dep in deps:
  106. pyc = env.File(str(dep) + 'c')
  107. env.SideEffect(pyc, code)
  108. return code
  109. def createCodeGenerateMethod(env):
  110. env.Append(SCANNERS = python_scanner)
  111. env.AddMethod(code_generate, 'CodeGenerate')
  112. def generate(env):
  113. """Common environment generation code"""
  114. # FIXME: this is already too late
  115. #if env.get('quiet', False):
  116. # quietCommandLines(env)
  117. # shortcuts
  118. debug = env['debug']
  119. machine = env['machine']
  120. platform = env['platform']
  121. x86 = env['machine'] == 'x86'
  122. gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
  123. msvc = env['platform'] in ('windows', 'winddk', 'wince')
  124. # Tool
  125. if platform == 'winddk':
  126. env.Tool('winddk')
  127. elif platform == 'wince':
  128. env.Tool('wcesdk')
  129. else:
  130. env.Tool('default')
  131. # Put build output in a separate dir, which depends on the current
  132. # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
  133. build_topdir = 'build'
  134. build_subdir = env['platform']
  135. if env['dri']:
  136. build_subdir += "-dri"
  137. if env['llvm']:
  138. build_subdir += "-llvm"
  139. if env['machine'] != 'generic':
  140. build_subdir += '-' + env['machine']
  141. if env['debug']:
  142. build_subdir += "-debug"
  143. if env['profile']:
  144. build_subdir += "-profile"
  145. build_dir = os.path.join(build_topdir, build_subdir)
  146. # Place the .sconsign file in the build dir too, to avoid issues with
  147. # different scons versions building the same source file
  148. env['build'] = build_dir
  149. env.SConsignFile(os.path.join(build_dir, '.sconsign'))
  150. # C preprocessor options
  151. cppdefines = []
  152. if debug:
  153. cppdefines += ['DEBUG']
  154. else:
  155. cppdefines += ['NDEBUG']
  156. if env['profile']:
  157. cppdefines += ['PROFILE']
  158. if platform == 'windows':
  159. cppdefines += [
  160. 'WIN32',
  161. '_WINDOWS',
  162. '_UNICODE',
  163. 'UNICODE',
  164. # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
  165. 'WIN32_LEAN_AND_MEAN',
  166. 'VC_EXTRALEAN',
  167. '_CRT_SECURE_NO_DEPRECATE',
  168. ]
  169. if debug:
  170. cppdefines += ['_DEBUG']
  171. if platform == 'winddk':
  172. # Mimic WINDDK's builtin flags. See also:
  173. # - WINDDK's bin/makefile.new i386mk.inc for more info.
  174. # - buildchk_wxp_x86.log files, generated by the WINDDK's build
  175. # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  176. cppdefines += [
  177. ('_X86_', '1'),
  178. ('i386', '1'),
  179. 'STD_CALL',
  180. ('CONDITION_HANDLING', '1'),
  181. ('NT_INST', '0'),
  182. ('WIN32', '100'),
  183. ('_NT1X_', '100'),
  184. ('WINNT', '1'),
  185. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  186. ('WINVER', '0x0501'),
  187. ('_WIN32_IE', '0x0603'),
  188. ('WIN32_LEAN_AND_MEAN', '1'),
  189. ('DEVL', '1'),
  190. ('__BUILDMACHINE__', 'WinDDK'),
  191. ('FPO', '0'),
  192. ]
  193. if debug:
  194. cppdefines += [('DBG', 1)]
  195. if platform == 'wince':
  196. cppdefines += [
  197. '_CRT_SECURE_NO_DEPRECATE',
  198. '_USE_32BIT_TIME_T',
  199. 'UNICODE',
  200. '_UNICODE',
  201. ('UNDER_CE', '600'),
  202. ('_WIN32_WCE', '0x600'),
  203. 'WINCEOEM',
  204. 'WINCEINTERNAL',
  205. 'WIN32',
  206. 'STRICT',
  207. 'x86',
  208. '_X86_',
  209. 'INTERNATIONAL',
  210. ('INTLMSG_CODEPAGE', '1252'),
  211. ]
  212. if platform == 'windows':
  213. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
  214. if platform == 'winddk':
  215. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
  216. if platform == 'wince':
  217. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
  218. env.Append(CPPDEFINES = cppdefines)
  219. # C preprocessor includes
  220. if platform == 'winddk':
  221. env.Append(CPPPATH = [
  222. env['SDK_INC_PATH'],
  223. env['DDK_INC_PATH'],
  224. env['WDM_INC_PATH'],
  225. env['CRT_INC_PATH'],
  226. ])
  227. # C compiler options
  228. cflags = []
  229. if gcc:
  230. if debug:
  231. cflags += ['-O0', '-g3']
  232. else:
  233. cflags += ['-O3', '-g3']
  234. if env['profile']:
  235. cflags += ['-pg']
  236. if env['machine'] == 'x86':
  237. cflags += [
  238. '-m32',
  239. #'-march=pentium4',
  240. '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
  241. #'-mfpmath=sse',
  242. ]
  243. if env['machine'] == 'x86_64':
  244. cflags += ['-m64']
  245. cflags += [
  246. '-Wall',
  247. '-Wmissing-prototypes',
  248. '-Wno-long-long',
  249. '-ffast-math',
  250. '-pedantic',
  251. '-fmessage-length=0', # be nice to Eclipse
  252. ]
  253. if msvc:
  254. # See also:
  255. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  256. # - cl /?
  257. if debug:
  258. cflags += [
  259. '/Od', # disable optimizations
  260. '/Oi', # enable intrinsic functions
  261. '/Oy-', # disable frame pointer omission
  262. ]
  263. else:
  264. cflags += [
  265. '/Ox', # maximum optimizations
  266. '/Oi', # enable intrinsic functions
  267. '/Os', # favor code space
  268. ]
  269. if env['profile']:
  270. cflags += [
  271. '/Gh', # enable _penter hook function
  272. '/GH', # enable _pexit hook function
  273. ]
  274. cflags += [
  275. '/W3', # warning level
  276. #'/Wp64', # enable 64 bit porting warnings
  277. ]
  278. if platform == 'windows':
  279. cflags += [
  280. # TODO
  281. ]
  282. if platform == 'winddk':
  283. cflags += [
  284. '/Zl', # omit default library name in .OBJ
  285. '/Zp8', # 8bytes struct member alignment
  286. '/Gy', # separate functions for linker
  287. '/Gm-', # disable minimal rebuild
  288. '/WX', # treat warnings as errors
  289. '/Gz', # __stdcall Calling convention
  290. '/GX-', # disable C++ EH
  291. '/GR-', # disable C++ RTTI
  292. '/GF', # enable read-only string pooling
  293. '/G6', # optimize for PPro, P-II, P-III
  294. '/Ze', # enable extensions
  295. '/Gi-', # disable incremental compilation
  296. '/QIfdiv-', # disable Pentium FDIV fix
  297. '/hotpatch', # prepares an image for hotpatching.
  298. #'/Z7', #enable old-style debug info
  299. ]
  300. if platform == 'wince':
  301. # See also C:\WINCE600\public\common\oak\misc\makefile.def
  302. cflags += [
  303. '/Zl', # omit default library name in .OBJ
  304. '/GF', # enable read-only string pooling
  305. '/GR-', # disable C++ RTTI
  306. '/GS', # enable security checks
  307. # Allow disabling language conformance to maintain backward compat
  308. #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
  309. #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
  310. #'/wd4867',
  311. #'/wd4430',
  312. #'/MT',
  313. #'/U_MT',
  314. ]
  315. # Automatic pdb generation
  316. # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
  317. env.EnsureSConsVersion(0, 98, 0)
  318. env['PDB'] = '${TARGET.base}.pdb'
  319. env.Append(CFLAGS = cflags)
  320. env.Append(CXXFLAGS = cflags)
  321. # Assembler options
  322. if gcc:
  323. if env['machine'] == 'x86':
  324. env.Append(ASFLAGS = ['-m32'])
  325. if env['machine'] == 'x86_64':
  326. env.Append(ASFLAGS = ['-m64'])
  327. # Linker options
  328. linkflags = []
  329. if gcc:
  330. if env['machine'] == 'x86':
  331. linkflags += ['-m32']
  332. if env['machine'] == 'x86_64':
  333. linkflags += ['-m64']
  334. if platform == 'winddk':
  335. # See also:
  336. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  337. linkflags += [
  338. '/merge:_PAGE=PAGE',
  339. '/merge:_TEXT=.text',
  340. '/section:INIT,d',
  341. '/opt:ref',
  342. '/opt:icf',
  343. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  344. '/incremental:no',
  345. '/fullbuild',
  346. '/release',
  347. '/nodefaultlib',
  348. '/wx',
  349. '/debug',
  350. '/debugtype:cv',
  351. '/version:5.1',
  352. '/osversion:5.1',
  353. '/functionpadmin:5',
  354. '/safeseh',
  355. '/pdbcompress',
  356. '/stack:0x40000,0x1000',
  357. '/driver',
  358. '/align:0x80',
  359. '/subsystem:native,5.01',
  360. '/base:0x10000',
  361. '/entry:DrvEnableDriver',
  362. ]
  363. if platform == 'wince':
  364. linkflags += [
  365. '/nodefaultlib',
  366. # '/incremental:no',
  367. # '/fullbuild',
  368. '/entry:_DllMainCRTStartup',
  369. ]
  370. if env['profile']:
  371. linkflags += [
  372. '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
  373. ]
  374. env.Append(LINKFLAGS = linkflags)
  375. # Custom builders and methods
  376. createConvenienceLibBuilder(env)
  377. createCodeGenerateMethod(env)
  378. # for debugging
  379. #print env.Dump()
  380. def exists(env):
  381. return 1