Debian Codegraph @

openpgm/pgm/SConstruct.FreeBSD80

raw
1 # -*- mode: python -*-
2 # OpenPGM build script
3
4 import platform
5 import os
6 import time
7 import sys
8
9 EnsureSConsVersion( 1, 0 )
10 SConsignFile('scons.signatures' + '-' + platform.system() + '-' + platform.machine());
11
12 vars = Variables()
13 vars.AddVariables (
14 EnumVariable ('BUILD', 'build environment', 'debug',
15 allowed_values=('release', 'debug', 'profile')),
16 EnumVariable ('BRANCH', 'branch prediction', 'none',
17 allowed_values=('none', 'profile', 'seed')),
18 EnumVariable ('WITH_GETTEXT', 'l10n support via libintl', 'false',
19 allowed_values=('true', 'false')),
20 EnumVariable ('WITH_GLIB', 'Build GLib dependent modules', 'false',
21 allowed_values=('true', 'false')),
22 EnumVariable ('COVERAGE', 'test coverage', 'none',
23 allowed_values=('none', 'full')),
24 EnumVariable ('WITH_HISTOGRAMS', 'Runtime statistical information', 'true',
25 allowed_values=('true', 'false')),
26 EnumVariable ('WITH_HTTP', 'HTTP administration', 'false',
27 allowed_values=('true', 'false')),
28 EnumVariable ('WITH_SNMP', 'SNMP administration', 'false',
29 allowed_values=('true', 'false')),
30 EnumVariable ('WITH_CHECK', 'Check test system', 'false',
31 allowed_values=('true', 'false')),
32 EnumVariable ('WITH_TEST', 'Network test system', 'false',
33 allowed_values=('true', 'false')),
34 EnumVariable ('WITH_CC', 'C++ examples', 'true',
35 allowed_values=('true', 'false')),
36 EnumVariable ('WITH_EXAMPLES', 'Examples', 'true',
37 allowed_values=('true', 'false')),
38 EnumVariable ('WITH_NCURSES', 'NCURSES examples', 'false',
39 allowed_values=('true', 'false')),
40 EnumVariable ('WITH_PROTOBUF', 'Google Protocol Buffer examples', 'false',
41 allowed_values=('true', 'false')),
42 )
43
44 #-----------------------------------------------------------------------------
45 # Dependencies
46
47 env = Environment();
48
49 def CheckPKGConfig(context, version):
50 context.Message( 'Checking for pkg-config... ' )
51 ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
52 context.Result( ret )
53 return ret
54
55 def CheckPKG(context, name):
56 context.Message( 'Checking for %s... ' % name )
57 ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
58 context.Result( ret )
59 return ret
60
61 conf = Configure(env, custom_tests = { 'CheckPKGConfig' : CheckPKGConfig,
62 'CheckPKG' : CheckPKG })
63
64 if not conf.CheckPKGConfig('0.15.0'):
65 print 'pkg-config >= 0.15.0 not found.'
66 # Exit(1)
67
68 if not conf.CheckPKG('glib-2.0 >= 2.10'):
69 print 'glib-2.0 >= 2.10 not found.'
70 # Exit(1)
71
72 if not conf.CheckPKG('gthread-2.0'):
73 print 'gthread-2.0 not found.'
74 # Exit(1)
75
76 env = conf.Finish();
77
78 #-----------------------------------------------------------------------------
79 # Platform specifics
80
81 env = Environment(
82 variables = vars,
83 ENV = os.environ,
84 CCFLAGS = [ '-pipe',
85 '-Wall',
86 '-Wextra',
87 '-Wfloat-equal',
88 '-Wshadow',
89 '-Wunsafe-loop-optimizations',
90 '-Wpointer-arith',
91 '-Wbad-function-cast',
92 '-Wcast-qual',
93 '-Wcast-align',
94 '-Wwrite-strings',
95 '-Waggregate-return',
96 '-Wstrict-prototypes',
97 '-Wold-style-definition',
98 '-Wmissing-prototypes',
99 '-Wmissing-declarations',
100 '-Wmissing-noreturn',
101 '-Wmissing-format-attribute',
102 '-Wredundant-decls',
103 '-Wnested-externs',
104 # '-Winline',
105 '-Wno-inline',
106 '-Wno-unused-function',
107 '-pedantic',
108 # Native arch
109 '-march=native',
110 # C99
111 '-std=gnu99',
112 # re-entrant libc
113 '-D_REENTRANT',
114 # POSIX spinlocks
115 '-DCONFIG_HAVE_POSIX_SPINLOCK',
116 # NSS protocol lookup
117 # '-DCONFIG_HAVE_GETPROTOBYNAME_R',
118 # '-DCONFIG_HAVE_GETPROTOBYNAME_R2',
119 # NSS networks lookup, IPv4 only
120 '-DCONFIG_HAVE_GETNETENT',
121 # variadic macros
122 '-DCONFIG_HAVE_ISO_VARARGS',
123 # '-DCONFIG_HAVE_GNUC_VARARGS',
124 # stack memory api header
125 # '-DCONFIG_HAVE_ALLOCA_H',
126 # useful /proc system
127 # '-DCONFIG_HAVE_PROC',
128 # example: crash handling
129 # '-DCONFIG_HAVE_BACKTRACE',
130 # timing
131 '-DCONFIG_HAVE_PSELECT',
132 # '-DCONFIG_HAVE_RTC',
133 '-DCONFIG_HAVE_TSC',
134 # '-DCONFIG_HAVE_HPET',
135 # event handling
136 '-DCONFIG_HAVE_POLL',
137 # '-DCONFIG_HAVE_EPOLL',
138 # interface enumeration
139 '-DCONFIG_HAVE_GETIFADDRS',
140 '-DCONFIG_HAVE_IFR_NETMASK',
141 # win32 cmsg
142 # '-DCONFIG_HAVE_WSACMSGHDR',
143 # multicast
144 # '-DCONFIG_HAVE_MCAST_JOIN',
145 '-DCONFIG_HAVE_IP_MREQN',
146 '-DCONFIG_HAVE_IP_MSFILTER',
147 # sprintf
148 '-DCONFIG_HAVE_SPRINTF_GROUPING',
149 '-DCONFIG_HAVE_VASPRINTF',
150 # symbol linking scope
151 '-DCONFIG_HAVE_DSO_VISIBILITY',
152 # socket binding
153 '-DCONFIG_BIND_INADDR_ANY',
154 # IP header order as per IP(4) on FreeBSD
155 '-DCONFIG_HOST_ORDER_IP_LEN',
156 '-DCONFIG_HOST_ORDER_IP_OFF',
157 # ticket based spinlocks
158 '-DCONFIG_TICKET_SPINLOCK',
159 # dumb read-write spinlock
160 '-DCONFIG_DUMB_RWSPINLOCK',
161 # optimum galois field multiplication
162 '-DCONFIG_GALOIS_MUL_LUT',
163 # GNU getopt
164 '-DCONFIG_HAVE_GETOPT'
165 ],
166 LINKFLAGS = [ '-pipe'
167 ],
168 LIBS = [
169 # histogram math
170 'm',
171 # clock_gettime()
172 'rt',
173 # ftime()
174 'compat',
175 # POSIX threads
176 'pthread'
177 ],
178 PROTOBUF_CCFLAGS = '-I/usr/local/include/google/protobuf',
179 PROTOBUF_LIBS = '/usr/local/lib/libprotobuf.a',
180 PROTOBUF_PROTOC = 'protoc'
181 )
182
183 # Branch prediction
184 if env['BRANCH'] == 'profile':
185 env.Append(CCFLAGS = '-fprofile-arcs')
186 env.Append(LINKFLAGS = '-fprofile-arcs')
187 elif env['BRANCH'] == 'seed':
188 env.Append(CCFLAGS = '-fbranch-probabilities')
189
190 # Coverage analysis
191 if env['COVERAGE'] == 'full':
192 env.Append(CCFLAGS = '-fprofile-arcs')
193 env.Append(CCFLAGS = '-ftest-coverage')
194 env.Append(LINKFLAGS = '-fprofile-arcs')
195 env.Append(LINKFLAGS = '-lgcov')
196
197 # Define separate build environments
198 release = env.Clone(BUILD = 'release')
199 release.Append(CCFLAGS = '-O2')
200
201 debug = env.Clone(BUILD = 'debug')
202 debug.Append(CCFLAGS = ['-DPGM_DEBUG','-ggdb'], LINKFLAGS = '-gdb')
203
204 profile = env.Clone(BUILD = 'profile')
205 profile.Append(CCFLAGS = ['-O2','-pg'], LINKFLAGS = '-pg')
206
207 thirtytwo = release.Clone(BUILD = 'thirtytwo')
208 thirtytwo.Append(CCFLAGS = '-m32', LINKFLAGS = '-m32')
209
210 # choose and environment to build
211 if env['BUILD'] == 'release':
212 Export({'env':release})
213 elif env['BUILD'] == 'profile':
214 Export({'env':profile})
215 elif env['BUILD'] == 'thirtytwo':
216 Export({'env':thirtytwo})
217 else:
218 Export({'env':debug})
219
220 #-----------------------------------------------------------------------------
221 # Re-analyse dependencies
222
223 Import('env')
224
225 # vanilla environment
226 if env['WITH_GLIB'] == 'true':
227 # You may need to add -I${includedir} to Cflags in glib-2.0.pc for gi18n-lib
228 env['GLIB_FLAGS'] = env.ParseFlags('!pkg-config --cflags --libs glib-2.0 gthread-2.0');
229 else:
230 env['GLIB_FLAGS'] = '';
231
232 # l10n
233 if env['WITH_GETTEXT'] == 'true':
234 env.Append(CCFLAGS = '-DCONFIG_HAVE_GETTEXT');
235
236 # instrumentation
237 if env['WITH_HTTP'] == 'true' and env['WITH_HISTOGRAMS'] == 'true':
238 env.Append(CCFLAGS = '-DCONFIG_HISTOGRAMS');
239
240 # managed environment for libpgmsnmp, libpgmhttp
241 if env['WITH_SNMP'] == 'true':
242 env['SNMP_FLAGS'] = env.ParseFlags('!net-snmp-config --cflags --agent-libs');
243
244 def restore_env(env, backup):
245 for var in backup.keys():
246 env[var] = backup[var];
247
248 def CheckSNMP(context):
249 context.Message('Checking Net-SNMP...');
250 # backup = context.env.Clone().Dictionary();
251 lastASFLAGS = context.env.get('ASFLAGS', '');
252 lastCCFLAGS = context.env.get('CCFLAGS', '');
253 lastCFLAGS = context.env.get('CFLAGS', '');
254 lastCPPDEFINES = context.env.get('CPPDEFINES', '');
255 lastCPPFLAGS = context.env.get('CPPFLAGS', '');
256 lastCPPPATH = context.env.get('CPPPATH', '');
257 lastLIBPATH = context.env.get('LIBPATH', '');
258 lastLIBS = context.env.get('LIBS', '');
259 lastLINKFLAGS = context.env.get('LINKFLAGS', '');
260 lastRPATH = context.env.get('RPATH', '');
261 context.env.MergeFlags(env['SNMP_FLAGS']);
262 result = context.TryLink("""
263 int main(int argc, char**argv)
264 {
265 init_agent("PGM");
266 return 0;
267 }
268 """, '.c');
269 # context.env.Replace(**backup);
270 context.env.Replace(ASFLAGS = lastASFLAGS,
271 CCFLAGS = lastCCFLAGS,
272 CFLAGS = lastCFLAGS,
273 CPPDEFINES = lastCPPDEFINES,
274 CPPFLAGS = lastCPPFLAGS,
275 CPPPATH = lastCPPPATH,
276 LIBPATH = lastLIBPATH,
277 LIBS = lastLIBS,
278 LINKFLAGS = lastLINKFLAGS,
279 RPATH = lastRPATH);
280 context.Result(not result);
281 return result;
282
283 def CheckCheck(context):
284 context.Message('Checking Check unit test framework...');
285 result = context.TryAction('pkg-config --cflags --libs check')[0];
286 context.Result(result);
287 return result;
288
289 def CheckEventFD(context):
290 context.Message('Checking eventfd...');
291 result = context.TryLink("""
292 #include <sys/eventfd.h>
293 int main(int argc, char**argv)
294 {
295 eventfd(0,0);
296 return 0;
297 }
298 """, '.c')
299 context.Result(result);
300 return result;
301
302 tests = {
303 'CheckCheck': CheckCheck,
304 'CheckEventFD': CheckEventFD
305 }
306 if env['WITH_SNMP'] == 'true':
307 tests['CheckSNMP'] = CheckSNMP;
308 conf = Configure(env, custom_tests = tests);
309
310 if env['WITH_SNMP'] == 'true' and not conf.CheckSNMP():
311 print 'Net-SNMP libraries not compatible.';
312 Exit(1);
313
314 if env['WITH_CHECK'] == 'true' and conf.CheckCheck():
315 print 'Enabling Check unit tests.';
316 conf.env['CHECK'] = 'true';
317 env['CHECK_FLAGS'] = env.ParseFlags('!pkg-config --cflags --libs check');
318 else:
319 print 'Disabling Check unit tests.';
320 conf.env['CHECK'] = 'false';
321
322 if conf.CheckEventFD():
323 print 'Enabling kernel eventfd notification mechanism.';
324 conf.env.Append(CCFLAGS = '-DCONFIG_EVENTFD');
325
326 env = conf.Finish();
327
328 # add builder to create PIC static libraries for including in shared libraries
329 action_list = [ Action("$ARCOM", "$ARCOMSTR") ];
330 if env.Detect('ranlib'):
331 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR");
332 action_list.append(ranlib_action);
333 pic_lib = Builder( action = action_list,
334 emitter = '$LIBEMITTER',
335 prefix = '$LIBPREFIX',
336 suffix = '$LIBSUFFIX',
337 src_suffix = '$OBJSUFFIX',
338 src_builder = 'SharedObject')
339 env.Append(BUILDERS = {'StaticSharedLibrary': pic_lib});
340
341
342 #-----------------------------------------------------------------------------
343
344 ref_node = 'ref/' + env['BUILD'] + '-' + platform.system() + '-' + platform.machine() + '/';
345 BuildDir(ref_node, '.', duplicate=0)
346
347 env.Append(CPPPATH = os.getcwd() + '/include');
348 env.Append(LIBPATH = os.getcwd() + '/' + ref_node);
349
350 if env['WITH_GLIB'] == 'true':
351 SConscript(ref_node + 'SConscript.libpgmex');
352 SConscript(ref_node + 'SConscript.libpgm');
353 if env['WITH_HTTP'] == 'true':
354 SConscript(ref_node + 'SConscript.libpgmhttp');
355 if env['WITH_SNMP'] == 'true':
356 SConscript(ref_node + 'SConscript.libpgmsnmp');
357 if env['WITH_TEST'] == 'true':
358 SConscript(ref_node + 'test/SConscript');
359 if env['WITH_EXAMPLES'] == 'true':
360 SConscript(ref_node + 'examples/SConscript');
361
362 # end of file