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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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['llvm']:
  121. build_subdir += "-llvm"
  122. if env['machine'] != 'generic':
  123. build_subdir += '-' + env['machine']
  124. if env['debug']:
  125. build_subdir += "-debug"
  126. if env['profile']:
  127. build_subdir += "-profile"
  128. build_dir = os.path.join(build_topdir, build_subdir)
  129. # Place the .sconsign file in the build dir too, to avoid issues with
  130. # different scons versions building the same source file
  131. env['build'] = build_dir
  132. env.SConsignFile(os.path.join(build_dir, '.sconsign'))
  133. env.CacheDir('build/cache')
  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. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  154. ('WINVER', '0x0501'),
  155. ]
  156. if msvc and env['toolchain'] != 'winddk':
  157. cppdefines += [
  158. 'VC_EXTRALEAN',
  159. '_USE_MATH_DEFINES',
  160. '_CRT_SECURE_NO_WARNINGS',
  161. '_CRT_SECURE_NO_DEPRECATE',
  162. '_SCL_SECURE_NO_WARNINGS',
  163. '_SCL_SECURE_NO_DEPRECATE',
  164. ]
  165. if debug:
  166. cppdefines += ['_DEBUG']
  167. if env['toolchain'] == 'winddk':
  168. # Mimic WINDDK's builtin flags. See also:
  169. # - WINDDK's bin/makefile.new i386mk.inc for more info.
  170. # - buildchk_wxp_x86.log files, generated by the WINDDK's build
  171. # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  172. if machine == 'x86':
  173. cppdefines += ['_X86_', 'i386']
  174. if machine == 'x86_64':
  175. cppdefines += ['_AMD64_', 'AMD64']
  176. if platform == 'winddk':
  177. cppdefines += [
  178. 'STD_CALL',
  179. ('CONDITION_HANDLING', '1'),
  180. ('NT_INST', '0'),
  181. ('WIN32', '100'),
  182. ('_NT1X_', '100'),
  183. ('WINNT', '1'),
  184. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  185. ('WINVER', '0x0501'),
  186. ('_WIN32_IE', '0x0603'),
  187. ('WIN32_LEAN_AND_MEAN', '1'),
  188. ('DEVL', '1'),
  189. ('__BUILDMACHINE__', 'WinDDK'),
  190. ('FPO', '0'),
  191. ]
  192. if debug:
  193. cppdefines += [('DBG', 1)]
  194. if platform == 'wince':
  195. cppdefines += [
  196. '_CRT_SECURE_NO_DEPRECATE',
  197. '_USE_32BIT_TIME_T',
  198. 'UNICODE',
  199. '_UNICODE',
  200. ('UNDER_CE', '600'),
  201. ('_WIN32_WCE', '0x600'),
  202. 'WINCEOEM',
  203. 'WINCEINTERNAL',
  204. 'WIN32',
  205. 'STRICT',
  206. 'x86',
  207. '_X86_',
  208. 'INTERNATIONAL',
  209. ('INTLMSG_CODEPAGE', '1252'),
  210. ]
  211. if platform == 'windows':
  212. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
  213. if platform == 'winddk':
  214. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
  215. if platform == 'wince':
  216. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
  217. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
  218. if platform == 'embedded':
  219. cppdefines += ['PIPE_OS_EMBEDDED']
  220. env.Append(CPPDEFINES = cppdefines)
  221. # C compiler options
  222. cflags = [] # C
  223. cxxflags = [] # C++
  224. ccflags = [] # C & C++
  225. if gcc:
  226. ccversion = env['CCVERSION']
  227. if debug:
  228. ccflags += ['-O0', '-g3']
  229. elif ccversion.startswith('4.2.'):
  230. # gcc 4.2.x optimizer is broken
  231. print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
  232. ccflags += ['-O0', '-g3']
  233. else:
  234. ccflags += ['-O3', '-g3']
  235. if env['profile']:
  236. # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
  237. ccflags += [
  238. '-fno-omit-frame-pointer',
  239. '-fno-optimize-sibling-calls',
  240. ]
  241. if env['machine'] == 'x86':
  242. ccflags += [
  243. '-m32',
  244. #'-march=pentium4',
  245. #'-mfpmath=sse',
  246. ]
  247. if platform != 'windows':
  248. # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
  249. # for -mincoming-stack-boundary=2. Still enable it on other
  250. # platforms for now, but we can't rely on it for cross platform
  251. # code. We have to use __attribute__((force_align_arg_pointer))
  252. # instead.
  253. ccflags += [
  254. '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
  255. ]
  256. if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2'):
  257. ccflags += [
  258. '-mstackrealign', # ensure stack is aligned
  259. ]
  260. if env['machine'] == 'x86_64':
  261. ccflags += ['-m64']
  262. # See also:
  263. # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  264. ccflags += [
  265. '-Wall',
  266. '-Wmissing-field-initializers',
  267. '-Wno-long-long',
  268. '-ffast-math',
  269. '-fmessage-length=0', # be nice to Eclipse
  270. ]
  271. cflags += [
  272. '-Wmissing-prototypes',
  273. '-std=gnu99',
  274. ]
  275. if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2'):
  276. ccflags += [
  277. '-Werror=pointer-arith',
  278. ]
  279. cflags += [
  280. '-Werror=declaration-after-statement',
  281. ]
  282. if msvc:
  283. # See also:
  284. # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
  285. # - cl /?
  286. if debug:
  287. ccflags += [
  288. '/Od', # disable optimizations
  289. '/Oi', # enable intrinsic functions
  290. '/Oy-', # disable frame pointer omission
  291. '/GL-', # disable whole program optimization
  292. ]
  293. else:
  294. ccflags += [
  295. '/O2', # optimize for speed
  296. '/GL', # enable whole program optimization
  297. ]
  298. ccflags += [
  299. '/fp:fast', # fast floating point
  300. '/W3', # warning level
  301. #'/Wp64', # enable 64 bit porting warnings
  302. ]
  303. if env['machine'] == 'x86':
  304. ccflags += [
  305. #'/arch:SSE2', # use the SSE2 instructions
  306. ]
  307. if platform == 'windows':
  308. ccflags += [
  309. # TODO
  310. ]
  311. if platform == 'winddk':
  312. ccflags += [
  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. ccflags += [
  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(CCFLAGS = ccflags)
  349. env.Append(CFLAGS = cflags)
  350. env.Append(CXXFLAGS = cxxflags)
  351. if env['platform'] == 'windows' and msvc:
  352. # Choose the appropriate MSVC CRT
  353. # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
  354. if env['debug']:
  355. env.Append(CCFLAGS = ['/MTd'])
  356. env.Append(SHCCFLAGS = ['/LDd'])
  357. else:
  358. env.Append(CCFLAGS = ['/MT'])
  359. env.Append(SHCCFLAGS = ['/LD'])
  360. # Assembler options
  361. if gcc:
  362. if env['machine'] == 'x86':
  363. env.Append(ASFLAGS = ['-m32'])
  364. if env['machine'] == 'x86_64':
  365. env.Append(ASFLAGS = ['-m64'])
  366. # Linker options
  367. linkflags = []
  368. shlinkflags = []
  369. if gcc:
  370. if env['machine'] == 'x86':
  371. linkflags += ['-m32']
  372. if env['machine'] == 'x86_64':
  373. linkflags += ['-m64']
  374. if env['platform'] not in ('darwin'):
  375. shlinkflags += [
  376. '-Wl,-Bsymbolic',
  377. ]
  378. # Handle circular dependencies in the libraries
  379. if env['platform'] in ('darwin'):
  380. pass
  381. else:
  382. env['_LIBFLAGS'] = '-Wl,--start-group ' + env['_LIBFLAGS'] + ' -Wl,--end-group'
  383. if msvc:
  384. if not env['debug']:
  385. # enable Link-time Code Generation
  386. linkflags += ['/LTCG']
  387. env.Append(ARFLAGS = ['/LTCG'])
  388. if platform == 'windows' and msvc:
  389. # See also:
  390. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  391. linkflags += [
  392. '/fixed:no',
  393. '/incremental:no',
  394. ]
  395. if platform == 'winddk':
  396. linkflags += [
  397. '/merge:_PAGE=PAGE',
  398. '/merge:_TEXT=.text',
  399. '/section:INIT,d',
  400. '/opt:ref',
  401. '/opt:icf',
  402. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  403. '/incremental:no',
  404. '/fullbuild',
  405. '/release',
  406. '/nodefaultlib',
  407. '/wx',
  408. '/debug',
  409. '/debugtype:cv',
  410. '/version:5.1',
  411. '/osversion:5.1',
  412. '/functionpadmin:5',
  413. '/safeseh',
  414. '/pdbcompress',
  415. '/stack:0x40000,0x1000',
  416. '/driver',
  417. '/align:0x80',
  418. '/subsystem:native,5.01',
  419. '/base:0x10000',
  420. '/entry:DrvEnableDriver',
  421. ]
  422. if env['debug'] or env['profile']:
  423. linkflags += [
  424. '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
  425. ]
  426. if platform == 'wince':
  427. linkflags += [
  428. '/nodefaultlib',
  429. #'/incremental:no',
  430. #'/fullbuild',
  431. '/entry:_DllMainCRTStartup',
  432. ]
  433. env.Append(LINKFLAGS = linkflags)
  434. env.Append(SHLINKFLAGS = shlinkflags)
  435. # Default libs
  436. env.Append(LIBS = [])
  437. # Custom builders and methods
  438. env.Tool('custom')
  439. createInstallMethods(env)
  440. # for debugging
  441. #print env.Dump()
  442. def exists(env):
  443. return 1