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 25KB

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