Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

gallium.py 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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 symlink(target, source, env):
  113. target = str(target[0])
  114. source = str(source[0])
  115. if os.path.islink(target) or os.path.exists(target):
  116. os.remove(target)
  117. os.symlink(os.path.basename(source), target)
  118. def install_shared_library(env, source, version = ()):
  119. source = str(source[0])
  120. version = tuple(map(str, version))
  121. target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build'], 'lib')
  122. target_name = '.'.join((str(source),) + version)
  123. last = env.InstallAs(os.path.join(target_dir, target_name), source)
  124. while len(version):
  125. version = version[:-1]
  126. target_name = '.'.join((str(source),) + version)
  127. action = SCons.Action.Action(symlink, "$TARGET -> $SOURCE")
  128. last = env.Command(os.path.join(target_dir, target_name), last, action)
  129. def createInstallMethods(env):
  130. env.AddMethod(install_shared_library, 'InstallSharedLibrary')
  131. def generate(env):
  132. """Common environment generation code"""
  133. # FIXME: this is already too late
  134. #if env.get('quiet', False):
  135. # quietCommandLines(env)
  136. # shortcuts
  137. debug = env['debug']
  138. machine = env['machine']
  139. platform = env['platform']
  140. x86 = env['machine'] == 'x86'
  141. gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
  142. msvc = env['platform'] in ('windows', 'winddk', 'wince')
  143. # Tool
  144. if platform == 'winddk':
  145. env.Tool('winddk')
  146. elif platform == 'wince':
  147. env.Tool('wcesdk')
  148. else:
  149. env.Tool('default')
  150. # Put build output in a separate dir, which depends on the current
  151. # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
  152. build_topdir = 'build'
  153. build_subdir = env['platform']
  154. if env['dri']:
  155. build_subdir += "-dri"
  156. if env['llvm']:
  157. build_subdir += "-llvm"
  158. if env['machine'] != 'generic':
  159. build_subdir += '-' + env['machine']
  160. if env['debug']:
  161. build_subdir += "-debug"
  162. if env['profile']:
  163. build_subdir += "-profile"
  164. build_dir = os.path.join(build_topdir, build_subdir)
  165. # Place the .sconsign file in the build dir too, to avoid issues with
  166. # different scons versions building the same source file
  167. env['build'] = build_dir
  168. env.SConsignFile(os.path.join(build_dir, '.sconsign'))
  169. # C preprocessor options
  170. cppdefines = []
  171. if debug:
  172. cppdefines += ['DEBUG']
  173. else:
  174. cppdefines += ['NDEBUG']
  175. if env['profile']:
  176. cppdefines += ['PROFILE']
  177. if platform == 'windows':
  178. cppdefines += [
  179. 'WIN32',
  180. '_WINDOWS',
  181. '_UNICODE',
  182. 'UNICODE',
  183. # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
  184. 'WIN32_LEAN_AND_MEAN',
  185. 'VC_EXTRALEAN',
  186. '_CRT_SECURE_NO_DEPRECATE',
  187. ]
  188. if debug:
  189. cppdefines += ['_DEBUG']
  190. if platform == 'winddk':
  191. # Mimic WINDDK's builtin flags. See also:
  192. # - WINDDK's bin/makefile.new i386mk.inc for more info.
  193. # - buildchk_wxp_x86.log files, generated by the WINDDK's build
  194. # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  195. cppdefines += [
  196. ('_X86_', '1'),
  197. ('i386', '1'),
  198. 'STD_CALL',
  199. ('CONDITION_HANDLING', '1'),
  200. ('NT_INST', '0'),
  201. ('WIN32', '100'),
  202. ('_NT1X_', '100'),
  203. ('WINNT', '1'),
  204. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  205. ('WINVER', '0x0501'),
  206. ('_WIN32_IE', '0x0603'),
  207. ('WIN32_LEAN_AND_MEAN', '1'),
  208. ('DEVL', '1'),
  209. ('__BUILDMACHINE__', 'WinDDK'),
  210. ('FPO', '0'),
  211. ]
  212. if debug:
  213. cppdefines += [('DBG', 1)]
  214. if platform == 'wince':
  215. cppdefines += [
  216. '_CRT_SECURE_NO_DEPRECATE',
  217. '_USE_32BIT_TIME_T',
  218. 'UNICODE',
  219. '_UNICODE',
  220. ('UNDER_CE', '600'),
  221. ('_WIN32_WCE', '0x600'),
  222. 'WINCEOEM',
  223. 'WINCEINTERNAL',
  224. 'WIN32',
  225. 'STRICT',
  226. 'x86',
  227. '_X86_',
  228. 'INTERNATIONAL',
  229. ('INTLMSG_CODEPAGE', '1252'),
  230. ]
  231. if platform == 'windows':
  232. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
  233. if platform == 'winddk':
  234. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
  235. if platform == 'wince':
  236. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
  237. env.Append(CPPDEFINES = cppdefines)
  238. # C preprocessor includes
  239. if platform == 'winddk':
  240. env.Append(CPPPATH = [
  241. env['SDK_INC_PATH'],
  242. env['DDK_INC_PATH'],
  243. env['WDM_INC_PATH'],
  244. env['CRT_INC_PATH'],
  245. ])
  246. # C compiler options
  247. cflags = []
  248. if gcc:
  249. if debug:
  250. cflags += ['-O0', '-g3']
  251. else:
  252. cflags += ['-O3', '-g3']
  253. if env['profile']:
  254. cflags += ['-pg']
  255. if env['machine'] == 'x86':
  256. cflags += [
  257. '-m32',
  258. #'-march=pentium4',
  259. '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
  260. #'-mfpmath=sse',
  261. ]
  262. if env['machine'] == 'x86_64':
  263. cflags += ['-m64']
  264. cflags += [
  265. '-Wall',
  266. '-Wmissing-prototypes',
  267. '-Wno-long-long',
  268. '-ffast-math',
  269. '-pedantic',
  270. '-fmessage-length=0', # be nice to Eclipse
  271. ]
  272. if msvc:
  273. # See also:
  274. # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
  275. # - cl /?
  276. if debug:
  277. cflags += [
  278. '/Od', # disable optimizations
  279. '/Oi', # enable intrinsic functions
  280. '/Oy-', # disable frame pointer omission
  281. ]
  282. else:
  283. cflags += [
  284. '/Ox', # maximum optimizations
  285. '/Oi', # enable intrinsic functions
  286. '/Ot', # favor code speed
  287. #'/fp:fast', # fast floating point
  288. ]
  289. if env['profile']:
  290. cflags += [
  291. '/Gh', # enable _penter hook function
  292. '/GH', # enable _pexit hook function
  293. ]
  294. cflags += [
  295. '/W3', # warning level
  296. #'/Wp64', # enable 64 bit porting warnings
  297. ]
  298. if env['machine'] == 'x86':
  299. cflags += [
  300. #'/QIfist', # Suppress _ftol
  301. #'/arch:SSE2', # use the SSE2 instructions
  302. ]
  303. if platform == 'windows':
  304. cflags += [
  305. # TODO
  306. ]
  307. if platform == 'winddk':
  308. cflags += [
  309. '/Zl', # omit default library name in .OBJ
  310. '/Zp8', # 8bytes struct member alignment
  311. '/Gy', # separate functions for linker
  312. '/Gm-', # disable minimal rebuild
  313. '/WX', # treat warnings as errors
  314. '/Gz', # __stdcall Calling convention
  315. '/GX-', # disable C++ EH
  316. '/GR-', # disable C++ RTTI
  317. '/GF', # enable read-only string pooling
  318. '/G6', # optimize for PPro, P-II, P-III
  319. '/Ze', # enable extensions
  320. '/Gi-', # disable incremental compilation
  321. '/QIfdiv-', # disable Pentium FDIV fix
  322. '/hotpatch', # prepares an image for hotpatching.
  323. #'/Z7', #enable old-style debug info
  324. ]
  325. if platform == 'wince':
  326. # See also C:\WINCE600\public\common\oak\misc\makefile.def
  327. cflags += [
  328. '/Zl', # omit default library name in .OBJ
  329. '/GF', # enable read-only string pooling
  330. '/GR-', # disable C++ RTTI
  331. '/GS', # enable security checks
  332. # Allow disabling language conformance to maintain backward compat
  333. #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
  334. #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
  335. #'/wd4867',
  336. #'/wd4430',
  337. #'/MT',
  338. #'/U_MT',
  339. ]
  340. # Automatic pdb generation
  341. # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
  342. env.EnsureSConsVersion(0, 98, 0)
  343. env['PDB'] = '${TARGET.base}.pdb'
  344. env.Append(CFLAGS = cflags)
  345. env.Append(CXXFLAGS = cflags)
  346. # Assembler options
  347. if gcc:
  348. if env['machine'] == 'x86':
  349. env.Append(ASFLAGS = ['-m32'])
  350. if env['machine'] == 'x86_64':
  351. env.Append(ASFLAGS = ['-m64'])
  352. # Linker options
  353. linkflags = []
  354. if gcc:
  355. if env['machine'] == 'x86':
  356. linkflags += ['-m32']
  357. if env['machine'] == 'x86_64':
  358. linkflags += ['-m64']
  359. if platform == 'winddk':
  360. # See also:
  361. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  362. linkflags += [
  363. '/merge:_PAGE=PAGE',
  364. '/merge:_TEXT=.text',
  365. '/section:INIT,d',
  366. '/opt:ref',
  367. '/opt:icf',
  368. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  369. '/incremental:no',
  370. '/fullbuild',
  371. '/release',
  372. '/nodefaultlib',
  373. '/wx',
  374. '/debug',
  375. '/debugtype:cv',
  376. '/version:5.1',
  377. '/osversion:5.1',
  378. '/functionpadmin:5',
  379. '/safeseh',
  380. '/pdbcompress',
  381. '/stack:0x40000,0x1000',
  382. '/driver',
  383. '/align:0x80',
  384. '/subsystem:native,5.01',
  385. '/base:0x10000',
  386. '/entry:DrvEnableDriver',
  387. ]
  388. if env['profile']:
  389. linkflags += [
  390. '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
  391. ]
  392. if platform == 'wince':
  393. linkflags += [
  394. '/nodefaultlib',
  395. #'/incremental:no',
  396. #'/fullbuild',
  397. '/entry:_DllMainCRTStartup',
  398. ]
  399. env.Append(LINKFLAGS = linkflags)
  400. # Default libs
  401. env.Append(LIBS = [])
  402. # Custom builders and methods
  403. createConvenienceLibBuilder(env)
  404. createCodeGenerateMethod(env)
  405. createInstallMethods(env)
  406. # for debugging
  407. #print env.Dump()
  408. def exists(env):
  409. return 1