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