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

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