summaryrefslogtreecommitdiff
path: root/src/SConstruct
blob: 37be39a9273076bca6a23393df976ec48b640a49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import os
import platform
import sys

_platform_map = {
	'darwin': 'darwin',
	'freebsd': 'freebsd',
	'linux2': 'linux',
	'win32': 'windows',
}

default_platform = _platform_map.get(sys.platform, 'unix')

_machine_map = {
	'x86': 'x86',
	'i386': 'x86',
	'i486': 'x86',
	'i586': 'x86',
	'i686': 'x86',
	'ppc' : 'ppc',
	'x86_64': 'x86_64',
}
if 'PROCESSOR_ARCHITECTURE' in os.environ:
	default_machine = os.environ['PROCESSOR_ARCHITECTURE']
else:
	default_machine = platform.machine()
default_machine = _machine_map.get(default_machine, 'generic')

if default_platform == 'windows':
    default_prefix = os.path.join(os.environ.get('ProgramFiles', 'C:\\Program Files'), 'glean')
else:
    default_prefix = '/usr/local'

vars = Variables()
vars.Add(BoolVariable('debug', 'debug build', 'yes'))
vars.Add(EnumVariable('platform', 'target platform', default_platform,
                      allowed_values=('linux', 'freebsd', 'unix', 'other', 'windows', 'darwin')))
vars.Add(EnumVariable('machine', 'use machine-specific assembly code', default_machine,
                      allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
vars.Add(EnumVariable('toolchain', 'compiler toolchain', 'default',
                      allowed_values=('default', 'crossmingw')))
vars.Add(PathVariable('prefix', 'installation prefix', default_prefix, PathVariable.PathIsDirCreate))
if platform.machine() == 'win32':
    vars.Add(EnumVariable('MSVS_VERSION', 'Microsoft Visual Studio version', None, 
                          allowed_values=('7.1', '8.0', '9.0')))

env = Environment(variables=vars)
Help(vars.GenerateHelpText(env))

Export(['env'])

env.Tool(env['toolchain'], ['../scons'])

env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
env['msvc'] = env['CC'] == 'cl'

# C preprocessor options
cppdefines = []
if not env['debug']:
    cppdefines += ['NDEBUG']
if env['platform'] == 'windows':
    cppdefines += [
        'WIN32',
        '_CONSOLE',
        '_MBCS',
    ]
    if env['debug']:
        cppdefines += ['_DEBUG']
env.Append(CPPDEFINES = cppdefines)

# C compiler options
cflags = [] # C
cxxflags = [] # C++
ccflags = [] # C & C++
if env['gcc']:
    if env['debug']:
        ccflags += ['-O0', '-g3']
    else:
        ccflags += ['-O3', '-g0']
    if env['machine'] == 'x86':
        ccflags += ['-m32']
    if env['machine'] == 'x86_64':
        ccflags += ['-m64']
    # See also:
    # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
    ccflags += [
        '-Wall',
        '-Wmissing-field-initializers',
        '-Wpointer-arith',
        '-fmessage-length=0', # be nice to Eclipse
    ]
    cflags += [
        '-Wdeclaration-after-statement',
        '-Wmissing-prototypes',
    ]
if env['msvc']:
    if env['debug']:
        ccflags += [
          '/Od', # disable optimizations
          '/Oi', # enable intrinsic functions
          '/Oy-', # disable frame pointer omission
          '/GL-', # disable whole program optimization
        ]
    else:
        ccflags += [
          '/O2', # optimize for speed
        ]
    ccflags += [
        '/EHsc', # set exception handling model
        #'/W3', # warning level
        #'/Wp64', # enable 64 bit porting warnings
    ]
    # Automatic pdb generation
    # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
    env.EnsureSConsVersion(0, 98, 0)
    env['PDB'] = '${TARGET.base}.pdb'
env.Append(CCFLAGS = ccflags)
env.Append(CFLAGS = cflags)
env.Append(CXXFLAGS = cxxflags)

if env['platform'] == 'windows' and env['msvc']:
    # Choose the appropriate MSVC CRT
    # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
    if env['debug']:
        env.Append(CCFLAGS = ['/MTd'])
        env.Append(SHCCFLAGS = ['/LDd'])
    else:
        env.Append(CCFLAGS = ['/MT'])
        env.Append(SHCCFLAGS = ['/LD'])
    
# Assembler options
if env['gcc']:
    if env['machine'] == 'x86':
        env.Append(ASFLAGS = ['-m32'])
    if env['machine'] == 'x86_64':
        env.Append(ASFLAGS = ['-m64'])

# Linker options
linkflags = []
if env['gcc']:
    if env['machine'] == 'x86':
        linkflags += ['-m32']
    if env['machine'] == 'x86_64':
        linkflags += ['-m64']
if env['platform'] == 'windows' and env['msvc']:
    # See also:
    # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
    linkflags += [
        '/fixed:no',
        '/incremental:no',
    ]
env.Append(LINKFLAGS = linkflags)

if env['platform'] in ('freebsd', 'linux', 'unix'):
    env.Append(CPPDEFINES = [
        '__UNIX__',
        '__X11__',
    ])
    env.Prepend(LIBS = [
        'GLU',
        'GL',
    ])

if env['platform'] == 'windows':
    env.Append(CPPDEFINES = [
        '__WIN__',
        '__MS__',
    ])
    env.Prepend(LIBS = [
        'glu32',
        'opengl32',
        'gdi32',
        'user32',
        'kernel32',
    ])

if env['platform'] == 'darwin':
    env.Append(CPPDEFINES = [
        '__UNIX__',
        '__AGL__',
    ])
    env.Prepend(FRAMEWORKS = [
        'AGL',
        'Carbon',
        'GLUT',
        'OpenGL',
    ])

variant = env['platform']
if env['machine'] != 'generic':
    variant += '-' + env['machine']
if env['debug']:
    variant += '-debug'
env['variant'] = variant

# Put all SCons' persistent data in the build dir
build_dir = os.path.join('..', 'build', variant)
env.SConsignFile(os.path.join(build_dir, 'sign'))
env['CONFIGUREDIR'] = os.path.join(build_dir, 'conf')
env['CONFIGURELOG'] = os.path.join(build_dir, 'config.log')

conf = Configure(env)
if not conf.CheckCHeader('GL/glext.h'):
    conf.env.Prepend(CPPPATH = ['#glext'])
if conf.CheckCHeader('GL/glut.h'):
    if env['platform'] == 'windows':
        conf.env.Prepend(LIBS = ['glut32'])
    else:
        conf.env.Prepend(LIBS = ['glut'])
    conf.env['glut'] = True
else:
    conf.env['glut'] = False
has_tiff = conf.CheckCHeader('tiff.h')
env = conf.Finish()

if has_tiff:
    conf.env.Prepend(LIBS = ['tiff'])
else:
    SConscript(['tiff/SConscript'])
    Import(['tiff'])
    conf.env.Prepend(CPPPATH = ['#tiff'])
    conf.env.Prepend(LIBS = [tiff])

env.Prepend(CPPPATH = [
    '#glh',
    '#libs/dsurf',
    '#libs/image',
    '#libs/lex',
    '#libs/rand',
    '#libs/stats',
    '#libs/timer',
])

env.VariantDir(build_dir, '.', duplicate=0)

SConscript('SConscript', variant_dir=build_dir, duplicate=0)