8
EnsureSConsVersion( 0, 97 )
9
SConsignFile('scons.signatures');
11
opt = Options(None, ARGUMENTS)
13
(EnumOption ('BUILD', 'build environment', 'debug', ('release', 'debug', 'profile'))),
14
(EnumOption ('BRANCH', 'branch prediction', 'none', ('none', 'profile', 'seed'))),
15
(EnumOption ('COVERAGE', 'test coverage', 'none', ('none', 'full'))),
16
(EnumOption ('WITH_HISTOGRAMS', 'Runtime statistical information', 'true', ('true', 'false'))),
17
(EnumOption ('WITH_HTTP', 'HTTP administration', 'true', ('true', 'false'))),
18
(EnumOption ('WITH_SNMP', 'SNMP administration', 'true', ('true', 'false'))),
19
(EnumOption ('WITH_CHECK', 'Check test system', 'false', ('true', 'false'))),
20
(EnumOption ('WITH_TEST', 'Network test system', 'false', ('true', 'false'))),
21
(EnumOption ('WITH_EXAMPLES', 'Examples', 'true', ('true', 'false'))),
22
(EnumOption ('WITH_NCURSES', 'NCURSES examples', 'false', ('true', 'false'))),
23
(EnumOption ('WITH_PROTOBUF', 'Google Protocol Buffer examples', 'false', ('true', 'false'))),
24
(EnumOption ('WITH_PLUS', 'libpgmplus GPL library', 'false', ('true', 'false'))),
27
#-----------------------------------------------------------------------------
32
def CheckPKGConfig(context, version):
33
context.Message( 'Checking for pkg-config... ' )
34
ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
38
def CheckPKG(context, name):
39
context.Message( 'Checking for %s... ' % name )
40
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
44
conf = Configure(env, custom_tests = { 'CheckPKGConfig' : CheckPKGConfig,
45
'CheckPKG' : CheckPKG })
47
if not conf.CheckPKGConfig('0.15.0'):
48
print 'pkg-config >= 0.15.0 not found.'
51
if not conf.CheckPKG('glib-2.0 >= 2.10'):
52
print 'glib-2.0 >= 2.10 not found.'
55
if not conf.CheckPKG('gthread-2.0'):
56
print 'gthread-2.0 not found.'
61
#-----------------------------------------------------------------------------
64
env = Environment(ENV = os.environ,
70
'-Wunsafe-loop-optimizations',
72
'-Wbad-function-cast',
77
'-Wstrict-prototypes',
78
'-Wold-style-definition',
79
'-Wmissing-prototypes',
80
'-Wmissing-declarations',
82
'-Wmissing-format-attribute',
88
'--param', 'max-inline-insns-single=600',
92
'-DCONFIG_16BIT_CHECKSUM',
94
'-DCONFIG_HAVE_BACKTRACE',
95
'-DCONFIG_HAVE_PSELECT',
97
'-DCONFIG_HAVE_EPOLL',
98
'-DCONFIG_HAVE_CLOCK_GETTIME',
99
'-DCONFIG_HAVE_CLOCK_NANOSLEEP',
100
'-DCONFIG_HAVE_NANOSLEEP',
101
'-DCONFIG_HAVE_USLEEP',
104
'-DCONFIG_HAVE_IFR_NETMASK',
105
'-DCONFIG_HAVE_GETIFADDRS',
106
'-DCONFIG_HAVE_GETHOSTBYNAME2',
107
'-DCONFIG_HAVE_GETPROTOBYNAME_R',
108
'-DCONFIG_HAVE_MCAST_JOIN',
109
'-DCONFIG_HAVE_IP_MREQN',
110
'-DCONFIG_HAVE_DSO_VISIBILITY',
111
'-DCONFIG_BIND_INADDR_ANY',
112
'-DCONFIG_GALOIS_MUL_LUT',
114
LINKFLAGS = [ '-pipe',
121
if env['BRANCH'] == 'profile':
122
env.Append(CCFLAGS = '-fprofile-arcs')
123
env.Append(LINKFLAGS = '-fprofile-arcs')
124
elif env['BRANCH'] == 'seed':
125
env.Append(CCFLAGS = '-fbranch-probabilities')
128
if env['COVERAGE'] == 'full':
129
env.Append(CCFLAGS = '-fprofile-arcs')
130
env.Append(CCFLAGS = '-ftest-coverage')
131
env.Append(LINKFLAGS = '-fprofile-arcs')
132
env.Append(LINKFLAGS = '-lgcov')
134
# Define separate build environments
135
release = env.Clone(BUILD = 'release')
136
release.Append(CCFLAGS = '-O2')
138
debug = env.Clone(BUILD = 'debug')
139
debug.Append(CCFLAGS = '-ggdb', LINKFLAGS = '-gdb')
141
profile = env.Clone(BUILD = 'profile')
142
profile.Append(CCFLAGS = ['-O2','-pg'], LINKFLAGS = '-pg')
144
thirtytwo = release.Clone(BUILD = 'thirtytwo')
145
thirtytwo.Append(CCFLAGS = '-m32', LINKFLAGS = '-m32')
147
# choose and environment to build
148
if env['BUILD'] == 'release':
149
Export({'env':release})
150
elif env['BUILD'] == 'profile':
151
Export({'env':profile})
152
elif env['BUILD'] == 'thirtytwo':
153
Export({'env':thirtytwo})
155
Export({'env':debug})
157
#-----------------------------------------------------------------------------
158
# Re-analyse dependencies
162
# vanilla environment
163
env.ParseConfig('pkg-config --cflags --libs glib-2.0 gthread-2.0');
166
if env['WITH_HTTP'] == 'true' and env['WITH_HISTOGRAMS'] == 'true':
167
env.Append(CCFLAGS = '-DCONFIG_HISTOGRAMS');
169
# managed environment for libpgmsnmp, libpgmhttp
170
env['SNMP_FLAGS'] = {
172
'LIBS' : [ 'netsnmpagent', 'netsnmpmibs', 'netsnmphelpers', 'netsnmp' ],
175
def CheckSNMP(context):
176
context.Message('Checking Net-SNMP...');
177
lastLIBS = context.env['LIBS'];
178
lastCCFLAGS= context.env['CCFLAGS'];
179
context.env.MergeFlags(env['SNMP_FLAGS']);
180
result = context.TryLink("""
181
int main(int argc, char**argv)
187
context.env.Replace(LIBS = lastLIBS, CCFLAGS=lastCCFLAGS);
188
context.Result(not result);
191
def CheckCheck(context):
192
context.Message('Checking Check unit test framework...');
193
result = context.TryAction('pkg-config --cflags --libs check')[0];
194
context.Result(result);
197
def CheckEventFD(context):
198
context.Message('Checking eventfd...');
199
result = context.TryLink("""
200
#include <sys/eventfd.h>
201
int main(int argc, char**argv)
207
context.Result(result);
211
'CheckCheck': CheckCheck,
212
'CheckEventFD': CheckEventFD
214
if env['WITH_SNMP'] == 'true':
215
tests['CheckSNMP'] = CheckSNMP;
216
conf = Configure(env, custom_tests = tests);
218
if env['WITH_SNMP'] == 'true' and not conf.CheckSNMP():
219
print 'Enabling extra Red Hat dependencies for Net-SNMP.';
220
conf.env['SNMP_FLAGS']['LIBS'].append(['librpm', 'libsensors', 'libdl', 'libwrap']);
221
lastLIBS = conf.env['LIBS'];
222
conf.env.ParseConfig('perl -MExtUtils::Embed -e ldopts');
223
conf.env['SNMP_FLAGS']['LIBS'].append(conf.env['LIBS']);
224
conf.env.Replace(LIBS = lastLIBS);
225
if not conf.CheckSNMP():
226
print 'Net-SNMP libraries not compatible.';
229
if env['WITH_CHECK'] == 'true' and conf.CheckCheck():
230
print 'Enabling Check unit tests.';
231
conf.env['CHECK'] = 'true';
232
env['CHECK_FLAGS'] = env.ParseFlags('!pkg-config --cflags --libs check');
234
print 'Disabling Check unit tests.';
235
conf.env['CHECK'] = 'false';
237
if conf.CheckEventFD():
238
print 'Enabling kernel eventfd notification mechanism.';
239
conf.env.Append(CCFLAGS = '-DCONFIG_EVENTFD');
243
# DSO visibility flags
244
if '-DCONFIG_HAVE_DSO_VISIBILITY' in env['CCFLAGS']:
245
env.Append(CCFLAGS = '-DPGM_GNUC_INTERNAL=G_GNUC_INTERNAL')
247
env.Append(CCFLAGS = '-DPGM_GNUC_INTERNAL=')
249
# add builder to create PIC static libraries for including in shared libraries
250
action_list = [ Action("$ARCOM", "$ARCOMSTR") ];
251
if env.Detect('ranlib'):
252
ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR");
253
action_list.append(ranlib_action);
254
pic_lib = Builder( action = action_list,
255
emitter = '$LIBEMITTER',
256
prefix = '$LIBPREFIX',
257
suffix = '$LIBSUFFIX',
258
src_suffix = '$OBJSUFFIX',
259
src_builder = 'SharedObject')
260
env.Append(BUILDERS = {'StaticSharedLibrary': pic_lib});
263
#-----------------------------------------------------------------------------
265
ref_node = 'ref/' + env['BUILD'] + '/';
266
BuildDir(ref_node, '.', duplicate=0)
268
env.Append(CPPPATH = os.getcwd() + '/include');
269
env.Append(LIBPATH = os.getcwd() + '/' + ref_node);
271
SConscript(ref_node + 'SConscript.libpgm');
272
SConscript(ref_node + 'SConscript.libpgmex');
273
if env['WITH_HTTP'] == 'true':
274
SConscript(ref_node + 'SConscript.libpgmhttp');
275
if env['WITH_SNMP'] == 'true':
276
SConscript(ref_node + 'SConscript.libpgmsnmp');
277
if env['WITH_TEST'] == 'true':
278
SConscript(ref_node + 'test/SConscript');
279
if env['WITH_EXAMPLES'] == 'true':
280
SConscript(ref_node + 'examples/SConscript');