-
Notifications
You must be signed in to change notification settings - Fork 4
/
SConstruct
233 lines (180 loc) · 7.22 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
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 ()
GIT_DESC = getGitDesc ()
print "building " + GIT_DESC + ".."
env = Environment ()
import shutil
if 'clean_test' in COMMAND_LINE_TARGETS:
print "cleaning out tests.."
for fn in os.listdir('./test/'):
if '.passed' in fn or '.setup' 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.."
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'])
nmenv = env.Clone()
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('glibmm-2.4'):
print "glibmm-2.4 not found."
Exit (1)
if not conf.CheckPKG('gmime-2.6'):
print "gmime-2.6 not found."
Exit (1)
if not conf.CheckLibWithHeader ('notmuch', 'notmuch.h', 'c'):
print "notmuch does not seem to be installed."
Exit (1)
# external libraries
env.ParseConfig ('pkg-config --libs --cflags glibmm-2.4')
env.ParseConfig ('pkg-config --libs --cflags gmime-2.6')
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)
if not conf.CheckLib ('boost_date_time', language = 'c++'):
print "boost_date_time 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. building notmuch_get_revision will be disabled. please get a notmuch with lastmod capabilities to ensure a speedier sync."
libs = ['notmuch',
'boost_filesystem',
'boost_system',
'boost_program_options',
'boost_date_time']
env.AppendUnique (LIBS = libs)
cenv = env.Clone (CFLAGS = ['-g', '-Wall'])
env.AppendUnique (CPPFLAGS = ['-g', '-Wall', '-std=c++11', '-pthread'] )
# write version file
#print ("writing version.hh..")
#vfd = open ('version.hh', 'w')
#vfd.write ("# pragma once\n")
#vfd.write ("# define GIT_DESC \"%s\"\n\n" % GIT_DESC)
#vfd.close ()
env = conf.Finish ()
spruce = cenv.Object ('spruce-imap-utils.c')
source = [ env.Object ('keywsync.cc'), spruce ]
env.Program (source = source, target = 'keywsync')
build = env.Alias ('build', ['keywsync'])
if have_get_rev:
nmenv.AppendUnique (LIBS = ['notmuch'])
nmenv.Program ('notmuch_get_revision', source = [ 'notmuch_get_revision.cc' ])
nmenv.Alias ('build', ['notmuch_get_revision'])
## tests
# http://drowcode.blogspot.no/2008/12/few-days-ago-i-decided-i-wanted-to-use.html
testEnv = env.Clone()
testEnv.Append (CPPPATH = '../')
testEnv.Tool ('unittest',
toolpath=['test/bt/'],
UTEST_MAIN_SRC=File('test/bt/boostautotestmain.cc'),
LIBS=['boost_unit_test_framework']
)
Export ('source')
Export ('testEnv')
Export ('env')
Default (build)
# grab stuff from sub-directories.
env.SConscript(dirs = ['test'])