-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
359 lines (267 loc) · 10.9 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import subprocess
import string
import glob
import sys
if sys.version_info.major <= 2:
import commands
EnsureSConsVersion(1, 2)
APP_NAME = 'freedcpp'
LIB_DCPP = 'libdcpp'
LIB_UPNP = 'libminiupnpc'
BUILD_PATH = '#/build/'
BUILD_LOCALE_PATH = 'build/locale/'
LIB_IS_UPNP = True
# ----------------------------------------------------------------------
# Function definitions
# ----------------------------------------------------------------------
def CheckPKGConfig(context):
context.Message('Checking for pkg-config... ')
ret = context.TryAction('pkg-config --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
def CheckCXXVersion(context, name, major, minor):
context.Message('Checking for %s >= %d.%d...' % (name, major, minor))
if sys.version_info.major <= 2:
ret = commands.getoutput('%s -dumpversion' % name)
else:
ret = subprocess.getoutput('%s -dumpversion' % name)
retval = 0
try:
if ((int(ret[0]) == major and int(ret[2]) >= minor)
or (int(ret[0]) > major) or (int(ret) > major)):
retval = 1
except ValueError:
print("No C++ compiler found!")
context.Result(retval)
return retval
# ----------------------------------------------------------------------
# Command-line options
# ----------------------------------------------------------------------
# Parameters are only sticky from scons -> scons install, otherwise they're cleared.
if 'install' in COMMAND_LINE_TARGETS:
vars = Variables('build/sconf/scache.conf')
else:
vars = Variables()
vars.AddVariables(
BoolVariable('debug', 'Compile the program with debug information', 0),
BoolVariable('release', 'Compile the program with optimizations', 0),
BoolVariable('profile', 'Compile the program with profiling information', 0),
PathVariable('PREFIX', 'Compile the program with PREFIX as the root for installation', '/usr/local'),
('FAKE_ROOT', 'Make scons install the program under a fake root (for gentoo ebuilds)', '')
)
# ----------------------------------------------------------------------
# Initialization
# ----------------------------------------------------------------------
env = Environment(ENV = os.environ, options = vars)
conf = Configure(env,
custom_tests =
{
'CheckPKGConfig' : CheckPKGConfig,
'CheckPKG' : CheckPKG,
'CheckCXXVersion' : CheckCXXVersion
},
conf_dir = 'build/sconf',
log_file = 'build/sconf/config.log')
if 'CXX' in os.environ:
conf.env['CXX'] = os.environ['CXX']
if 'CC' in os.environ:
conf.env['CC'] = os.environ['CC']
if 'CXXFLAGS' in os.environ:
conf.env['CPPFLAGS'] = conf.env['CXXFLAGS'] = os.environ['CXXFLAGS'].split()
if 'LDFLAGS' in os.environ:
conf.env['LINKFLAGS'] = os.environ['LDFLAGS'].split()
if 'CFLAGS' in os.environ:
conf.env['CFLAGS'] = os.environ['CFLAGS'].split()
env.SConsignFile('build/sconf/.sconsign')
vars.Save('build/sconf/scache.conf', env)
Help(vars.GenerateHelpText(env))
# ----------------------------------------------------------------------
# Dependencies
# ----------------------------------------------------------------------
if not 'install' in COMMAND_LINE_TARGETS:
if not ('CXX' in conf.env and conf.env['CXX']):
print('CXX env variable is not set, attempting to use g++')
conf.env['CXX'] = 'g++'
if not conf.CheckCXXVersion(env['CXX'], 4, 1):
print('Compiler version check failed. g++ 4.1 or later is needed')
Exit(1)
if not conf.CheckPKGConfig():
print('\tpkg-config not found.')
Exit(1)
if not conf.CheckPKG('gtk+-2.0 >= 2.10'):
print('\tgtk+ >= 2.10 not found.')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckPKG('gthread-2.0 >= 2.4'):
print('\tgthread >= 2.4 not found.')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckPKG('libglade-2.0 >= 2.4'):
print('\tlibglade-2.0 >= 2.4 not found.')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckPKG('libcanberra-gtk >= 0.30'):
print('\tlibcanberra-gtk >= 0.30 not found.')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckPKG('libnotify >= 0.4.1'):
print('\tlibnotify >= 0.4.1 not found.')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckCXXHeader('boost/version.hpp', '<>'):
print('\tboost not found.')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckHeader('time.h'):
Exit(1)
if not conf.CheckHeader('signal.h'):
Exit(1)
if not conf.CheckHeader('unistd.h'):
Exit(1)
if not conf.CheckLibWithHeader('pthread', 'pthread.h', 'c'):
print('\tpthread library not found')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckLibWithHeader('z', 'zlib.h', 'c'):
print('\tz library (gzip/z compression) not found')
print('\tNote: You might have the lib but not the headers')
Exit(1)
if not conf.CheckLibWithHeader('bz2', 'bzlib.h', 'c'):
print('\tbz2 library (bz2 compression) not found')
print('\tNote: You might have the lib but not the headers')
Exit(1)
# This needs to be before ssl check on *BSD systems
if not conf.CheckLib('crypto'):
print('\tcrypto library not found')
print('\tNote: This library may be a part of libssl on your system')
Exit(1)
if not conf.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'c'):
print('\tOpenSSL library (libssl) not found')
print('\tNote: You might have the lib but not the headers')
Exit(1)
# Needed for XFlush(). Headers shouldn't be needed since we include gdk/gdkx.h
if not conf.CheckLib('X11'):
print('\tX11 library not found')
Exit(1)
if not conf.CheckHeader('iconv.h'):
Exit(1)
elif conf.CheckLibWithHeader('iconv', 'iconv.h', 'c', 'iconv(0, (const char **)0, 0, (char**)0, 0);'):
conf.env['ICONV_CONST'] = 'const'
if conf.CheckHeader(['sys/types.h', 'sys/socket.h', 'ifaddrs.h', 'net/if.h']):
conf.env['HAVE_IFADDRS_H'] = True
# MiniUPnPc for UPnP
if not conf.CheckLib('libminiupnpc'):
LIB_IS_UPNP = False
env = conf.Finish()
# ----------------------------------------------------------------------
# Compile and link flags
# ----------------------------------------------------------------------
# todo: remove -fpermissive and fix the errors
env.Append(CXXFLAGS = ['-I.', '-D_GNU_SOURCE', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_REENTRANT', '-fpermissive', '-std=gnu++14'])
if os.sys.platform == 'linux2':
env.Append(LINKFLAGS = ['-Wl,--as-needed'])
if os.name == 'mac' or os.sys.platform == 'darwin':
env['ICONV_CONST'] = ''
if os.sys.platform == 'sunos5':
env['ICONV_CONST'] = 'const'
env.Append(LINKFLAGS = ['-lsocket', '-lnsl'])
if 'ICONV_CONST' in env and env['ICONV_CONST']:
env.Append(CXXFLAGS = '-DICONV_CONST=' + env['ICONV_CONST'])
if 'HAVE_IFADDRS_H' in env:
env.Append(CXXFLAGS = '-DHAVE_IFADDRS_H')
if 'debug' in env and env['debug']:
env.Append(CXXFLAGS = ['-g', '-ggdb', '-D_DEBUG', '-Wall'])
env.Append(LINKFLAGS = ['-g', '-ggdb' '-Wall'])
BUILD_PATH = BUILD_PATH + 'debug/'
elif 'release' in env and env['release']:
env.Append(CXXFLAGS = ['-O3', '-fomit-frame-pointer', '-DNDEBUG'])
BUILD_PATH = BUILD_PATH + 'release/'
else: BUILD_PATH = BUILD_PATH + 'default/'
if 'profile' in env and env['profile']:
env.Append(CXXFLAGS = '-pg')
env.Append(LINKFLAGS= '-pg')
if 'PREFIX' in env and env['PREFIX']:
env.Append(CXXFLAGS = '-D_DATADIR=\'\"' + env['PREFIX'] + '/share' + '\"\'')
env.ParseConfig('pkg-config --libs libglade-2.0')
env.ParseConfig('pkg-config --libs libcanberra-gtk')
env.ParseConfig('pkg-config --libs libnotify')
env.ParseConfig('pkg-config --libs gthread-2.0')
env.Append(LIBPATH = [BUILD_PATH + LIB_DCPP])
env.Prepend(LIBS = [LIB_DCPP])
if not LIB_IS_UPNP:
env.Append(LIBPATH = [BUILD_PATH + LIB_UPNP])
env.Prepend(LIBS = [LIB_UPNP])
mo_args = ['msgfmt', '-c', '-o', '$TARGET', '$SOURCE']
mo_bld = Builder(action = Action([mo_args], 'Create $TARGET from $SOURCE'))
env.Append(BUILDERS = {'MoBuild' : mo_bld})
# ----------------------------------------------------------------------
# Build
# ----------------------------------------------------------------------
Export('env')
# Build the miniupnpc library
if not LIB_IS_UPNP:
upnp = SConscript(dirs = 'miniupnpc', variant_dir = BUILD_PATH + LIB_UPNP, duplicate = 0)
# Build the dcpp library
dcpp = SConscript(dirs = 'dcpp', variant_dir = BUILD_PATH + LIB_DCPP, duplicate = 0)
# Build the GUI
gui = SConscript(dirs = 'linux', variant_dir = BUILD_PATH + APP_NAME, duplicate = 0)
# Create the executable
if not LIB_IS_UPNP:
env.Program(target = APP_NAME, source = [dcpp, upnp, gui])
else:
env.Program(target = APP_NAME, source = [dcpp, gui])
# ----------------------------------------------------------------------
# Install
# ----------------------------------------------------------------------
else:
glade_files = glob.glob('glade/*.glade')
text_files = glob.glob('*.txt')
prefix = env['FAKE_ROOT'] + os.path.join(env['PREFIX'], 'share')
mo_files = []
locale = []
# freedcpp gui
path = BUILD_LOCALE_PATH + APP_NAME + '/'
languages = os.listdir(path)
for lang in languages:
locale.append(os.path.join(prefix, 'locale', lang, 'LC_MESSAGES', APP_NAME + '.mo'))
mo_files.append(path + lang)
# dcpp library
path = BUILD_LOCALE_PATH + LIB_DCPP + '/'
languages = os.listdir(path)
for lang in languages:
locale.append(os.path.join(prefix, 'locale', lang, 'LC_MESSAGES', LIB_DCPP + '.mo'))
mo_files.append(path + lang)
target_icons = []
source_icons = []
for root, dirs, files in os.walk('icons/hicolor/'):
for file in files:
filename = file.rsplit('.', 1)
if (len(filename) == 2):
if (filename[1] == 'png'):
target_icons.append(os.path.join(prefix, APP_NAME, root, file))
source_icons.append(os.path.join(root, file))
elif filename[1] == 'svg':
target_icons.append(os.path.join(prefix, APP_NAME, root, file))
source_icons.append(os.path.join(root, file))
# install glade files
env.Alias('install', env.Install(dir = env['FAKE_ROOT'] + env['PREFIX'] + '/share/' + APP_NAME + '/glade', source = glade_files))
# install icons
env.Alias('install', env.InstallAs(target = target_icons, source = source_icons))
# install pixmap file
env.Alias('install', env.Install(dir = env['FAKE_ROOT'] + env['PREFIX'] + '/share/pixmaps/', source = 'icons/' + APP_NAME + '.xpm'))
# install text files
env.Alias('install', env.Install(dir = env['FAKE_ROOT'] + env['PREFIX'] + '/share/doc/' + APP_NAME, source = text_files))
# install desktop file
env.Alias('install', env.Install(dir = env['FAKE_ROOT'] + env['PREFIX'] + '/share/applications/', source = APP_NAME + '.desktop'))
# install app file
env.Alias('install', env.Install(dir = env['FAKE_ROOT'] + env['PREFIX'] + '/bin', source = APP_NAME))
# install locale
env.Alias('install', env.InstallAs(target = locale, source = mo_files))