blob: 8607d2cd8e0ab726039d02202e067c158ae75ff4 [file] [log] [blame]
José Fonsecac42e6252008-01-31 13:14:35 +09001#######################################################################
2# Top-level SConstruct
José Fonsecac42e6252008-01-31 13:14:35 +09003#
4# For example, invoke scons as
5#
José Fonseca601498a2010-11-01 13:30:22 +00006# scons build=debug llvm=yes machine=x86
José Fonsecac42e6252008-01-31 13:14:35 +09007#
8# to set configuration variables. Or you can write those options to a file
9# named config.py:
10#
11# # config.py
José Fonseca601498a2010-11-01 13:30:22 +000012# build='debug'
13# llvm=True
José Fonseca81b6a802008-02-06 14:36:50 +090014# machine='x86'
José Fonsecac42e6252008-01-31 13:14:35 +090015#
16# Invoke
17#
18# scons -h
19#
20# to get the full list of options. See scons manpage for more info.
21#
22
José Fonseca94090432008-02-27 17:36:28 +090023import os
24import os.path
25import sys
Alan Hourihane550fc192010-01-26 19:57:34 +000026import SCons.Util
José Fonsecad710a7c2008-02-19 18:53:16 +090027
José Fonseca94090432008-02-27 17:36:28 +090028import common
José Fonseca58a3d7d2008-02-23 19:49:08 +090029
José Fonseca94090432008-02-27 17:36:28 +090030#######################################################################
31# Configuration options
32
José Fonsecae9fb90a2009-05-01 16:12:17 +010033opts = Variables('config.py')
José Fonseca13174c12008-03-03 18:52:37 +010034common.AddOptions(opts)
Jonathan White3c819922008-08-29 11:30:32 -060035
José Fonseca81b6a802008-02-06 14:36:50 +090036env = Environment(
José Fonsecab04aa712008-06-06 14:48:57 +090037 options = opts,
38 tools = ['gallium'],
José Fonseca2c4349a2008-07-15 07:56:42 +090039 toolpath = ['#scons'],
José Fonsecab04aa712008-06-06 14:48:57 +090040 ENV = os.environ,
41)
42
José Fonseca601498a2010-11-01 13:30:22 +000043# Backwards compatability with old target configuration variable
44try:
45 targets = ARGUMENTS['targets']
46except KeyError:
47 pass
48else:
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 Hourihane6544be62010-01-26 19:14:16 +000056
José Fonsecac42e6252008-01-31 13:14:35 +090057Help(opts.GenerateHelpText(env))
58
Chia-I Wubb770af2011-01-14 17:50:29 +080059# fail early for a common error on windows
60if env['gles']:
61 try:
62 import libxml2
63 except ImportError:
64 raise SCons.Errors.UserError, "GLES requires libxml2-python to build"
José Fonsecac42e6252008-01-31 13:14:35 +090065
66#######################################################################
67# Environment setup
José Fonsecac42e6252008-01-31 13:14:35 +090068
69# Includes
Vinson Lee5fd97572010-04-26 01:08:34 -070070env.Prepend(CPPPATH = [
José Fonsecac42e6252008-01-31 13:14:35 +090071 '#/include',
Vinson Lee5fd97572010-04-26 01:08:34 -070072])
73env.Append(CPPPATH = [
José Fonseca33ceb672008-02-18 10:52:44 +000074 '#/src/gallium/include',
75 '#/src/gallium/auxiliary',
76 '#/src/gallium/drivers',
José Fonseca601bfb52010-03-10 10:34:29 +000077 '#/src/gallium/winsys',
José Fonsecac42e6252008-01-31 13:14:35 +090078])
79
José Fonsecadc6bcc92010-01-10 10:36:35 +000080if env['msvc']:
81 env.Append(CPPPATH = ['#include/c99'])
82
Alan Hourihane32e60432010-01-28 17:26:05 +000083# Embedded
José Fonseca601498a2010-11-01 13:30:22 +000084if env['platform'] == 'embedded':
José Fonseca00137962008-02-07 19:59:17 +090085 env.Append(CPPDEFINES = [
86 '_POSIX_SOURCE',
87 ('_POSIX_C_SOURCE', '199309L'),
88 '_SVID_SOURCE',
89 '_BSD_SOURCE',
90 '_GNU_SOURCE',
91
92 'PTHREADS',
José Fonseca00137962008-02-07 19:59:17 +090093 ])
Alan Hourihane32e60432010-01-28 17:26:05 +000094 env.Append(LIBS = [
95 'm',
96 'pthread',
97 'dl',
98 ])
99
100# Posix
José Fonseca601498a2010-11-01 13:30:22 +0000101if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
Alan Hourihane32e60432010-01-28 17:26:05 +0000102 env.Append(CPPDEFINES = [
103 '_POSIX_SOURCE',
104 ('_POSIX_C_SOURCE', '199309L'),
105 '_SVID_SOURCE',
106 '_BSD_SOURCE',
107 '_GNU_SOURCE',
Alan Hourihane32e60432010-01-28 17:26:05 +0000108 'PTHREADS',
109 'HAVE_POSIX_MEMALIGN',
110 ])
José Fonseca601498a2010-11-01 13:30:22 +0000111 if env['gcc']:
Jakob Bornecrantz2ebe0272010-05-12 22:48:32 +0100112 env.Append(CFLAGS = ['-fvisibility=hidden'])
José Fonseca601498a2010-11-01 13:30:22 +0000113 if env['platform'] == 'darwin':
Vinson Leed57ba162010-01-23 21:05:58 -0800114 env.Append(CPPDEFINES = ['_DARWIN_C_SOURCE'])
José Fonseca00137962008-02-07 19:59:17 +0900115 env.Append(LIBS = [
116 'm',
117 'pthread',
José Fonseca00137962008-02-07 19:59:17 +0900118 'dl',
119 ])
José Fonsecac42e6252008-01-31 13:14:35 +0900120
José Fonseca4f17bd22008-03-12 13:34:30 +0000121# for debugging
122#print env.Dump()
123
José Fonsecac42e6252008-01-31 13:14:35 +0900124
125#######################################################################
José Fonsecae1bc68b2011-01-13 20:52:01 +0000126# 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é Fonsecaae760272011-02-11 16:44:13 +0000133if env['crosscompile'] and env['platform'] != 'embedded':
José Fonsecae1bc68b2011-01-13 20:52:01 +0000134 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é Fonseca982609f2011-02-11 17:38:54 +0000150 host_env['hostonly'] = True
151 assert host_env['crosscompile'] == False
152
José Fonseca6826d582011-02-11 17:59:36 +0000153 if host_env['msvc']:
154 host_env.Append(CPPPATH = ['#include/c99'])
155
José Fonseca9f9d6482011-02-15 15:31:19 +0000156 target_env = env
157 env = host_env
158 Export('env')
José Fonseca982609f2011-02-11 17:38:54 +0000159
José Fonsecae1bc68b2011-01-13 20:52:01 +0000160 SConscript(
José Fonseca982609f2011-02-11 17:38:54 +0000161 'src/SConscript',
José Fonsecae1bc68b2011-01-13 20:52:01 +0000162 variant_dir = host_env['build_dir'],
163 duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
José Fonsecae1bc68b2011-01-13 20:52:01 +0000164 )
165
José Fonseca9f9d6482011-02-15 15:31:19 +0000166 env = target_env
167
José Fonseca982609f2011-02-11 17:38:54 +0000168Export('env')
José Fonsecae1bc68b2011-01-13 20:52:01 +0000169
170#######################################################################
José Fonsecac42e6252008-01-31 13:14:35 +0900171# Invoke SConscripts
172
José Fonsecaf4192cb42008-01-31 14:21:49 +0900173# TODO: Build several variants at the same time?
174# http://www.scons.org/wiki/SimultaneousVariantBuilds
José Fonsecac42e6252008-01-31 13:14:35 +0900175
176SConscript(
José Fonseca33ceb672008-02-18 10:52:44 +0000177 'src/SConscript',
José Fonseca67450f02010-09-29 14:08:53 +0100178 variant_dir = env['build_dir'],
José Fonsecac42e6252008-01-31 13:14:35 +0900179 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
180)
José Fonseca7bbf7f92009-12-31 21:10:25 +0000181