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.

SConstruct 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #######################################################################
  2. # Top-level SConstruct
  3. import os
  4. import os.path
  5. import sys
  6. #######################################################################
  7. # Configuration options
  8. #
  9. # For example, invoke scons as
  10. #
  11. # scons debug=1 dri=0 machine=x86
  12. #
  13. # to set configuration variables. Or you can write those options to a file
  14. # named config.py:
  15. #
  16. # # config.py
  17. # debug=1
  18. # dri=0
  19. # machine='x86'
  20. #
  21. # Invoke
  22. #
  23. # scons -h
  24. #
  25. # to get the full list of options. See scons manpage for more info.
  26. #
  27. platform_map = {
  28. 'linux2': 'linux',
  29. 'win32': 'winddk',
  30. }
  31. default_platform = platform_map.get(sys.platform, sys.platform)
  32. if default_platform in ('linux', 'freebsd', 'darwin'):
  33. default_statetrackers = 'mesa'
  34. default_drivers = 'softpipe,failover,i915simple,i965simple'
  35. default_winsys = 'xlib'
  36. default_dri = 'yes'
  37. elif default_platform in ('winddk',):
  38. default_statetrackers = 'none'
  39. default_drivers = 'softpipe,i915simple'
  40. default_winsys = 'none'
  41. default_dri = 'no'
  42. else:
  43. default_drivers = 'all'
  44. default_winsys = 'all'
  45. default_dri = 'no'
  46. # TODO: auto-detect defaults
  47. opts = Options('config.py')
  48. opts.Add(BoolOption('debug', 'build debug version', False))
  49. opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
  50. allowed_values=('generic', 'x86', 'x86-64')))
  51. opts.Add(EnumOption('platform', 'target platform', default_platform,
  52. allowed_values=('linux', 'cell', 'winddk')))
  53. opts.Add(ListOption('statetrackers', 'state_trackers to build', default_statetrackers,
  54. [
  55. 'mesa',
  56. ],
  57. ))
  58. opts.Add(ListOption('drivers', 'pipe drivers to build', default_drivers,
  59. [
  60. 'softpipe',
  61. 'failover',
  62. 'i915simple',
  63. 'i965simple',
  64. 'cell',
  65. ],
  66. ))
  67. opts.Add(ListOption('winsys', 'winsys drivers to build', default_winsys,
  68. [
  69. 'xlib',
  70. 'intel',
  71. ],
  72. ))
  73. opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
  74. opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
  75. env = Environment(
  76. options = opts,
  77. ENV = os.environ)
  78. Help(opts.GenerateHelpText(env))
  79. # for debugging
  80. #print env.Dump()
  81. # replicate options values in local variables
  82. debug = env['debug']
  83. dri = env['dri']
  84. llvm = env['llvm']
  85. machine = env['machine']
  86. platform = env['platform']
  87. # derived options
  88. x86 = machine == 'x86'
  89. gcc = platform in ('linux', 'freebsd', 'darwin')
  90. msvc = platform in ('win32', 'winddk')
  91. Export([
  92. 'debug',
  93. 'x86',
  94. 'dri',
  95. 'llvm',
  96. 'platform',
  97. 'gcc',
  98. 'msvc',
  99. ])
  100. #######################################################################
  101. # Environment setup
  102. #
  103. # TODO: put the compiler specific settings in separate files
  104. # TODO: auto-detect as much as possible
  105. if platform == 'winddk':
  106. import ntpath
  107. escape = env['ESCAPE']
  108. env.Tool('winddk', '.')
  109. if 'BASEDIR' in os.environ:
  110. WINDDK = os.environ['BASEDIR']
  111. else:
  112. WINDDK = "C:\\WINDDK\\3790.1830"
  113. # NOTE: We need this elaborate construct to get the absolute paths and
  114. # forward slashes to msvc unharmed when cross compiling from posix platforms
  115. #env.Append(CPPFLAGS = [
  116. # escape('/I' + ntpath.join(WINDDK, 'inc\\wxp')),
  117. # escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wxp')),
  118. # escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wdm\\wxp')),
  119. # escape('/I' + ntpath.join(WINDDK, 'inc\\crt')),
  120. #])
  121. env.Append(CFLAGS = '/W3')
  122. if debug:
  123. env.Append(CPPDEFINES = [
  124. ('DBG', '1'),
  125. ('DEBUG', '1'),
  126. ('_DEBUG', '1'),
  127. ])
  128. env.Append(CFLAGS = '/Od /Zi')
  129. env.Append(CXXFLAGS = '/Od /Zi')
  130. # Optimization flags
  131. if gcc:
  132. if debug:
  133. env.Append(CFLAGS = '-O0 -g3')
  134. env.Append(CXXFLAGS = '-O0 -g3')
  135. else:
  136. env.Append(CFLAGS = '-O3 -g3')
  137. env.Append(CXXFLAGS = '-O3 -g3')
  138. env.Append(CFLAGS = '-Wall -Wmissing-prototypes -Wno-long-long -ffast-math -pedantic')
  139. env.Append(CXXFLAGS = '-Wall -pedantic')
  140. # Be nice to Eclipse
  141. env.Append(CFLAGS = '-fmessage-length=0')
  142. env.Append(CXXFLAGS = '-fmessage-length=0')
  143. # Defines
  144. if debug:
  145. env.Append(CPPDEFINES = ['DEBUG'])
  146. else:
  147. env.Append(CPPDEFINES = ['NDEBUG'])
  148. # Includes
  149. env.Append(CPPPATH = [
  150. '#/include',
  151. '#/src/gallium/include',
  152. '#/src/gallium/auxiliary',
  153. '#/src/gallium/drivers',
  154. ])
  155. # x86 assembly
  156. if x86:
  157. env.Append(CPPDEFINES = [
  158. 'USE_X86_ASM',
  159. 'USE_MMX_ASM',
  160. 'USE_3DNOW_ASM',
  161. 'USE_SSE_ASM',
  162. ])
  163. if gcc:
  164. env.Append(CFLAGS = '-m32')
  165. env.Append(CXXFLAGS = '-m32')
  166. # Posix
  167. if platform in ('posix', 'linux', 'freebsd', 'darwin'):
  168. env.Append(CPPDEFINES = [
  169. '_POSIX_SOURCE',
  170. ('_POSIX_C_SOURCE', '199309L'),
  171. '_SVID_SOURCE',
  172. '_BSD_SOURCE',
  173. '_GNU_SOURCE',
  174. 'PTHREADS',
  175. 'HAVE_POSIX_MEMALIGN',
  176. ])
  177. env.Append(CPPPATH = ['/usr/X11R6/include'])
  178. env.Append(LIBPATH = ['/usr/X11R6/lib'])
  179. env.Append(LIBS = [
  180. 'm',
  181. 'pthread',
  182. 'expat',
  183. 'dl',
  184. ])
  185. # DRI
  186. if dri:
  187. env.ParseConfig('pkg-config --cflags --libs libdrm')
  188. env.Append(CPPDEFINES = [
  189. ('USE_EXTERNAL_DXTN_LIB', '1'),
  190. 'IN_DRI_DRIVER',
  191. 'GLX_DIRECT_RENDERING',
  192. 'GLX_INDIRECT_RENDERING',
  193. ])
  194. # LLVM
  195. if llvm:
  196. # See also http://www.scons.org/wiki/UsingPkgConfig
  197. env.ParseConfig('llvm-config --cflags --ldflags --libs')
  198. env.Append(CPPDEFINES = ['MESA_LLVM'])
  199. env.Append(CXXFLAGS = ['-Wno-long-long'])
  200. # libGL
  201. if platform not in ('winddk',):
  202. env.Append(LIBS = [
  203. 'X11',
  204. 'Xext',
  205. 'Xxf86vm',
  206. 'Xdamage',
  207. 'Xfixes',
  208. ])
  209. Export('env')
  210. #######################################################################
  211. # Convenience Library Builder
  212. # based on the stock StaticLibrary and SharedLibrary builders
  213. def createConvenienceLibBuilder(env):
  214. """This is a utility function that creates the ConvenienceLibrary
  215. Builder in an Environment if it is not there already.
  216. If it is already there, we return the existing one.
  217. """
  218. try:
  219. convenience_lib = env['BUILDERS']['ConvenienceLibrary']
  220. except KeyError:
  221. action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
  222. if env.Detect('ranlib'):
  223. ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
  224. action_list.append(ranlib_action)
  225. convenience_lib = Builder(action = action_list,
  226. emitter = '$LIBEMITTER',
  227. prefix = '$LIBPREFIX',
  228. suffix = '$LIBSUFFIX',
  229. src_suffix = '$SHOBJSUFFIX',
  230. src_builder = 'SharedObject')
  231. env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
  232. env['BUILDERS']['Library'] = convenience_lib
  233. return convenience_lib
  234. createConvenienceLibBuilder(env)
  235. #######################################################################
  236. # Invoke SConscripts
  237. # Put build output in a separate dir, which depends on the current configuration
  238. # See also http://www.scons.org/wiki/AdvancedBuildExample
  239. build_topdir = 'build'
  240. build_subdir = platform
  241. if dri:
  242. build_subdir += "-dri"
  243. if llvm:
  244. build_subdir += "-llvm"
  245. if x86:
  246. build_subdir += "-x86"
  247. if debug:
  248. build_subdir += "-debug"
  249. build_dir = os.path.join(build_topdir, build_subdir)
  250. # TODO: Build several variants at the same time?
  251. # http://www.scons.org/wiki/SimultaneousVariantBuilds
  252. SConscript(
  253. 'src/SConscript',
  254. build_dir = build_dir,
  255. duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
  256. )