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

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