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 | |
| 31 | # TODO: auto-detect defaults |
| 32 | opts = Options('config.py') |
| 33 | opts.Add(BoolOption('debug', 'build debug version', False)) |
| 34 | opts.Add(BoolOption('dri', 'build dri drivers', False)) |
| 35 | opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86', |
| 36 | allowed_values=('generic', 'x86', 'x86-64'))) |
| 37 | |
José Fonseca | 81b6a80 | 2008-02-06 14:36:50 +0900 | [diff] [blame] | 38 | env = Environment( |
| 39 | options = opts, |
| 40 | ENV = os.environ) |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 41 | Help(opts.GenerateHelpText(env)) |
| 42 | |
| 43 | # for debugging |
| 44 | #print env.Dump() |
| 45 | |
José Fonseca | f4192cb4 | 2008-01-31 14:21:49 +0900 | [diff] [blame] | 46 | if 0: |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 47 | # platform will be typically 'posix' or 'win32' |
| 48 | platform = env['PLATFORM'] |
| 49 | else: |
| 50 | # platform will be one of 'linux', 'freebsd', 'win32', 'darwin', etc. |
| 51 | platform = sys.platform |
| 52 | if platform == 'linux2': |
| 53 | platform = 'linux' |
| 54 | |
| 55 | # replicate options values in local variables |
| 56 | debug = env['debug'] |
| 57 | dri = env['dri'] |
| 58 | machine = env['machine'] |
| 59 | |
| 60 | # derived options |
| 61 | x86 = machine == 'x86' |
José Fonseca | f4192cb4 | 2008-01-31 14:21:49 +0900 | [diff] [blame] | 62 | gcc = platform in ('posix', 'linux', 'freebsd', 'darwin') |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 63 | msvc = platform == 'win32' |
| 64 | |
| 65 | Export([ |
| 66 | 'debug', |
| 67 | 'x86', |
| 68 | 'dri', |
| 69 | 'platform', |
| 70 | 'gcc', |
| 71 | 'msvc', |
| 72 | ]) |
| 73 | |
| 74 | |
| 75 | ####################################################################### |
| 76 | # Environment setup |
| 77 | # |
| 78 | # TODO: put the compiler specific settings in seperate files |
| 79 | # TODO: auto-detect as much as possible |
| 80 | |
| 81 | |
| 82 | # Optimization flags |
| 83 | if gcc: |
| 84 | if debug: |
| 85 | env.Append(CFLAGS = '-O0 -g3') |
| 86 | env.Append(CXXFLAGS = '-O0 -g3') |
| 87 | else: |
| 88 | env.Append(CFLAGS = '-O3 -g3') |
| 89 | env.Append(CXXFLAGS = '-O3 -g3') |
| 90 | |
| 91 | env.Append(CFLAGS = '-Wall -Wmissing-prototypes -std=c99 -ffast-math -pedantic') |
| 92 | env.Append(CXXFLAGS = '-Wall -pedantic') |
| 93 | |
| 94 | # Be nice to Eclipse |
| 95 | env.Append(CFLAGS = '-fmessage-length=0') |
| 96 | env.Append(CXXFLAGS = '-fmessage-length=0') |
| 97 | |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 98 | |
José Fonseca | 0013796 | 2008-02-07 19:59:17 +0900 | [diff] [blame] | 99 | # Defines |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 100 | if debug: |
| 101 | env.Append(CPPDEFINES = ['DEBUG']) |
| 102 | else: |
| 103 | env.Append(CPPDEFINES = ['NDEBUG']) |
| 104 | |
| 105 | |
| 106 | # Includes |
| 107 | env.Append(CPPPATH = [ |
| 108 | '#/include', |
| 109 | '#/src/mesa', |
| 110 | '#/src/mesa/main', |
José Fonseca | 33ceb67 | 2008-02-18 10:52:44 +0000 | [diff] [blame] | 111 | '#/src/gallium/include', |
| 112 | '#/src/gallium/auxiliary', |
| 113 | '#/src/gallium/drivers', |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 114 | ]) |
| 115 | |
| 116 | |
| 117 | # x86 assembly |
| 118 | if x86: |
| 119 | env.Append(CPPDEFINES = [ |
| 120 | 'USE_X86_ASM', |
| 121 | 'USE_MMX_ASM', |
| 122 | 'USE_3DNOW_ASM', |
| 123 | 'USE_SSE_ASM', |
| 124 | ]) |
| 125 | if gcc: |
| 126 | env.Append(CFLAGS = '-m32') |
| 127 | env.Append(CXXFLAGS = '-m32') |
| 128 | |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 129 | |
José Fonseca | 0013796 | 2008-02-07 19:59:17 +0900 | [diff] [blame] | 130 | # Posix |
| 131 | if platform in ('posix', 'linux', 'freebsd', 'darwin'): |
| 132 | env.Append(CPPDEFINES = [ |
| 133 | '_POSIX_SOURCE', |
| 134 | ('_POSIX_C_SOURCE', '199309L'), |
| 135 | '_SVID_SOURCE', |
| 136 | '_BSD_SOURCE', |
| 137 | '_GNU_SOURCE', |
| 138 | |
| 139 | 'PTHREADS', |
| 140 | 'HAVE_POSIX_MEMALIGN', |
| 141 | ]) |
| 142 | env.Append(CPPPATH = ['/usr/X11R6/include']) |
| 143 | env.Append(LIBPATH = ['/usr/X11R6/lib']) |
| 144 | env.Append(LIBS = [ |
| 145 | 'm', |
| 146 | 'pthread', |
| 147 | 'expat', |
| 148 | 'dl', |
| 149 | ]) |
| 150 | |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 151 | |
| 152 | # DRI |
| 153 | if dri: |
| 154 | env.ParseConfig('pkg-config --cflags --libs libdrm') |
| 155 | env.Append(CPPDEFINES = [ |
| 156 | ('USE_EXTERNAL_DXTN_LIB', '1'), |
| 157 | 'IN_DRI_DRIVER', |
| 158 | 'GLX_DIRECT_RENDERING', |
| 159 | 'GLX_INDIRECT_RENDERING', |
| 160 | ]) |
| 161 | |
| 162 | # libGL |
| 163 | if 1: |
| 164 | env.Append(LIBS = [ |
| 165 | 'X11', |
| 166 | 'Xext', |
| 167 | 'Xxf86vm', |
| 168 | 'Xdamage', |
| 169 | 'Xfixes', |
| 170 | ]) |
| 171 | |
| 172 | Export('env') |
| 173 | |
| 174 | |
| 175 | ####################################################################### |
| 176 | # Convenience Library Builder |
| 177 | # based on the stock StaticLibrary and SharedLibrary builders |
| 178 | |
| 179 | def createConvenienceLibBuilder(env): |
| 180 | """This is a utility function that creates the ConvenienceLibrary |
| 181 | Builder in an Environment if it is not there already. |
| 182 | |
| 183 | If it is already there, we return the existing one. |
| 184 | """ |
| 185 | |
| 186 | try: |
| 187 | convenience_lib = env['BUILDERS']['ConvenienceLibrary'] |
| 188 | except KeyError: |
| 189 | action_list = [ Action("$ARCOM", "$ARCOMSTR") ] |
| 190 | if env.Detect('ranlib'): |
| 191 | ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR") |
| 192 | action_list.append(ranlib_action) |
| 193 | |
| 194 | convenience_lib = Builder(action = action_list, |
| 195 | emitter = '$LIBEMITTER', |
| 196 | prefix = '$LIBPREFIX', |
| 197 | suffix = '$LIBSUFFIX', |
| 198 | src_suffix = '$SHOBJSUFFIX', |
| 199 | src_builder = 'SharedObject') |
| 200 | env['BUILDERS']['ConvenienceLibrary'] = convenience_lib |
| 201 | env['BUILDERS']['Library'] = convenience_lib |
| 202 | |
| 203 | return convenience_lib |
| 204 | |
| 205 | createConvenienceLibBuilder(env) |
| 206 | |
| 207 | |
| 208 | ####################################################################### |
| 209 | # Invoke SConscripts |
| 210 | |
José Fonseca | f4192cb4 | 2008-01-31 14:21:49 +0900 | [diff] [blame] | 211 | # Put build output in a separate dir, which depends on the current configuration |
| 212 | # See also http://www.scons.org/wiki/AdvancedBuildExample |
| 213 | build_topdir = 'build' |
| 214 | build_subdir = platform |
| 215 | if dri: |
| 216 | build_subdir += "-dri" |
| 217 | if x86: |
| 218 | build_subdir += "-x86" |
| 219 | if debug: |
| 220 | build_subdir += "-debug" |
| 221 | build_dir = os.path.join(build_topdir, build_subdir) |
| 222 | |
| 223 | # TODO: Build several variants at the same time? |
| 224 | # http://www.scons.org/wiki/SimultaneousVariantBuilds |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 225 | |
| 226 | SConscript( |
José Fonseca | 33ceb67 | 2008-02-18 10:52:44 +0000 | [diff] [blame] | 227 | 'src/SConscript', |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 228 | build_dir = build_dir, |
| 229 | duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html |
| 230 | ) |