summaryrefslogtreecommitdiffstats
path: root/3rdparty/openpgm-svn-r1085/pgm/SConstruct.RHEL4
blob: 1637ea5d80ddf8e4ebf1089255d134c6c634290a (plain) (blame)
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
# -*- mode: python -*-
# OpenPGM build script

import os
import time
import sys

EnsureSConsVersion( 0, 97 )
SConsignFile('scons.signatures');

opt = Options(None, ARGUMENTS)
opt.AddOptions (
	(EnumOption ('BUILD', 'build environment', 'debug', ('release', 'debug', 'profile'))),
	(EnumOption ('BRANCH', 'branch prediction', 'none', ('none', 'profile', 'seed'))),
	(EnumOption ('COVERAGE', 'test coverage', 'none', ('none', 'full'))),
	(EnumOption ('WITH_HISTOGRAMS', 'Runtime statistical information', 'true', ('true', 'false'))),
	(EnumOption ('WITH_HTTP', 'HTTP administration', 'true', ('true', 'false'))),
	(EnumOption ('WITH_SNMP', 'SNMP administration', 'true', ('true', 'false'))),
	(EnumOption ('WITH_CHECK', 'Check test system', 'false', ('true', 'false'))),
	(EnumOption ('WITH_TEST', 'Network test system', 'false', ('true', 'false'))),
	(EnumOption ('WITH_EXAMPLES', 'Examples', 'true', ('true', 'false'))),
	(EnumOption ('WITH_NCURSES', 'NCURSES examples', 'false', ('true', 'false'))),
	(EnumOption ('WITH_PROTOBUF', 'Google Protocol Buffer examples', 'false', ('true', 'false'))),
	(EnumOption ('WITH_PLUS', 'libpgmplus GPL library', 'false', ('true', 'false'))),
)

#-----------------------------------------------------------------------------
# Dependencies

env = Environment();

def CheckPKGConfig(context, version):
	context.Message( 'Checking for pkg-config... ' )
	ret = context.TryAction('PKG_CONFIG_PATH=/usr/evolution28/lib/pkgconfig:/usr/lib/pkconfig 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_PATH=/usr/evolution28/lib/pkgconfig:/usr/lib/pkconfig pkg-config --exists \'%s\'' % name)[0]
	context.Result( ret )
	return ret

conf = Configure(env, custom_tests = { 'CheckPKGConfig' : CheckPKGConfig,
				       'CheckPKG' : CheckPKG })

if not conf.CheckPKGConfig('0.15.0'):
	print 'pkg-config >= 0.15.0 not found.'
	Exit(1)

if not conf.CheckPKG('glib-2.0 >= 2.10'):
	print 'glib-2.0 >= 2.10 not found.'
	Exit(1)

if not conf.CheckPKG('gthread-2.0'):
	print 'gthread-2.0 not found.'
	Exit(1)

env = conf.Finish();

#-----------------------------------------------------------------------------
# Platform specifics

env = Environment(ENV = os.environ,
	CCFLAGS = [	'-pipe',
			'-Wall',
				'-Wextra',
				'-Wfloat-equal',
				'-Wshadow',
				'-Wpointer-arith',
				'-Wbad-function-cast',
				'-Wcast-qual',
				'-Wcast-align',
				'-Wwrite-strings',
				'-Waggregate-return',
				'-Wstrict-prototypes',
				'-Wold-style-definition',
				'-Wmissing-prototypes',
				'-Wmissing-declarations',
				'-Wmissing-noreturn',
				'-Wmissing-format-attribute',
				'-Wredundant-decls',
				'-Wnested-externs',
				'-Winline',
			'-pedantic',
			'-std=gnu99',
			'--param', 'max-inline-insns-single=600',
			'-D_REENTRANT',
			'-D_GNU_SOURCE',
			'-D__need_IOV_MAX',
			'-DCONFIG_16BIT_CHECKSUM',
			'-DCONFIG_HAVE_PROC',
			'-DCONFIG_HAVE_BACKTRACE',
			'-DCONFIG_HAVE_PSELECT',
			'-DCONFIG_HAVE_POLL',
			'-DCONFIG_HAVE_EPOLL',
			'-DCONFIG_HAVE_CLOCK_GETTIME',
			'-DCONFIG_HAVE_CLOCK_NANOSLEEP',
			'-DCONFIG_HAVE_NANOSLEEP',
			'-DCONFIG_HAVE_USLEEP',
			'-DCONFIG_HAVE_RTC',
			'-DCONFIG_HAVE_TSC',
			'-DCONFIG_HAVE_GETIFADDRS',
			'-DCONFIG_HAVE_GETHOSTBYNAME2',
			'-DCONFIG_HAVE_GETPROTOBYNAME_R',
			'-DCONFIG_HAVE_MCAST_JOIN',
			'-DCONFIG_HAVE_IP_MREQN',
			'-DCONFIG_HAVE_DSO_VISIBILITY',
			'-DCONFIG_BIND_INADDR_ANY',
			'-DCONFIG_GALOIS_MUL_LUT',
		 ],
	LINKFLAGS = [	'-pipe',
			'-lm'
		    ]
)
opt.Update (env)

# Branch prediction
if env['BRANCH'] == 'profile':
	env.Append(CCFLAGS = '-fprofile-arcs')
	env.Append(LINKFLAGS = '-fprofile-arcs')
elif env['BRANCH'] == 'seed':
	env.Append(CCFLAGS = '-fbranch-probabilities')

# Coverage analysis
if env['COVERAGE'] == 'full':
	env.Append(CCFLAGS = '-fprofile-arcs')
	env.Append(CCFLAGS = '-ftest-coverage')
	env.Append(LINKFLAGS = '-fprofile-arcs')
	env.Append(LINKFLAGS = '-lgcov')

# Define separate build environments
release = env.Clone(BUILD = 'release')
release.Append(CCFLAGS = '-O2')

debug = env.Clone(BUILD = 'debug')
debug.Append(CCFLAGS = '-ggdb', LINKFLAGS = '-gdb')

profile = env.Clone(BUILD = 'profile')
profile.Append(CCFLAGS = ['-O2','-pg'], LINKFLAGS = '-pg')

thirtytwo = release.Clone(BUILD = 'thirtytwo')
thirtytwo.Append(CCFLAGS = '-m32', LINKFLAGS = '-m32')

# choose and environment to build
if env['BUILD'] == 'release':
	Export({'env':release})
elif env['BUILD'] == 'profile':
	Export({'env':profile})
elif env['BUILD'] == 'thirtytwo':
	Export({'env':thirtytwo})
else:
	Export({'env':debug})

#-----------------------------------------------------------------------------
# Re-analyse dependencies

Import('env')

# vanilla environment
env.ParseConfig('PKG_CONFIG_PATH=/usr/evolution28/lib/pkgconfig:/usr/lib/pkconfig pkg-config --cflags --libs glib-2.0 gthread-2.0');

# instrumentation
if env['WITH_HTTP'] == 'true' and env['WITH_HISTOGRAMS'] == 'true':
	env.Append(CCFLAGS = '-DCONFIG_HISTOGRAMS');

# managed environment for libpgmsnmp, libpgmhttp
env['SNMP_FLAGS'] = { 
        'CCFLAGS'       : [],
        'LIBS'          : [ 'netsnmpagent', 'netsnmpmibs', 'netsnmphelpers', 'netsnmp' ],
};

def CheckSNMP(context):
	context.Message('Checking Net-SNMP...');
	lastLIBS = context.env['LIBS'];
	lastCCFLAGS= context.env['CCFLAGS'];
	context.env.MergeFlags(env['SNMP_FLAGS']);
	result = context.TryLink("""
int main(int argc, char**argv)
{
	init_agent("PGM");
	return 0;
}
""", '.c');
	context.env.Replace(LIBS = lastLIBS, CCFLAGS=lastCCFLAGS);
	context.Result(not result);
	return result;

def CheckCheck(context):
	context.Message('Checking Check unit test framework...');
	result = context.TryAction('pkg-config --cflags --libs check')[0];
	context.Result(result);
	return result;

def CheckEventFD(context):
	context.Message('Checking eventfd...');
	result = context.TryLink("""
#include <sys/eventfd.h>
int main(int argc, char**argv)
{
	eventfd(0,0);
	return 0;
}
""", '.c')
	context.Result(result);
	return result;

tests = {
	'CheckCheck':	CheckCheck,
	'CheckEventFD':	CheckEventFD
}
if env['WITH_SNMP'] == 'true':
	tests['CheckSNMP'] = CheckSNMP;
conf = Configure(env, custom_tests = tests);

if env['WITH_SNMP'] == 'true' and not conf.CheckSNMP():
	print 'Enabling extra Red Hat dependencies for Net-SNMP.';
	conf.env['SNMP_FLAGS']['LIBS'].append(['librpm', 'libsensors', 'libdl', 'libwrap']);
	lastLIBS = conf.env['LIBS'];
	conf.env.ParseConfig('perl -MExtUtils::Embed -e ldopts');
	conf.env['SNMP_FLAGS']['LIBS'].append(conf.env['LIBS']);
	conf.env.Replace(LIBS = lastLIBS);
	if not conf.CheckSNMP():
		print 'Net-SNMP libraries not compatible.';
		Exit(1);

if env['WITH_CHECK'] == 'true' and conf.CheckCheck():
	print 'Enabling Check unit tests.';
	conf.env['CHECK'] = 'true';
else:
	print 'Disabling Check unit tests.';
	conf.env['CHECK'] = 'false';

if conf.CheckEventFD():
	print 'Enabling kernel eventfd notification mechanism.';
	conf.env.Append(CCFLAGS = '-DCONFIG_EVENTFD');

env = conf.Finish();

# DSO visibility flags
if '-DCONFIG_HAVE_DSO_VISIBILITY' in env['CCFLAGS']:
	env.Append(CCFLAGS = '-DPGM_GNUC_INTERNAL=G_GNUC_INTERNAL')
else:
	env.Append(CCFLAGS = '-DPGM_GNUC_INTERNAL=')

# add builder to create PIC static libraries for including in shared libraries
action_list = [ Action("$ARCOM", "$ARCOMSTR") ];
if env.Detect('ranlib'):
	ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR");
	action_list.append(ranlib_action);
pic_lib = Builder(	action = action_list,
			emitter = '$LIBEMITTER',
			prefix = '$LIBPREFIX',
			suffix = '$LIBSUFFIX',
			src_suffix = '$OBJSUFFIX',
			src_builder = 'SharedObject')
env.Append(BUILDERS = {'StaticSharedLibrary': pic_lib});


#-----------------------------------------------------------------------------

ref_node = 'ref/' + env['BUILD'] + '/';
BuildDir(ref_node, '.', duplicate=0)

env.Append(CPPPATH = os.getcwd() + '/include');
env.Append(LIBPATH = os.getcwd() + '/' + ref_node);

SConscript(ref_node + 'SConscript.libpgm');
SConscript(ref_node + 'SConscript.libpgmex');
if env['WITH_HTTP'] == 'true':
	SConscript(ref_node + 'SConscript.libpgmhttp');
if env['WITH_SNMP'] == 'true':
	SConscript(ref_node + 'SConscript.libpgmsnmp');
if env['WITH_TEST'] == 'true':
	SConscript(ref_node + 'test/SConscript');
if env['WITH_EXAMPLES'] == 'true':
	SConscript(ref_node + 'examples/SConscript');

# end of file