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