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