Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

gallium.py 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 symlink(target, source, env):
  35. target = str(target[0])
  36. source = str(source[0])
  37. if os.path.islink(target) or os.path.exists(target):
  38. os.remove(target)
  39. os.symlink(os.path.basename(source), target)
  40. def install(env, source, subdir):
  41. target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build'], subdir)
  42. env.Install(target_dir, source)
  43. def install_program(env, source):
  44. install(env, source, 'bin')
  45. def install_shared_library(env, sources, version = ()):
  46. install_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build'])
  47. version = tuple(map(str, version))
  48. if env['SHLIBSUFFIX'] == '.dll':
  49. dlls = env.FindIxes(sources, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  50. install(env, dlls, 'bin')
  51. libs = env.FindIxes(sources, 'LIBPREFIX', 'LIBSUFFIX')
  52. install(env, libs, 'lib')
  53. else:
  54. for source in sources:
  55. target_dir = os.path.join(install_dir, 'lib')
  56. target_name = '.'.join((str(source),) + version)
  57. last = env.InstallAs(os.path.join(target_dir, target_name), source)
  58. while len(version):
  59. version = version[:-1]
  60. target_name = '.'.join((str(source),) + version)
  61. action = SCons.Action.Action(symlink, "$TARGET -> $SOURCE")
  62. last = env.Command(os.path.join(target_dir, target_name), last, action)
  63. def createInstallMethods(env):
  64. env.AddMethod(install_program, 'InstallProgram')
  65. env.AddMethod(install_shared_library, 'InstallSharedLibrary')
  66. def num_jobs():
  67. try:
  68. return int(os.environ['NUMBER_OF_PROCESSORS'])
  69. except (ValueError, KeyError):
  70. pass
  71. try:
  72. return os.sysconf('SC_NPROCESSORS_ONLN')
  73. except (ValueError, OSError, AttributeError):
  74. pass
  75. try:
  76. return int(os.popen2("sysctl -n hw.ncpu")[1].read())
  77. except ValueError:
  78. pass
  79. return 1
  80. def generate(env):
  81. """Common environment generation code"""
  82. # Toolchain
  83. platform = env['platform']
  84. if env['toolchain'] == 'default':
  85. if platform == 'winddk':
  86. env['toolchain'] = 'winddk'
  87. elif platform == 'wince':
  88. env['toolchain'] = 'wcesdk'
  89. env.Tool(env['toolchain'])
  90. env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
  91. env['msvc'] = env['CC'] == 'cl'
  92. # shortcuts
  93. debug = env['debug']
  94. machine = env['machine']
  95. platform = env['platform']
  96. x86 = env['machine'] == 'x86'
  97. ppc = env['machine'] == 'ppc'
  98. gcc = env['gcc']
  99. msvc = env['msvc']
  100. # Put build output in a separate dir, which depends on the current
  101. # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
  102. build_topdir = 'build'
  103. build_subdir = env['platform']
  104. if env['llvm']:
  105. build_subdir += "-llvm"
  106. if env['machine'] != 'generic':
  107. build_subdir += '-' + env['machine']
  108. if env['debug']:
  109. build_subdir += "-debug"
  110. if env['profile']:
  111. build_subdir += "-profile"
  112. build_dir = os.path.join(build_topdir, build_subdir)
  113. # Place the .sconsign file in the build dir too, to avoid issues with
  114. # different scons versions building the same source file
  115. env['build'] = build_dir
  116. env.SConsignFile(os.path.join(build_dir, '.sconsign'))
  117. env.CacheDir('build/cache')
  118. env['CONFIGUREDIR'] = os.path.join(build_dir, 'conf')
  119. env['CONFIGURELOG'] = os.path.join(os.path.abspath(build_dir), 'config.log')
  120. # Parallel build
  121. if env.GetOption('num_jobs') <= 1:
  122. env.SetOption('num_jobs', num_jobs())
  123. # C preprocessor options
  124. cppdefines = []
  125. if debug:
  126. cppdefines += ['DEBUG']
  127. else:
  128. cppdefines += ['NDEBUG']
  129. if env['profile']:
  130. cppdefines += ['PROFILE']
  131. if platform == 'windows':
  132. cppdefines += [
  133. 'WIN32',
  134. '_WINDOWS',
  135. #'_UNICODE',
  136. #'UNICODE',
  137. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  138. ('WINVER', '0x0501'),
  139. ]
  140. if msvc and env['toolchain'] != 'winddk':
  141. cppdefines += [
  142. 'VC_EXTRALEAN',
  143. '_USE_MATH_DEFINES',
  144. '_CRT_SECURE_NO_WARNINGS',
  145. '_CRT_SECURE_NO_DEPRECATE',
  146. '_SCL_SECURE_NO_WARNINGS',
  147. '_SCL_SECURE_NO_DEPRECATE',
  148. ]
  149. if debug:
  150. cppdefines += ['_DEBUG']
  151. if env['toolchain'] == 'winddk':
  152. # Mimic WINDDK's builtin flags. See also:
  153. # - WINDDK's bin/makefile.new i386mk.inc for more info.
  154. # - buildchk_wxp_x86.log files, generated by the WINDDK's build
  155. # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  156. if machine == 'x86':
  157. cppdefines += ['_X86_', 'i386']
  158. if machine == 'x86_64':
  159. cppdefines += ['_AMD64_', 'AMD64']
  160. if platform == 'winddk':
  161. cppdefines += [
  162. 'STD_CALL',
  163. ('CONDITION_HANDLING', '1'),
  164. ('NT_INST', '0'),
  165. ('WIN32', '100'),
  166. ('_NT1X_', '100'),
  167. ('WINNT', '1'),
  168. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  169. ('WINVER', '0x0501'),
  170. ('_WIN32_IE', '0x0603'),
  171. ('WIN32_LEAN_AND_MEAN', '1'),
  172. ('DEVL', '1'),
  173. ('__BUILDMACHINE__', 'WinDDK'),
  174. ('FPO', '0'),
  175. ]
  176. if debug:
  177. cppdefines += [('DBG', 1)]
  178. if platform == 'wince':
  179. cppdefines += [
  180. '_CRT_SECURE_NO_DEPRECATE',
  181. '_USE_32BIT_TIME_T',
  182. 'UNICODE',
  183. '_UNICODE',
  184. ('UNDER_CE', '600'),
  185. ('_WIN32_WCE', '0x600'),
  186. 'WINCEOEM',
  187. 'WINCEINTERNAL',
  188. 'WIN32',
  189. 'STRICT',
  190. 'x86',
  191. '_X86_',
  192. 'INTERNATIONAL',
  193. ('INTLMSG_CODEPAGE', '1252'),
  194. ]
  195. if platform == 'windows':
  196. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
  197. if platform == 'winddk':
  198. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
  199. if platform == 'wince':
  200. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
  201. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
  202. env.Append(CPPDEFINES = cppdefines)
  203. # C compiler options
  204. cflags = [] # C
  205. cxxflags = [] # C++
  206. ccflags = [] # C & C++
  207. if gcc:
  208. if debug:
  209. ccflags += ['-O0', '-g3']
  210. elif env['CCVERSION'].startswith('4.2.'):
  211. # gcc 4.2.x optimizer is broken
  212. print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
  213. ccflags += ['-O0', '-g3']
  214. else:
  215. ccflags += ['-O3', '-g3']
  216. if env['profile']:
  217. # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
  218. ccflags += [
  219. '-fno-omit-frame-pointer',
  220. '-fno-optimize-sibling-calls',
  221. ]
  222. if env['machine'] == 'x86':
  223. ccflags += [
  224. '-m32',
  225. #'-march=pentium4',
  226. #'-mfpmath=sse',
  227. ]
  228. if platform != 'windows':
  229. # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
  230. # for -mincoming-stack-boundary=2. Still enable it on other
  231. # platforms for now, but we can't rely on it for cross platform
  232. # code. We have to use __attribute__((force_align_arg_pointer))
  233. # instead.
  234. ccflags += [
  235. '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
  236. '-mstackrealign', # ensure stack is aligned
  237. ]
  238. if env['machine'] == 'x86_64':
  239. ccflags += ['-m64']
  240. # See also:
  241. # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  242. ccflags += [
  243. '-Wall',
  244. '-Wmissing-field-initializers',
  245. '-Werror=pointer-arith',
  246. '-Wno-long-long',
  247. '-ffast-math',
  248. '-fmessage-length=0', # be nice to Eclipse
  249. ]
  250. cflags += [
  251. '-Werror=declaration-after-statement',
  252. '-Wmissing-prototypes',
  253. '-std=gnu99',
  254. ]
  255. if msvc:
  256. # See also:
  257. # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
  258. # - cl /?
  259. if debug:
  260. ccflags += [
  261. '/Od', # disable optimizations
  262. '/Oi', # enable intrinsic functions
  263. '/Oy-', # disable frame pointer omission
  264. '/GL-', # disable whole program optimization
  265. ]
  266. else:
  267. ccflags += [
  268. '/O2', # optimize for speed
  269. '/GL', # enable whole program optimization
  270. ]
  271. ccflags += [
  272. '/fp:fast', # fast floating point
  273. '/W3', # warning level
  274. #'/Wp64', # enable 64 bit porting warnings
  275. ]
  276. if env['machine'] == 'x86':
  277. ccflags += [
  278. #'/arch:SSE2', # use the SSE2 instructions
  279. ]
  280. if platform == 'windows':
  281. ccflags += [
  282. # TODO
  283. ]
  284. if platform == 'winddk':
  285. ccflags += [
  286. '/Zl', # omit default library name in .OBJ
  287. '/Zp8', # 8bytes struct member alignment
  288. '/Gy', # separate functions for linker
  289. '/Gm-', # disable minimal rebuild
  290. '/WX', # treat warnings as errors
  291. '/Gz', # __stdcall Calling convention
  292. '/GX-', # disable C++ EH
  293. '/GR-', # disable C++ RTTI
  294. '/GF', # enable read-only string pooling
  295. '/G6', # optimize for PPro, P-II, P-III
  296. '/Ze', # enable extensions
  297. '/Gi-', # disable incremental compilation
  298. '/QIfdiv-', # disable Pentium FDIV fix
  299. '/hotpatch', # prepares an image for hotpatching.
  300. #'/Z7', #enable old-style debug info
  301. ]
  302. if platform == 'wince':
  303. # See also C:\WINCE600\public\common\oak\misc\makefile.def
  304. ccflags += [
  305. '/Zl', # omit default library name in .OBJ
  306. '/GF', # enable read-only string pooling
  307. '/GR-', # disable C++ RTTI
  308. '/GS', # enable security checks
  309. # Allow disabling language conformance to maintain backward compat
  310. #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
  311. #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
  312. #'/wd4867',
  313. #'/wd4430',
  314. #'/MT',
  315. #'/U_MT',
  316. ]
  317. # Automatic pdb generation
  318. # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
  319. env.EnsureSConsVersion(0, 98, 0)
  320. env['PDB'] = '${TARGET.base}.pdb'
  321. env.Append(CCFLAGS = ccflags)
  322. env.Append(CFLAGS = cflags)
  323. env.Append(CXXFLAGS = cxxflags)
  324. if env['platform'] == 'windows' and msvc:
  325. # Choose the appropriate MSVC CRT
  326. # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
  327. if env['debug']:
  328. env.Append(CCFLAGS = ['/MTd'])
  329. env.Append(SHCCFLAGS = ['/LDd'])
  330. else:
  331. env.Append(CCFLAGS = ['/MT'])
  332. env.Append(SHCCFLAGS = ['/LD'])
  333. # Assembler options
  334. if gcc:
  335. if env['machine'] == 'x86':
  336. env.Append(ASFLAGS = ['-m32'])
  337. if env['machine'] == 'x86_64':
  338. env.Append(ASFLAGS = ['-m64'])
  339. # Linker options
  340. linkflags = []
  341. shlinkflags = []
  342. if gcc:
  343. if env['machine'] == 'x86':
  344. linkflags += ['-m32']
  345. if env['machine'] == 'x86_64':
  346. linkflags += ['-m64']
  347. shlinkflags += [
  348. '-Wl,-Bsymbolic',
  349. ]
  350. # Handle circular dependencies in the libraries
  351. env['_LIBFLAGS'] = '-Wl,--start-group ' + env['_LIBFLAGS'] + ' -Wl,--end-group'
  352. if msvc:
  353. if not env['debug']:
  354. # enable Link-time Code Generation
  355. linkflags += ['/LTCG']
  356. env.Append(ARFLAGS = ['/LTCG'])
  357. if platform == 'windows' and msvc:
  358. # See also:
  359. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  360. linkflags += [
  361. '/fixed:no',
  362. '/incremental:no',
  363. ]
  364. if platform == 'winddk':
  365. linkflags += [
  366. '/merge:_PAGE=PAGE',
  367. '/merge:_TEXT=.text',
  368. '/section:INIT,d',
  369. '/opt:ref',
  370. '/opt:icf',
  371. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  372. '/incremental:no',
  373. '/fullbuild',
  374. '/release',
  375. '/nodefaultlib',
  376. '/wx',
  377. '/debug',
  378. '/debugtype:cv',
  379. '/version:5.1',
  380. '/osversion:5.1',
  381. '/functionpadmin:5',
  382. '/safeseh',
  383. '/pdbcompress',
  384. '/stack:0x40000,0x1000',
  385. '/driver',
  386. '/align:0x80',
  387. '/subsystem:native,5.01',
  388. '/base:0x10000',
  389. '/entry:DrvEnableDriver',
  390. ]
  391. if env['debug'] or env['profile']:
  392. linkflags += [
  393. '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
  394. ]
  395. if platform == 'wince':
  396. linkflags += [
  397. '/nodefaultlib',
  398. #'/incremental:no',
  399. #'/fullbuild',
  400. '/entry:_DllMainCRTStartup',
  401. ]
  402. env.Append(LINKFLAGS = linkflags)
  403. env.Append(SHLINKFLAGS = shlinkflags)
  404. # Default libs
  405. env.Append(LIBS = [])
  406. # Custom builders and methods
  407. env.Tool('custom')
  408. createInstallMethods(env)
  409. # for debugging
  410. #print env.Dump()
  411. def exists(env):
  412. return 1