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

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