forked from astroidmail/astroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
313 lines (245 loc) · 9.88 KB
/
SConstruct
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import os, sys
import SCons
from subprocess import *
def getGitDesc():
return Popen('git describe --abbrev=8 --tags --always', stdout=PIPE, shell=True).stdout.read ().strip ()
env = Environment ()
AddOption ("--release", action="store", dest="release", default="git", help="Make a release (default: git describe output)")
AddOption ("--enable-debug", action="store", dest="debug", default=None, help="Enable the -g flag for debugging (default: true when release is git)")
AddOption ("--prefix", action="store", dest="prefix", default = '/usr/local', help="Directory to install astroid under")
prefix = GetOption ("prefix")
release = GetOption("release")
if release != "git":
GIT_DESC = release
print "building release: " + release
in_release = True
else:
GIT_DESC = getGitDesc ()
print "building version " + GIT_DESC + " (git).."
in_release = False
debug = GetOption("debug")
if debug == None:
debug = (release == "git")
else:
debug = (debug.lower () == 'yes' or debug.lower () == 'true')
print "debug flag enabled: " + str(debug)
if 'clean_test' in COMMAND_LINE_TARGETS:
print "cleaning out tests.."
for fn in os.listdir('./test/'):
if '.passed' in fn:
print "delting: " + fn
os.remove (os.path.join ('./test', fn))
for fn in os.listdir('./test/mail/'):
if '.passed' in fn or '.setup' in fn:
print "delting: " + fn
os.remove (os.path.join ('./test/mail/', fn))
# clean notmuch dir
print "cleaning out notmuch dir.."
import shutil
if os.path.exists ("./test/mail/test_mail/.notmuch"):
shutil.rmtree ("./test/mail/test_mail/.notmuch")
exit ()
# Verbose / Non-verbose output{{{
colors = {}
colors['cyan'] = '\033[96m'
colors['purple'] = '\033[95m'
colors['blue'] = '\033[94m'
colors['green'] = '\033[92m'
colors['yellow'] = '\033[93m'
colors['red'] = '\033[91m'
colors['end'] = '\033[0m'
#If the output is not a terminal, remove the colors
if not sys.stdout.isatty():
for key, value in colors.iteritems():
colors[key] = ''
compile_source_message = '%scompiling %s==> %s$SOURCE%s' % \
(colors['blue'], colors['purple'], colors['yellow'], colors['end'])
compile_shared_source_message = '%scompiling shared %s==> %s$SOURCE%s' % \
(colors['blue'], colors['purple'], colors['yellow'], colors['end'])
link_program_message = '%slinking Program %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
link_library_message = '%slinking Static Library %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
ranlib_library_message = '%sranlib Library %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
link_shared_library_message = '%slinking Shared Library %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
java_compile_source_message = '%scompiling %s==> %s$SOURCE%s' % \
(colors['blue'], colors['purple'], colors['yellow'], colors['end'])
java_library_message = '%screating Java Archive %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
AddOption("--verbose",action="store_true", dest="verbose_flag",default=False,help="verbose output")
if not GetOption("verbose_flag"):
env["CXXCOMSTR"] = compile_source_message,
env["CCCOMSTR"] = compile_source_message,
env["SHCCCOMSTR"] = compile_shared_source_message,
env["SHCXXCOMSTR"] = compile_shared_source_message,
env["ARCOMSTR"] = link_library_message,
env["RANLIBCOMSTR"] = ranlib_library_message,
env["SHLINKCOMSTR"] = link_shared_library_message,
env["LINKCOMSTR"] = link_program_message,
env["JARCOMSTR"] = java_library_message,
env["JAVACCOMSTR"] = java_compile_source_message,
# Verbose }}}
# set up compiler and linker from env variables
if os.environ.has_key('CC'):
env['CC'] = os.environ['CC']
if os.environ.has_key('CFLAGS'):
env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
if os.environ.has_key('CXX'):
env['CXX'] = os.environ['CXX']
if os.environ.has_key('CXXFLAGS'):
env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
if os.environ.has_key('CPPFLAGS'):
env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CPPFLAGS'])
if os.environ.has_key('LDFLAGS'):
env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
def CheckPKGConfig(context, version):
context.Message( 'Checking for pkg-config... ' )
ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
context.Result( ret )
return ret
def CheckPKG(context, name):
context.Message( 'Checking for %s... ' % name )
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.Result( ret )
return ret
nm_db_get_revision_test_src = """
# include <notmuch.h>
int main (int argc, char ** argv)
{
notmuch_database_t * nm_db;
const char * uuid;
notmuch_database_get_revision (nm_db, &uuid);
return 0;
}
"""
# http://www.scons.org/doc/1.2.0/HTML/scons-user/x4076.html
def check_notmuch_get_revision (ctx):
ctx.Message ("Checking for C function notmuch_database_get_revision()..")
result = ctx.TryCompile (nm_db_get_revision_test_src, '.cpp')
ctx.Result (result)
return result
conf = Configure(env, custom_tests = { 'CheckPKGConfig' : CheckPKGConfig,
'CheckPKG' : CheckPKG,
'CheckNotmuchGetRev' : check_notmuch_get_revision})
if not conf.CheckPKGConfig('0.15.0'):
print 'pkg-config >= 0.15.0 not found.'
Exit(1)
if not conf.CheckPKG('gtkmm-3.0 >= 3.10'):
print 'gtkmm-3.0 >= 3.10 not found.'
Exit(1)
if not conf.CheckPKG('glibmm-2.4'):
print "glibmm-2.4 not found."
Exit (1)
if not conf.CheckPKG('gmime-2.6 >= 2.6.18'):
print "gmime-2.6 not found."
Exit (1)
if not conf.CheckPKG('webkitgtk-3.0'):
print "webkitgtk not found."
Exit (1)
if conf.CheckLibWithHeader ('libsass', 'sass_context.h', 'c'):
env.AppendUnique (CPPFLAGS = [ '-DSASSCTX_SASS_CONTEXT_H' ])
elif conf.CheckLibWithHeader ('libsass', 'sass/context.h', 'c'):
env.AppendUnique (CPPFLAGS = [ '-DSASSCTX_CONTEXT_H' ])
else:
print "libsass must be installed: could not find header file."
Exit (1)
if not conf.CheckLibWithHeader ('notmuch', 'notmuch.h', 'c'):
print "notmuch does not seem to be installed."
Exit (1)
if conf.CheckNotmuchGetRev ():
have_get_rev = True
env.AppendUnique (CPPFLAGS = [ '-DHAVE_NOTMUCH_GET_REV' ])
else:
have_get_rev = False
print "notmuch_database_get_revision() not available. A recent notmuch with lastmod capabilities will result in easier updating of new threads and smoother polls."
# external libraries
env.ParseConfig ('pkg-config --libs --cflags glibmm-2.4')
env.ParseConfig ('pkg-config --libs --cflags gtkmm-3.0')
env.ParseConfig ('pkg-config --libs --cflags gmime-2.6')
env.ParseConfig ('pkg-config --libs --cflags webkitgtk-3.0')
env.ParseConfig ('pkg-config --libs --cflags libsass')
if not conf.CheckLib ('boost_filesystem', language = 'c++'):
print "boost_filesystem does not seem to be installed."
Exit (1)
if not conf.CheckLib ('boost_system', language = 'c++'):
print "boost_system does not seem to be installed."
Exit (1)
if not conf.CheckLib ('boost_program_options', language = 'c++'):
print "boost_program_options does not seem to be installed."
Exit (1)
libs = ['notmuch',
'boost_filesystem',
'boost_system',
'boost_program_options',
'stdc++']
env.AppendUnique (LIBS = libs)
env.AppendUnique (CPPFLAGS = ['-Wall', '-std=c++11', '-pthread'] )
if debug:
env.AppendUnique (CPPFLAGS = ['-g', '-Wextra', '-DDEBUG'])
## write config file
print ("writing src/build_config.hh..")
vfd = open ('src/build_config.hh', 'w')
vfd.write ("""// this is an automatically generated file. it will be overwritten by\n"""
"""// scons. do not check this file into git.\n""")
vfd.write ("# pragma once\n")
vfd.write ("# define GIT_DESC \"%s\"\n" % GIT_DESC)
vfd.write ("# define PREFIX \"%s\"\n" % prefix)
vfd.write ("\n")
vfd.close ()
env.Append (CPPPATH = 'src')
source = (
Glob('src/*.cc', strings = True) +
Glob('src/modes/*.cc', strings = True) +
Glob('src/modes/thread_index/*.cc', strings = True) +
Glob('src/modes/thread_view/*.cc', strings = True) +
Glob('src/modes/editor/*.cc', strings = True) +
Glob('src/actions/*.cc', strings = True) +
Glob('src/utils/*.cc', strings = True)
)
source.remove ('src/main.cc')
source_objs = [env.Object (s) for s in source]
Export ('source')
Export ('source_objs')
Export ('debug')
env = conf.Finish ()
astroid = env.Program (source = ['src/main.cc', source_objs], target = 'astroid')
build = env.Alias ('build', 'astroid')
Export ('env')
Export ('astroid')
## tests
# http://drowcode.blogspot.no/2008/12/few-days-ago-i-decided-i-wanted-to-use.html
testEnv = env.Clone()
testEnv.Append (CPPPATH = '../src')
testEnv.Tool ('unittest',
toolpath=['test/bt/'],
UTEST_MAIN_SRC=File('test/bt/boostautotestmain.cc'),
LIBS=['boost_unit_test_framework']
)
Export ('testEnv')
# grab stuff from sub-directories.
env.SConscript(dirs = ['test'])
## Install target
idir_prefix = prefix
idir_bin = os.path.join (prefix, 'bin')
idir_shr = os.path.join (prefix, 'share/astroid')
idir_ui = os.path.join (idir_shr, 'ui')
idir_app = os.path.join (prefix, 'share/applications')
inst_bin = env.Install (idir_bin, astroid)
inst_shr = env.Install (idir_ui, Glob ('ui/*.glade') +
Glob ('ui/*.scss') +
Glob ('ui/*.png') +
Glob ('ui/*.html'))
inst_app = env.Install (idir_app, 'ui/astroid.desktop')
env.Alias ('install', inst_bin)
env.Alias ('install', inst_shr)
env.Alias ('install', inst_app)
env.Depends (inst_bin, astroid)
env.Depends (inst_shr, astroid)
env.Depends (inst_app, astroid)
Ignore ('.', inst_bin)
Ignore ('.', inst_shr)
Ignore ('.', inst_app)
## Default target
Default (astroid)