Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

gallium.py 16KB

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