Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

gallium.py 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. """gallium
  2. Frontend-tool for Gallium3D architecture.
  3. """
  4. #
  5. # Copyright 2008 VMware, Inc.
  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 VMWARE 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 platform as host_platform
  34. import sys
  35. import tempfile
  36. import SCons.Action
  37. import SCons.Builder
  38. import SCons.Scanner
  39. def symlink(target, source, env):
  40. target = str(target[0])
  41. source = str(source[0])
  42. if os.path.islink(target) or os.path.exists(target):
  43. os.remove(target)
  44. os.symlink(os.path.basename(source), target)
  45. def install(env, source, subdir):
  46. target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build_dir'], subdir)
  47. return env.Install(target_dir, source)
  48. def install_program(env, source):
  49. return install(env, source, 'bin')
  50. def install_shared_library(env, sources, version = ()):
  51. targets = []
  52. install_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build_dir'])
  53. version = tuple(map(str, version))
  54. if env['SHLIBSUFFIX'] == '.dll':
  55. dlls = env.FindIxes(sources, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  56. targets += install(env, dlls, 'bin')
  57. libs = env.FindIxes(sources, 'LIBPREFIX', 'LIBSUFFIX')
  58. targets += install(env, libs, 'lib')
  59. else:
  60. for source in sources:
  61. target_dir = os.path.join(install_dir, 'lib')
  62. target_name = '.'.join((str(source),) + version)
  63. last = env.InstallAs(os.path.join(target_dir, target_name), source)
  64. targets += last
  65. while len(version):
  66. version = version[:-1]
  67. target_name = '.'.join((str(source),) + version)
  68. action = SCons.Action.Action(symlink, " Symlinking $TARGET ...")
  69. last = env.Command(os.path.join(target_dir, target_name), last, action)
  70. targets += last
  71. return targets
  72. def msvc2013_compat(env):
  73. if env['gcc']:
  74. env.Append(CCFLAGS = [
  75. '-Werror=vla',
  76. '-Werror=pointer-arith',
  77. ])
  78. def unit_test(env, test_name, program_target, args=None):
  79. env.InstallProgram(program_target)
  80. cmd = [program_target[0].abspath]
  81. if args is not None:
  82. cmd += args
  83. cmd = ' '.join(cmd)
  84. # http://www.scons.org/wiki/UnitTests
  85. action = SCons.Action.Action(cmd, " Running $SOURCE ...")
  86. alias = env.Alias(test_name, program_target, action)
  87. env.AlwaysBuild(alias)
  88. env.Depends('check', alias)
  89. def num_jobs():
  90. try:
  91. return int(os.environ['NUMBER_OF_PROCESSORS'])
  92. except (ValueError, KeyError):
  93. pass
  94. try:
  95. return os.sysconf('SC_NPROCESSORS_ONLN')
  96. except (ValueError, OSError, AttributeError):
  97. pass
  98. try:
  99. return int(os.popen2("sysctl -n hw.ncpu")[1].read())
  100. except ValueError:
  101. pass
  102. return 1
  103. def check_cc(env, cc, expr, cpp_opt = '-E'):
  104. # Invoke C-preprocessor to determine whether the specified expression is
  105. # true or not.
  106. sys.stdout.write('Checking for %s ... ' % cc)
  107. source = tempfile.NamedTemporaryFile(suffix='.c', delete=False)
  108. source.write('#if !(%s)\n#error\n#endif\n' % expr)
  109. source.close()
  110. pipe = SCons.Action._subproc(env, [env['CC'], cpp_opt, source.name],
  111. stdin = 'devnull',
  112. stderr = 'devnull',
  113. stdout = 'devnull')
  114. result = pipe.wait() == 0
  115. os.unlink(source.name)
  116. sys.stdout.write(' %s\n' % ['no', 'yes'][int(bool(result))])
  117. return result
  118. def check_prog(env, prog):
  119. """Check whether this program exists."""
  120. sys.stdout.write('Checking for %s ... ' % prog)
  121. result = env.Detect(prog)
  122. sys.stdout.write(' %s\n' % ['no', 'yes'][int(bool(result))])
  123. return result
  124. def generate(env):
  125. """Common environment generation code"""
  126. # Tell tools which machine to compile for
  127. env['TARGET_ARCH'] = env['machine']
  128. env['MSVS_ARCH'] = env['machine']
  129. # Toolchain
  130. platform = env['platform']
  131. env.Tool(env['toolchain'])
  132. # Allow override compiler and specify additional flags from environment
  133. if os.environ.has_key('CC'):
  134. env['CC'] = os.environ['CC']
  135. if os.environ.has_key('CFLAGS'):
  136. env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
  137. if os.environ.has_key('CXX'):
  138. env['CXX'] = os.environ['CXX']
  139. if os.environ.has_key('CXXFLAGS'):
  140. env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
  141. if os.environ.has_key('LDFLAGS'):
  142. env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
  143. # Detect gcc/clang not by executable name, but through pre-defined macros
  144. # as autoconf does, to avoid drawing wrong conclusions when using tools
  145. # that overrice CC/CXX like scan-build.
  146. env['gcc_compat'] = 0
  147. env['clang'] = 0
  148. env['msvc'] = 0
  149. if host_platform.system() == 'Windows':
  150. env['msvc'] = check_cc(env, 'MSVC', 'defined(_MSC_VER)', '/E')
  151. if not env['msvc']:
  152. env['gcc_compat'] = check_cc(env, 'GCC', 'defined(__GNUC__)')
  153. env['clang'] = check_cc(env, 'Clang', '__clang__')
  154. env['gcc'] = env['gcc_compat'] and not env['clang']
  155. env['suncc'] = env['platform'] == 'sunos' and os.path.basename(env['CC']) == 'cc'
  156. env['icc'] = 'icc' == os.path.basename(env['CC'])
  157. if env['msvc'] and env['toolchain'] == 'default' and env['machine'] == 'x86_64':
  158. # MSVC x64 support is broken in earlier versions of scons
  159. env.EnsurePythonVersion(2, 0)
  160. # shortcuts
  161. machine = env['machine']
  162. platform = env['platform']
  163. x86 = env['machine'] == 'x86'
  164. ppc = env['machine'] == 'ppc'
  165. gcc_compat = env['gcc_compat']
  166. msvc = env['msvc']
  167. suncc = env['suncc']
  168. icc = env['icc']
  169. # Determine whether we are cross compiling; in particular, whether we need
  170. # to compile code generators with a different compiler as the target code.
  171. hosthost_platform = host_platform.system().lower()
  172. if hosthost_platform.startswith('cygwin'):
  173. hosthost_platform = 'cygwin'
  174. host_machine = os.environ.get('PROCESSOR_ARCHITEW6432', os.environ.get('PROCESSOR_ARCHITECTURE', host_platform.machine()))
  175. host_machine = {
  176. 'x86': 'x86',
  177. 'i386': 'x86',
  178. 'i486': 'x86',
  179. 'i586': 'x86',
  180. 'i686': 'x86',
  181. 'ppc' : 'ppc',
  182. 'AMD64': 'x86_64',
  183. 'x86_64': 'x86_64',
  184. }.get(host_machine, 'generic')
  185. env['crosscompile'] = platform != hosthost_platform
  186. if machine == 'x86_64' and host_machine != 'x86_64':
  187. env['crosscompile'] = True
  188. env['hostonly'] = False
  189. # Backwards compatability with the debug= profile= options
  190. if env['build'] == 'debug':
  191. if not env['debug']:
  192. print 'scons: warning: debug option is deprecated and will be removed eventually; use instead'
  193. print
  194. print ' scons build=release'
  195. print
  196. env['build'] = 'release'
  197. if env['profile']:
  198. print 'scons: warning: profile option is deprecated and will be removed eventually; use instead'
  199. print
  200. print ' scons build=profile'
  201. print
  202. env['build'] = 'profile'
  203. if False:
  204. # Enforce SConscripts to use the new build variable
  205. env.popitem('debug')
  206. env.popitem('profile')
  207. else:
  208. # Backwards portability with older sconscripts
  209. if env['build'] in ('debug', 'checked'):
  210. env['debug'] = True
  211. env['profile'] = False
  212. if env['build'] == 'profile':
  213. env['debug'] = False
  214. env['profile'] = True
  215. if env['build'] in ('release', 'opt'):
  216. env['debug'] = False
  217. env['profile'] = False
  218. # Put build output in a separate dir, which depends on the current
  219. # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
  220. build_topdir = 'build'
  221. build_subdir = env['platform']
  222. if env['embedded']:
  223. build_subdir = 'embedded-' + build_subdir
  224. if env['machine'] != 'generic':
  225. build_subdir += '-' + env['machine']
  226. if env['build'] != 'release':
  227. build_subdir += '-' + env['build']
  228. build_dir = os.path.join(build_topdir, build_subdir)
  229. # Place the .sconsign file in the build dir too, to avoid issues with
  230. # different scons versions building the same source file
  231. env['build_dir'] = build_dir
  232. env.SConsignFile(os.path.join(build_dir, '.sconsign'))
  233. if 'SCONS_CACHE_DIR' in os.environ:
  234. print 'scons: Using build cache in %s.' % (os.environ['SCONS_CACHE_DIR'],)
  235. env.CacheDir(os.environ['SCONS_CACHE_DIR'])
  236. env['CONFIGUREDIR'] = os.path.join(build_dir, 'conf')
  237. env['CONFIGURELOG'] = os.path.join(os.path.abspath(build_dir), 'config.log')
  238. # Parallel build
  239. if env.GetOption('num_jobs') <= 1:
  240. env.SetOption('num_jobs', num_jobs())
  241. env.Decider('MD5-timestamp')
  242. env.SetOption('max_drift', 60)
  243. # C preprocessor options
  244. cppdefines = []
  245. cppdefines += [
  246. '__STDC_LIMIT_MACROS',
  247. '__STDC_CONSTANT_MACROS',
  248. 'HAVE_NO_AUTOCONF',
  249. ]
  250. if env['build'] in ('debug', 'checked'):
  251. cppdefines += ['DEBUG']
  252. else:
  253. cppdefines += ['NDEBUG']
  254. if env['build'] == 'profile':
  255. cppdefines += ['PROFILE']
  256. if env['build'] in ('opt', 'profile'):
  257. cppdefines += ['VMX86_STATS']
  258. if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
  259. cppdefines += [
  260. '_POSIX_SOURCE',
  261. ('_POSIX_C_SOURCE', '199309L'),
  262. '_SVID_SOURCE',
  263. '_BSD_SOURCE',
  264. '_GNU_SOURCE',
  265. '_DEFAULT_SOURCE',
  266. ]
  267. if env['platform'] == 'darwin':
  268. cppdefines += [
  269. '_DARWIN_C_SOURCE',
  270. 'GLX_USE_APPLEGL',
  271. 'GLX_DIRECT_RENDERING',
  272. ]
  273. else:
  274. cppdefines += [
  275. 'GLX_DIRECT_RENDERING',
  276. 'GLX_INDIRECT_RENDERING',
  277. ]
  278. if env['platform'] in ('linux', 'freebsd'):
  279. cppdefines += ['HAVE_ALIAS']
  280. else:
  281. cppdefines += ['GLX_ALIAS_UNSUPPORTED']
  282. if env['platform'] in ('linux', 'darwin'):
  283. cppdefines += ['HAVE_XLOCALE_H']
  284. if platform == 'windows':
  285. cppdefines += [
  286. 'WIN32',
  287. '_WINDOWS',
  288. #'_UNICODE',
  289. #'UNICODE',
  290. # http://msdn.microsoft.com/en-us/library/aa383745.aspx
  291. ('_WIN32_WINNT', '0x0601'),
  292. ('WINVER', '0x0601'),
  293. ]
  294. if gcc_compat:
  295. cppdefines += [('__MSVCRT_VERSION__', '0x0700')]
  296. if msvc:
  297. cppdefines += [
  298. 'VC_EXTRALEAN',
  299. '_USE_MATH_DEFINES',
  300. '_CRT_SECURE_NO_WARNINGS',
  301. '_CRT_SECURE_NO_DEPRECATE',
  302. '_SCL_SECURE_NO_WARNINGS',
  303. '_SCL_SECURE_NO_DEPRECATE',
  304. '_ALLOW_KEYWORD_MACROS',
  305. '_HAS_EXCEPTIONS=0', # Tell C++ STL to not use exceptions
  306. ]
  307. if env['build'] in ('debug', 'checked'):
  308. cppdefines += ['_DEBUG']
  309. if platform == 'windows':
  310. cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
  311. if env['embedded']:
  312. cppdefines += ['PIPE_SUBSYSTEM_EMBEDDED']
  313. if env['texture_float']:
  314. print 'warning: Floating-point textures enabled.'
  315. print 'warning: Please consult docs/patents.txt with your lawyer before building Mesa.'
  316. cppdefines += ['TEXTURE_FLOAT_ENABLED']
  317. env.Append(CPPDEFINES = cppdefines)
  318. # C compiler options
  319. cflags = [] # C
  320. cxxflags = [] # C++
  321. ccflags = [] # C & C++
  322. if gcc_compat:
  323. if env['build'] == 'debug':
  324. ccflags += ['-O0']
  325. else:
  326. ccflags += ['-O3']
  327. if env['gcc']:
  328. # gcc's builtin memcmp is slower than glibc's
  329. # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
  330. ccflags += ['-fno-builtin-memcmp']
  331. # Work around aliasing bugs - developers should comment this out
  332. ccflags += ['-fno-strict-aliasing']
  333. ccflags += ['-g']
  334. if env['build'] in ('checked', 'profile') or env['asan']:
  335. # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
  336. ccflags += [
  337. '-fno-omit-frame-pointer',
  338. ]
  339. if env['gcc']:
  340. ccflags += ['-fno-optimize-sibling-calls']
  341. if env['machine'] == 'x86':
  342. ccflags += [
  343. '-m32',
  344. #'-march=pentium4',
  345. ]
  346. if platform != 'haiku':
  347. # NOTE: We need to ensure stack is realigned given that we
  348. # produce shared objects, and have no control over the stack
  349. # alignment policy of the application. Therefore we need
  350. # -mstackrealign ore -mincoming-stack-boundary=2.
  351. #
  352. # XXX: We could have SSE without -mstackrealign if we always used
  353. # __attribute__((force_align_arg_pointer)), but that's not
  354. # always the case.
  355. ccflags += [
  356. '-mstackrealign', # ensure stack is aligned
  357. '-msse', '-msse2', # enable SIMD intrinsics
  358. '-mfpmath=sse', # generate SSE floating-point arithmetic
  359. ]
  360. if platform in ['windows', 'darwin']:
  361. # Workaround http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216
  362. ccflags += ['-fno-common']
  363. if platform in ['haiku']:
  364. # Make optimizations compatible with Pentium or higher on Haiku
  365. ccflags += [
  366. '-mstackrealign', # ensure stack is aligned
  367. '-march=i586', # Haiku target is Pentium
  368. '-mtune=i686' # use i686 where we can
  369. ]
  370. if env['machine'] == 'x86_64':
  371. ccflags += ['-m64']
  372. if platform == 'darwin':
  373. ccflags += ['-fno-common']
  374. if env['platform'] not in ('cygwin', 'haiku', 'windows'):
  375. ccflags += ['-fvisibility=hidden']
  376. # See also:
  377. # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  378. ccflags += [
  379. '-Wall',
  380. '-Wno-long-long',
  381. '-fmessage-length=0', # be nice to Eclipse
  382. ]
  383. cflags += [
  384. '-Wmissing-prototypes',
  385. '-std=gnu99',
  386. ]
  387. if icc:
  388. cflags += [
  389. '-std=gnu99',
  390. ]
  391. if msvc:
  392. # See also:
  393. # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
  394. # - cl /?
  395. if env['build'] == 'debug':
  396. ccflags += [
  397. '/Od', # disable optimizations
  398. '/Oi', # enable intrinsic functions
  399. ]
  400. else:
  401. ccflags += [
  402. '/O2', # optimize for speed
  403. ]
  404. if env['build'] in ('release', 'opt'):
  405. if not env['clang']:
  406. ccflags += [
  407. '/GL', # enable whole program optimization
  408. ]
  409. else:
  410. ccflags += [
  411. '/Oy-', # disable frame pointer omission
  412. ]
  413. ccflags += [
  414. '/W3', # warning level
  415. '/wd4018', # signed/unsigned mismatch
  416. '/wd4056', # overflow in floating-point constant arithmetic
  417. '/wd4244', # conversion from 'type1' to 'type2', possible loss of data
  418. '/wd4267', # 'var' : conversion from 'size_t' to 'type', possible loss of data
  419. '/wd4305', # truncation from 'type1' to 'type2'
  420. '/wd4351', # new behavior: elements of array 'array' will be default initialized
  421. '/wd4756', # overflow in constant arithmetic
  422. '/wd4800', # forcing value to bool 'true' or 'false' (performance warning)
  423. '/wd4996', # disable deprecated POSIX name warnings
  424. ]
  425. if env['clang']:
  426. ccflags += [
  427. '-Wno-microsoft-enum-value', # enumerator value is not representable in underlying type 'int'
  428. ]
  429. if env['machine'] == 'x86':
  430. ccflags += [
  431. '/arch:SSE2', # use the SSE2 instructions (default since MSVC 2012)
  432. ]
  433. if platform == 'windows':
  434. ccflags += [
  435. # TODO
  436. ]
  437. # Automatic pdb generation
  438. # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
  439. env.EnsureSConsVersion(0, 98, 0)
  440. env['PDB'] = '${TARGET.base}.pdb'
  441. env.Append(CCFLAGS = ccflags)
  442. env.Append(CFLAGS = cflags)
  443. env.Append(CXXFLAGS = cxxflags)
  444. if env['platform'] == 'windows' and msvc:
  445. # Choose the appropriate MSVC CRT
  446. # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
  447. if env['build'] in ('debug', 'checked'):
  448. env.Append(CCFLAGS = ['/MTd'])
  449. env.Append(SHCCFLAGS = ['/LDd'])
  450. else:
  451. env.Append(CCFLAGS = ['/MT'])
  452. env.Append(SHCCFLAGS = ['/LD'])
  453. # Static code analysis
  454. if env['analyze']:
  455. if env['msvc']:
  456. # http://msdn.microsoft.com/en-us/library/ms173498.aspx
  457. env.Append(CCFLAGS = [
  458. '/analyze',
  459. #'/analyze:log', '${TARGET.base}.xml',
  460. '/wd28251', # Inconsistent annotation for function
  461. ])
  462. if env['clang']:
  463. # scan-build will produce more comprehensive output
  464. env.Append(CCFLAGS = ['--analyze'])
  465. # https://github.com/google/sanitizers/wiki/AddressSanitizer
  466. if env['asan']:
  467. if gcc_compat:
  468. env.Append(CCFLAGS = [
  469. '-fsanitize=address',
  470. ])
  471. env.Append(LINKFLAGS = [
  472. '-fsanitize=address',
  473. ])
  474. # Assembler options
  475. if gcc_compat:
  476. if env['machine'] == 'x86':
  477. env.Append(ASFLAGS = ['-m32'])
  478. if env['machine'] == 'x86_64':
  479. env.Append(ASFLAGS = ['-m64'])
  480. # Linker options
  481. linkflags = []
  482. shlinkflags = []
  483. if gcc_compat:
  484. if env['machine'] == 'x86':
  485. linkflags += ['-m32']
  486. if env['machine'] == 'x86_64':
  487. linkflags += ['-m64']
  488. if env['platform'] not in ('darwin'):
  489. shlinkflags += [
  490. '-Wl,-Bsymbolic',
  491. ]
  492. # Handle circular dependencies in the libraries
  493. if env['platform'] in ('darwin'):
  494. pass
  495. else:
  496. env['_LIBFLAGS'] = '-Wl,--start-group ' + env['_LIBFLAGS'] + ' -Wl,--end-group'
  497. if env['platform'] == 'windows':
  498. linkflags += [
  499. '-Wl,--nxcompat', # DEP
  500. '-Wl,--dynamicbase', # ASLR
  501. ]
  502. # Avoid depending on gcc runtime DLLs
  503. linkflags += ['-static-libgcc']
  504. if 'w64' in env['CC'].split('-'):
  505. linkflags += ['-static-libstdc++']
  506. # Handle the @xx symbol munging of DLL exports
  507. shlinkflags += ['-Wl,--enable-stdcall-fixup']
  508. #shlinkflags += ['-Wl,--kill-at']
  509. if msvc:
  510. if env['build'] in ('release', 'opt') and not env['clang']:
  511. # enable Link-time Code Generation
  512. linkflags += ['/LTCG']
  513. env.Append(ARFLAGS = ['/LTCG'])
  514. if platform == 'windows' and msvc:
  515. # See also:
  516. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  517. linkflags += [
  518. '/fixed:no',
  519. '/incremental:no',
  520. '/dynamicbase', # ASLR
  521. '/nxcompat', # DEP
  522. ]
  523. env.Append(LINKFLAGS = linkflags)
  524. env.Append(SHLINKFLAGS = shlinkflags)
  525. # We have C++ in several libraries, so always link with the C++ compiler
  526. if gcc_compat:
  527. env['LINK'] = env['CXX']
  528. # Default libs
  529. libs = []
  530. if env['platform'] in ('darwin', 'freebsd', 'linux', 'posix', 'sunos'):
  531. libs += ['m', 'pthread', 'dl']
  532. if env['platform'] in ('linux',):
  533. libs += ['rt']
  534. if env['platform'] in ('haiku'):
  535. libs += ['root', 'be', 'network', 'translation']
  536. env.Append(LIBS = libs)
  537. # OpenMP
  538. if env['openmp']:
  539. if env['msvc']:
  540. env.Append(CCFLAGS = ['/openmp'])
  541. # When building openmp release VS2008 link.exe crashes with LNK1103 error.
  542. # Workaround: overwrite PDB flags with empty value as it isn't required anyways
  543. if env['build'] == 'release':
  544. env['PDB'] = ''
  545. if env['gcc']:
  546. env.Append(CCFLAGS = ['-fopenmp'])
  547. env.Append(LIBS = ['gomp'])
  548. # Load tools
  549. env.Tool('lex')
  550. if env['msvc']:
  551. env.Append(LEXFLAGS = [
  552. # Force flex to use const keyword in prototypes, as relies on
  553. # __cplusplus or __STDC__ macro to determine whether it's safe to
  554. # use const keyword, but MSVC never defines __STDC__ unless we
  555. # disable all MSVC extensions.
  556. '-DYY_USE_CONST=',
  557. ])
  558. # Flex relies on __STDC_VERSION__>=199901L to decide when to include
  559. # C99 inttypes.h. We always have inttypes.h available with MSVC
  560. # (either the one bundled with MSVC 2013, or the one we bundle
  561. # ourselves), but we can't just define __STDC_VERSION__ without
  562. # breaking stuff, as MSVC doesn't fully support C99. There's also no
  563. # way to premptively include stdint.
  564. env.Append(CCFLAGS = ['-FIinttypes.h'])
  565. if host_platform.system() == 'Windows':
  566. # Prefer winflexbison binaries, as not only they are easier to install
  567. # (no additional dependencies), but also better Windows support.
  568. if check_prog(env, 'win_flex'):
  569. env["LEX"] = 'win_flex'
  570. env.Append(LEXFLAGS = [
  571. # windows compatibility (uses <io.h> instead of <unistd.h> and
  572. # _isatty, _fileno functions)
  573. '--wincompat'
  574. ])
  575. env.Tool('yacc')
  576. if host_platform.system() == 'Windows':
  577. if check_prog(env, 'win_bison'):
  578. env["YACC"] = 'win_bison'
  579. if env['llvm']:
  580. env.Tool('llvm')
  581. # Custom builders and methods
  582. env.Tool('custom')
  583. env.AddMethod(install_program, 'InstallProgram')
  584. env.AddMethod(install_shared_library, 'InstallSharedLibrary')
  585. env.AddMethod(msvc2013_compat, 'MSVC2013Compat')
  586. env.AddMethod(unit_test, 'UnitTest')
  587. env.PkgCheckModules('X11', ['x11', 'xext', 'xdamage', 'xfixes', 'glproto >= 1.4.13'])
  588. env.PkgCheckModules('XCB', ['x11-xcb', 'xcb-glx >= 1.8.1', 'xcb-dri2 >= 1.8'])
  589. env.PkgCheckModules('XF86VIDMODE', ['xxf86vm'])
  590. env.PkgCheckModules('DRM', ['libdrm >= 2.4.38'])
  591. env.PkgCheckModules('UDEV', ['libudev >= 151'])
  592. if env['x11']:
  593. env.Append(CPPPATH = env['X11_CPPPATH'])
  594. env['dri'] = env['x11'] and env['drm']
  595. # for debugging
  596. #print env.Dump()
  597. def exists(env):
  598. return 1