José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 1 | ####################################################################### |
| 2 | # Top-level SConstruct |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 3 | # |
| 4 | # For example, invoke scons as |
| 5 | # |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 6 | # scons build=debug llvm=yes machine=x86 |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 7 | # |
| 8 | # to set configuration variables. Or you can write those options to a file |
| 9 | # named config.py: |
| 10 | # |
| 11 | # # config.py |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 12 | # build='debug' |
| 13 | # llvm=True |
José Fonseca | 81b6a80 | 2008-02-06 14:36:50 +0900 | [diff] [blame] | 14 | # machine='x86' |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 15 | # |
| 16 | # Invoke |
| 17 | # |
| 18 | # scons -h |
| 19 | # |
| 20 | # to get the full list of options. See scons manpage for more info. |
| 21 | # |
| 22 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 23 | import os |
| 24 | import os.path |
| 25 | import sys |
Alan Hourihane | 550fc19 | 2010-01-26 19:57:34 +0000 | [diff] [blame] | 26 | import SCons.Util |
José Fonseca | d710a7c | 2008-02-19 18:53:16 +0900 | [diff] [blame] | 27 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 28 | import common |
José Fonseca | 58a3d7d | 2008-02-23 19:49:08 +0900 | [diff] [blame] | 29 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 30 | ####################################################################### |
| 31 | # Configuration options |
| 32 | |
José Fonseca | e9fb90a | 2009-05-01 16:12:17 +0100 | [diff] [blame] | 33 | opts = Variables('config.py') |
José Fonseca | 13174c1 | 2008-03-03 18:52:37 +0100 | [diff] [blame] | 34 | common.AddOptions(opts) |
Jonathan White | 3c81992 | 2008-08-29 11:30:32 -0600 | [diff] [blame] | 35 | |
José Fonseca | 81b6a80 | 2008-02-06 14:36:50 +0900 | [diff] [blame] | 36 | env = Environment( |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 37 | options = opts, |
| 38 | tools = ['gallium'], |
José Fonseca | 2c4349a | 2008-07-15 07:56:42 +0900 | [diff] [blame] | 39 | toolpath = ['#scons'], |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 40 | ENV = os.environ, |
| 41 | ) |
| 42 | |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 43 | # Backwards compatability with old target configuration variable |
| 44 | try: |
| 45 | targets = ARGUMENTS['targets'] |
| 46 | except KeyError: |
| 47 | pass |
| 48 | else: |
| 49 | targets = targets.split(',') |
| 50 | print 'scons: warning: targets option is deprecated; pass the targets on their own such as' |
| 51 | print |
| 52 | print ' scons %s' % ' '.join(targets) |
| 53 | print |
| 54 | COMMAND_LINE_TARGETS.append(targets) |
| 55 | |
Alan Hourihane | 6544be6 | 2010-01-26 19:14:16 +0000 | [diff] [blame] | 56 | |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 57 | Help(opts.GenerateHelpText(env)) |
| 58 | |
Chia-I Wu | bb770af | 2011-01-14 17:50:29 +0800 | [diff] [blame] | 59 | # fail early for a common error on windows |
| 60 | if env['gles']: |
| 61 | try: |
| 62 | import libxml2 |
| 63 | except ImportError: |
| 64 | raise SCons.Errors.UserError, "GLES requires libxml2-python to build" |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 65 | |
| 66 | ####################################################################### |
| 67 | # Environment setup |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 68 | |
| 69 | # Includes |
Vinson Lee | 5fd9757 | 2010-04-26 01:08:34 -0700 | [diff] [blame] | 70 | env.Prepend(CPPPATH = [ |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 71 | '#/include', |
Vinson Lee | 5fd9757 | 2010-04-26 01:08:34 -0700 | [diff] [blame] | 72 | ]) |
| 73 | env.Append(CPPPATH = [ |
José Fonseca | 33ceb67 | 2008-02-18 10:52:44 +0000 | [diff] [blame] | 74 | '#/src/gallium/include', |
| 75 | '#/src/gallium/auxiliary', |
| 76 | '#/src/gallium/drivers', |
José Fonseca | 601bfb5 | 2010-03-10 10:34:29 +0000 | [diff] [blame] | 77 | '#/src/gallium/winsys', |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 78 | ]) |
| 79 | |
José Fonseca | dc6bcc9 | 2010-01-10 10:36:35 +0000 | [diff] [blame] | 80 | if env['msvc']: |
| 81 | env.Append(CPPPATH = ['#include/c99']) |
| 82 | |
Alan Hourihane | 32e6043 | 2010-01-28 17:26:05 +0000 | [diff] [blame] | 83 | # Embedded |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 84 | if env['platform'] == 'embedded': |
José Fonseca | 0013796 | 2008-02-07 19:59:17 +0900 | [diff] [blame] | 85 | env.Append(CPPDEFINES = [ |
| 86 | '_POSIX_SOURCE', |
| 87 | ('_POSIX_C_SOURCE', '199309L'), |
| 88 | '_SVID_SOURCE', |
| 89 | '_BSD_SOURCE', |
| 90 | '_GNU_SOURCE', |
| 91 | |
| 92 | 'PTHREADS', |
José Fonseca | 0013796 | 2008-02-07 19:59:17 +0900 | [diff] [blame] | 93 | ]) |
Alan Hourihane | 32e6043 | 2010-01-28 17:26:05 +0000 | [diff] [blame] | 94 | env.Append(LIBS = [ |
| 95 | 'm', |
| 96 | 'pthread', |
| 97 | 'dl', |
| 98 | ]) |
| 99 | |
| 100 | # Posix |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 101 | if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'): |
Alan Hourihane | 32e6043 | 2010-01-28 17:26:05 +0000 | [diff] [blame] | 102 | env.Append(CPPDEFINES = [ |
| 103 | '_POSIX_SOURCE', |
| 104 | ('_POSIX_C_SOURCE', '199309L'), |
| 105 | '_SVID_SOURCE', |
| 106 | '_BSD_SOURCE', |
| 107 | '_GNU_SOURCE', |
Alan Hourihane | 32e6043 | 2010-01-28 17:26:05 +0000 | [diff] [blame] | 108 | 'PTHREADS', |
| 109 | 'HAVE_POSIX_MEMALIGN', |
| 110 | ]) |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 111 | if env['gcc']: |
Jakob Bornecrantz | 2ebe027 | 2010-05-12 22:48:32 +0100 | [diff] [blame] | 112 | env.Append(CFLAGS = ['-fvisibility=hidden']) |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 113 | if env['platform'] == 'darwin': |
Vinson Lee | d57ba16 | 2010-01-23 21:05:58 -0800 | [diff] [blame] | 114 | env.Append(CPPDEFINES = ['_DARWIN_C_SOURCE']) |
José Fonseca | 0013796 | 2008-02-07 19:59:17 +0900 | [diff] [blame] | 115 | env.Append(LIBS = [ |
| 116 | 'm', |
| 117 | 'pthread', |
José Fonseca | 0013796 | 2008-02-07 19:59:17 +0900 | [diff] [blame] | 118 | 'dl', |
| 119 | ]) |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 120 | |
José Fonseca | 4f17bd2 | 2008-03-12 13:34:30 +0000 | [diff] [blame] | 121 | # for debugging |
| 122 | #print env.Dump() |
| 123 | |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 124 | |
| 125 | ####################################################################### |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 126 | # Invoke host SConscripts |
| 127 | # |
| 128 | # For things that are meant to be run on the native host build machine, instead |
| 129 | # of the target machine. |
| 130 | # |
| 131 | |
| 132 | # Create host environent |
José Fonseca | ae76027 | 2011-02-11 16:44:13 +0000 | [diff] [blame] | 133 | if env['crosscompile'] and env['platform'] != 'embedded': |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 134 | host_env = Environment( |
| 135 | options = opts, |
| 136 | # no tool used |
| 137 | tools = [], |
| 138 | toolpath = ['#scons'], |
| 139 | ENV = os.environ, |
| 140 | ) |
| 141 | |
| 142 | # Override options |
| 143 | host_env['platform'] = common.host_platform |
| 144 | host_env['machine'] = common.host_machine |
| 145 | host_env['toolchain'] = 'default' |
| 146 | host_env['llvm'] = False |
| 147 | |
| 148 | host_env.Tool('gallium') |
| 149 | |
José Fonseca | 982609f | 2011-02-11 17:38:54 +0000 | [diff] [blame] | 150 | host_env['hostonly'] = True |
| 151 | assert host_env['crosscompile'] == False |
| 152 | |
José Fonseca | 6826d58 | 2011-02-11 17:59:36 +0000 | [diff] [blame] | 153 | if host_env['msvc']: |
| 154 | host_env.Append(CPPPATH = ['#include/c99']) |
| 155 | |
José Fonseca | 9f9d648 | 2011-02-15 15:31:19 +0000 | [diff] [blame] | 156 | target_env = env |
| 157 | env = host_env |
| 158 | Export('env') |
José Fonseca | 982609f | 2011-02-11 17:38:54 +0000 | [diff] [blame] | 159 | |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 160 | SConscript( |
José Fonseca | 982609f | 2011-02-11 17:38:54 +0000 | [diff] [blame] | 161 | 'src/SConscript', |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 162 | variant_dir = host_env['build_dir'], |
| 163 | duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 164 | ) |
| 165 | |
José Fonseca | 9f9d648 | 2011-02-15 15:31:19 +0000 | [diff] [blame] | 166 | env = target_env |
| 167 | |
José Fonseca | 982609f | 2011-02-11 17:38:54 +0000 | [diff] [blame] | 168 | Export('env') |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 169 | |
| 170 | ####################################################################### |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 171 | # Invoke SConscripts |
| 172 | |
José Fonseca | f4192cb4 | 2008-01-31 14:21:49 +0900 | [diff] [blame] | 173 | # TODO: Build several variants at the same time? |
| 174 | # http://www.scons.org/wiki/SimultaneousVariantBuilds |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 175 | |
| 176 | SConscript( |
José Fonseca | 33ceb67 | 2008-02-18 10:52:44 +0000 | [diff] [blame] | 177 | 'src/SConscript', |
José Fonseca | 67450f0 | 2010-09-29 14:08:53 +0100 | [diff] [blame] | 178 | variant_dir = env['build_dir'], |
José Fonseca | c42e625 | 2008-01-31 13:14:35 +0900 | [diff] [blame] | 179 | duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html |
| 180 | ) |
José Fonseca | 7bbf7f9 | 2009-12-31 21:10:25 +0000 | [diff] [blame] | 181 | |