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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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 platform in ['windows', 'darwin']:
  258. # Workaround http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216
  259. ccflags += ['-fno-common']
  260. if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2'):
  261. ccflags += [
  262. '-mstackrealign', # ensure stack is aligned
  263. ]
  264. if env['machine'] == 'x86_64':
  265. ccflags += ['-m64']
  266. if platform == 'darwin':
  267. ccflags += ['-fno-common']
  268. # See also:
  269. # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  270. ccflags += [
  271. '-Wall',
  272. '-Wno-long-long',
  273. '-ffast-math',
  274. '-fmessage-length=0', # be nice to Eclipse
  275. ]
  276. cflags += [
  277. '-Wmissing-prototypes',
  278. '-std=gnu99',
  279. ]
  280. if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.0'):
  281. ccflags += [
  282. '-Wmissing-field-initializers',
  283. ]
  284. if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2'):
  285. ccflags += [
  286. '-Werror=pointer-arith',
  287. ]
  288. cflags += [
  289. '-Werror=declaration-after-statement',
  290. ]
  291. if msvc:
  292. # See also:
  293. # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
  294. # - cl /?
  295. if debug:
  296. ccflags += [
  297. '/Od', # disable optimizations
  298. '/Oi', # enable intrinsic functions
  299. '/Oy-', # disable frame pointer omission
  300. '/GL-', # disable whole program optimization
  301. ]
  302. else:
  303. ccflags += [
  304. '/O2', # optimize for speed
  305. '/GL', # enable whole program optimization
  306. ]
  307. ccflags += [
  308. '/fp:fast', # fast floating point
  309. '/W3', # warning level
  310. #'/Wp64', # enable 64 bit porting warnings
  311. ]
  312. if env['machine'] == 'x86':
  313. ccflags += [
  314. #'/arch:SSE2', # use the SSE2 instructions
  315. ]
  316. if platform == 'windows':
  317. ccflags += [
  318. # TODO
  319. ]
  320. if platform == 'winddk':
  321. ccflags += [
  322. '/Zl', # omit default library name in .OBJ
  323. '/Zp8', # 8bytes struct member alignment
  324. '/Gy', # separate functions for linker
  325. '/Gm-', # disable minimal rebuild
  326. '/WX', # treat warnings as errors
  327. '/Gz', # __stdcall Calling convention
  328. '/GX-', # disable C++ EH
  329. '/GR-', # disable C++ RTTI
  330. '/GF', # enable read-only string pooling
  331. '/G6', # optimize for PPro, P-II, P-III
  332. '/Ze', # enable extensions
  333. '/Gi-', # disable incremental compilation
  334. '/QIfdiv-', # disable Pentium FDIV fix
  335. '/hotpatch', # prepares an image for hotpatching.
  336. #'/Z7', #enable old-style debug info
  337. ]
  338. if platform == 'wince':
  339. # See also C:\WINCE600\public\common\oak\misc\makefile.def
  340. ccflags += [
  341. '/Zl', # omit default library name in .OBJ
  342. '/GF', # enable read-only string pooling
  343. '/GR-', # disable C++ RTTI
  344. '/GS', # enable security checks
  345. # Allow disabling language conformance to maintain backward compat
  346. #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
  347. #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
  348. #'/wd4867',
  349. #'/wd4430',
  350. #'/MT',
  351. #'/U_MT',
  352. ]
  353. # Automatic pdb generation
  354. # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
  355. env.EnsureSConsVersion(0, 98, 0)
  356. env['PDB'] = '${TARGET.base}.pdb'
  357. env.Append(CCFLAGS = ccflags)
  358. env.Append(CFLAGS = cflags)
  359. env.Append(CXXFLAGS = cxxflags)
  360. if env['platform'] == 'windows' and msvc:
  361. # Choose the appropriate MSVC CRT
  362. # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
  363. if env['debug']:
  364. env.Append(CCFLAGS = ['/MTd'])
  365. env.Append(SHCCFLAGS = ['/LDd'])
  366. else:
  367. env.Append(CCFLAGS = ['/MT'])
  368. env.Append(SHCCFLAGS = ['/LD'])
  369. # Assembler options
  370. if gcc:
  371. if env['machine'] == 'x86':
  372. env.Append(ASFLAGS = ['-m32'])
  373. if env['machine'] == 'x86_64':
  374. env.Append(ASFLAGS = ['-m64'])
  375. # Linker options
  376. linkflags = []
  377. shlinkflags = []
  378. if gcc:
  379. if env['machine'] == 'x86':
  380. linkflags += ['-m32']
  381. if env['machine'] == 'x86_64':
  382. linkflags += ['-m64']
  383. if env['platform'] not in ('darwin'):
  384. shlinkflags += [
  385. '-Wl,-Bsymbolic',
  386. ]
  387. # Handle circular dependencies in the libraries
  388. if env['platform'] in ('darwin'):
  389. pass
  390. else:
  391. env['_LIBFLAGS'] = '-Wl,--start-group ' + env['_LIBFLAGS'] + ' -Wl,--end-group'
  392. if msvc:
  393. if not env['debug']:
  394. # enable Link-time Code Generation
  395. linkflags += ['/LTCG']
  396. env.Append(ARFLAGS = ['/LTCG'])
  397. if platform == 'windows' and msvc:
  398. # See also:
  399. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  400. linkflags += [
  401. '/fixed:no',
  402. '/incremental:no',
  403. ]
  404. if platform == 'winddk':
  405. linkflags += [
  406. '/merge:_PAGE=PAGE',
  407. '/merge:_TEXT=.text',
  408. '/section:INIT,d',
  409. '/opt:ref',
  410. '/opt:icf',
  411. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  412. '/incremental:no',
  413. '/fullbuild',
  414. '/release',
  415. '/nodefaultlib',
  416. '/wx',
  417. '/debug',
  418. '/debugtype:cv',
  419. '/version:5.1',
  420. '/osversion:5.1',
  421. '/functionpadmin:5',
  422. '/safeseh',
  423. '/pdbcompress',
  424. '/stack:0x40000,0x1000',
  425. '/driver',
  426. '/align:0x80',
  427. '/subsystem:native,5.01',
  428. '/base:0x10000',
  429. '/entry:DrvEnableDriver',
  430. ]
  431. if env['debug'] or env['profile']:
  432. linkflags += [
  433. '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
  434. ]
  435. if platform == 'wince':
  436. linkflags += [
  437. '/nodefaultlib',
  438. #'/incremental:no',
  439. #'/fullbuild',
  440. '/entry:_DllMainCRTStartup',
  441. ]
  442. env.Append(LINKFLAGS = linkflags)
  443. env.Append(SHLINKFLAGS = shlinkflags)
  444. # Default libs
  445. env.Append(LIBS = [])
  446. # Load LLVM
  447. if env['llvm']:
  448. env.Tool('llvm')
  449. # Custom builders and methods
  450. env.Tool('custom')
  451. createInstallMethods(env)
  452. # for debugging
  453. #print env.Dump()
  454. def exists(env):
  455. return 1