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
| | # -*- mode: python; coding: utf-8 -*-
import os
variables = Variables('custom.py')
variables.Add('DESTDIR',
'Destination directory',
'')
variables.Add('prefix',
'Installation prefix',
'/usr/local')
variables.Add('bindir',
'Directory that user binaries go into',
'${prefix}/bin')
variables.Add('datadir',
'Directory that static data files go into',
'${prefix}/share')
variables.Add('mandir',
'Directory that manual pages go into',
'${datadir}/man')
variables.Add('emacs_lispdir',
'Directory that Emacs LISP files go into',
'${default_emacs_lispdir}')
variables.Add('sysconfdir',
'Directory that system configuration files go into',
'/etc')
variables.Add('bash_completion_dir',
'Directory that Bash completion files go into',
'${sysconfdir}/bash_completion.d')
variables.Add('desktop_dir',
'Directory that desktop files go into',
'${datadir}/applications')
variables.Add('gzip',
'Gzip executable',
'gzip')
variables.Add('emacs',
'Emacs executable',
'emacs')
def InstallPerm(env, dest, files, perm):
obj = env.Install(dest, files)
for i in obj:
env.AddPostAction(i, Chmod(str(i), perm))
return dest
def InstallAsPerm(env, dest, files, perm):
obj = env.InstallAs(dest, files)
for i in obj:
env.AddPostAction(i, Chmod(str(i), perm))
return dest
topenv = Environment(variables = variables,
BUILDERS = {'InstallPerm': InstallPerm,
'InstallAsPerm': InstallAsPerm})
topenv.Append(CPPPATH=['#/lib'])
cflags = None
if os.environ.has_key('CFLAGS'):
cflags = topenv.ParseFlags(os.environ['CFLAGS'])
topenv.MergeFlags(cflags)
if os.environ.has_key('CXXFLAGS'):
cxxflags = topenv.ParseFlags(os.environ['CXXFLAGS'])
topenv.MergeFlags(cxxflags)
if cflags is None or cxxflags is None:
optflags = topenv.ParseFlags('-O2')
topenv.MergeFlags(optflags)
warnflags = topenv.ParseFlags('-Wall -Wextra -Wmissing-declarations -Wwrite-strings -Wswitch-enum')
topenv.MergeFlags(warnflags)
def CheckPkgConfig(context, version):
context.Message('Checking for pkg-config... ')
result = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
context.Result(result)
return result
def CheckPkg(context, name):
context.Message('Checking for %s... ' % name)
result = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.Result(result)
return result
def CheckXapian(context):
context.Message('Checking for xapian-core... ')
for xapian_config in ['xapian-config-1.1', 'xapian-config']:
result, output = context.TryAction('%s --version > $TARGET' % xapian_config)
if result:
xapian_version = output.strip().split()[-1]
context.env['xapian_config'] = xapian_config
context.env['xapian_version'] = xapian_version
context.Result(xapian_version)
return result
context.Result(False)
return False
def CheckEmacs(context):
context.Message('Checking for emacs... ')
context.env['default_emacs_lispdir'] = '${prefix}/share/emacs/site-lisp'
result = context.TryAction('pkg-config --exists emacs')
if result:
result, output = context.TryAction('pkg-config emacs --variable sitepkglispdir > $TARGET')
if result:
context.env['default_emacs_lispdir'] = output.strip()
context.Result(True)
return True
context.Result(False)
return False
def CheckDesktopFileInstall(context):
context.Message('Checking for desktop-file-install... ')
result = context.TryAction('desktop-file-install -h')[0]
context.Result(result)
return result
conf = Configure(topenv, custom_tests = {'CheckPkgConfig': CheckPkgConfig,
'CheckPkg': CheckPkg,
'CheckXapian': CheckXapian,
'CheckEmacs': CheckEmacs,
'CheckDesktopFileInstall': CheckDesktopFileInstall})
if not conf.CheckPkgConfig('0.23'):
print 'pkg-config >= 0.23 not found.'
Exit(1)
if not conf.CheckPkg('glib-2.0 >= 2.22'):
print 'glib-2.0 >= 2.22 not found'
Exit(1)
if not conf.CheckPkg('gmime-2.4 >= 2.4.0'):
print 'gmime-2.4 >= 2.4.0 not found'
Exit(1)
if not conf.CheckPkg('talloc >= 2.0.0'):
print 'talloc >= 2.0.0 not found'
Exit(1)
if not conf.CheckXapian():
print 'xapian not found'
Exit(1)
emacs = conf.CheckEmacs()
valgrind = conf.CheckPkg('valgrind >= 3.5.0')
desktop = conf.CheckDesktopFileInstall()
if not conf.CheckFunc('strndup'):
conf.env.Append(CPPDEFINES = ['NEED_STRNDUP'])
if not conf.CheckFunc('getline'):
conf.env.Append(CPPDEFINES = ['NEED_GETLINE'])
topenv = conf.Finish()
topenv.ParseConfig('pkg-config glib-2.0 --cflags --libs')
topenv.ParseConfig('pkg-config gmime-2.4 --cflags --libs')
topenv.ParseConfig('pkg-config talloc --cflags --libs')
topenv.ParseConfig('${xapian_config} --cxxflags --libs')
if valgrind:
topenv.ParseConfig('pkg-config valgrind --cflags')
topenv.Append(CPPDEFINES = ['HAVE_VALGRIND'])
Help(variables.GenerateHelpText(topenv))
Export('topenv')
libnotmuch = SConscript(['lib/SConscript'])
env = topenv.Clone()
notmuch = env.Program('notmuch', ['debugger.c',
'gmime-filter-reply.c',
'notmuch.c',
'notmuch-config.c',
'notmuch-dump.c',
'notmuch-new.c',
'notmuch-reply.c',
'notmuch-restore.c',
'notmuch-search.c',
'notmuch-setup.c',
'notmuch-show.c',
'notmuch-tag.c',
'notmuch-time.c',
'query-string.c',
'show-message.c',
libnotmuch])
env.Alias('all', notmuch)
env.Install('${DESTDIR}${bindir}', notmuch)
env.Alias('install', '${DESTDIR}${bindir}')
manpage = env.Command('notmuch.1.gz', 'notmuch.1', '${gzip} -9 < $SOURCE > $TARGET')
env.Alias('all', manpage)
env.InstallPerm('${DESTDIR}${mandir}/man1', manpage, 0644)
env.Alias('install', '${DESTDIR}${mandir}/man1')
env.InstallAsPerm('${DESTDIR}${bash_completion_dir}/notmuch', 'contrib/notmuch-completion.bash', 0644)
env.Alias('install', '${DESTDIR}${bash_completion_dir}')
if desktop:
env.Command('${DESTDIR}${desktop_dir}/notmuch.desktop', 'notmuch.desktop', 'desktop-file-install --mode 0644 --dir ${DESTDIR}${desktop_dir} ${SOURCE}')
env.Alias('install-desktop', '${DESTDIR}${desktop_dir}')
if emacs:
elisp = env.Command('notmuch.elc', 'notmuch.el', '${emacs} --no-window-system --no-site-file --no-init-file --no-splash --batch --funcall batch-byte-compile $SOURCE')
env.Alias('emacs', elisp)
env.InstallPerm('${DESTDIR}${emacs_lispdir}', elisp, 0644)
env.InstallPerm('${DESTDIR}${emacs_lispdir}', 'notmuch.el', 0644)
env.Alias('install-emacs', '${DESTDIR}${emacs_lispdir}')
Default('all')
|