Debian Codegraph @

openpgm/pgm/SConstruct.OSX1011

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', 'false',
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 # Platform specifics
46
47 env = Environment(
48 variables = vars,
49 ENV = os.environ,
50 CCFLAGS = [ '-pipe',
51 '-Wall',
52 '-Wextra',
53 '-Wfloat-equal',
54 '-Wshadow',
55 '-Wunsafe-loop-optimizations',
56 '-Wpointer-arith',
57 '-Wbad-function-cast',
58 '-Wcast-qual',
59 '-Wcast-align',
60 '-Wwrite-strings',
61 '-Waggregate-return',
62 '-Wstrict-prototypes',
63 '-Wold-style-definition',
64 '-Wmissing-prototypes',
65 '-Wmissing-declarations',
66 '-Wmissing-noreturn',
67 '-Wmissing-format-attribute',
68 '-Wredundant-decls',
69 '-Wnested-externs',
70 # '-Winline',
71 '-Wno-inline',
72 '-Wno-unused-function',
73 '-pedantic',
74 # Native arch
75 '-march=native',
76 # C99
77 '-std=gnu99',
78 # re-entrant libc
79 '-D_REENTRANT',
80 # POSIX spinlocks
81 # '-DHAVE_PTHREAD_SPINLOCK',
82 # NSS protocol lookup
83 # '-DHAVE_GETPROTOBYNAME_R',
84 # '-DGETPROTOBYNAME_R_STRUCT_PROTOENT_P',
85 # NSS networks lookup, IPv4 only
86 '-DHAVE_GETNETENT',
87 # variadic macros
88 '-DHAVE_ISO_VARARGS',
89 # '-DHAVE_GNUC_VARARGS',
90 # stack memory api header
91 # '-DHAVE_ALLOCA_H',
92 # useful /proc system
93 # '-DHAVE_PROC_CPUINFO',
94 # example: crash handling
95 # '-DHAVE_BACKTRACE',
96 # timing
97 '-DHAVE_FTIME',
98 '-DHAVE_GETTIMEOFDAY',
99 '-DHAVE_CLOCKGETTIME',
100 '-DHAVE_PSELECT',
101 # '-DHAVE_DEV_RTC',
102 # '-DHAVE_RDTSC',
103 # '-DHAVE_DEV_HPET',
104 # event handling
105 '-DHAVE_POLL',
106 # '-DHAVE_EPOLL_CTL',
107 # interface enumeration
108 '-DHAVE_GETIFADDRS',
109 '-DHAVE_STRUCT_IFADDRS_IFR_NETMASK',
110 # win32 cmsg
111 # '-DHAVE_WSACMSGHDR',
112 # multicast
113 # '-DHAVE_STRUCT_GROUP_REQ',
114 # '-DHAVE_STRUCT_IP_MREQN',
115 # '-DHAVE_STRUCT_IP_MSFILTER',
116 # sprintf
117 '-DHAVE_SPRINTF_GROUPING',
118 '-DHAVE_VASPRINTF',
119 # symbol linking scope
120 '-DHAVE_DSO_VISIBILITY',
121 # socket binding
122 '-DUSE_BIND_INADDR_ANY',
123 # IPv6 socket options
124 '-D__APPLE_USE_RFC_3542',
125 # IP header order as per IP(4) on FreeBSD
126 '-DHAVE_HOST_ORDER_IP_LEN',
127 '-DHAVE_HOST_ORDER_IP_OFF',
128 # ticket based spinlocks
129 '-DUSE_TICKET_SPINLOCK',
130 # dumb read-write spinlock
131 '-DUSE_DUMB_RWSPINLOCK',
132 # optimum galois field multiplication
133 '-DUSE_GALOIS_MUL_LUT',
134 # GNU getopt
135 '-DHAVE_GETOPT'
136 ],
137 LINKFLAGS = [ '-pipe'
138 ],
139 LIBS = [
140 # histogram math
141 'm',
142 # POSIX threads
143 'pthread'
144 ],
145 PROTOBUF_CCFLAGS = '-I/usr/local/include/google/protobuf',
146 PROTOBUF_LIBS = '/usr/local/lib/libprotobuf.a',
147 PROTOBUF_PROTOC = 'protoc'
148 )
149
150 # Branch prediction
151 if env['BRANCH'] == 'profile':
152 env.Append(CCFLAGS = '-fprofile-arcs')
153 env.Append(LINKFLAGS = '-fprofile-arcs')
154 elif env['BRANCH'] == 'seed':
155 env.Append(CCFLAGS = '-fbranch-probabilities')
156
157 # Coverage analysis
158 if env['COVERAGE'] == 'full':
159 env.Append(CCFLAGS = '-fprofile-arcs')
160 env.Append(CCFLAGS = '-ftest-coverage')
161 env.Append(LINKFLAGS = '-fprofile-arcs')
162 env.Append(LINKFLAGS = '-lgcov')
163
164 # Define separate build environments
165 release = env.Clone(BUILD = 'release')
166 release.Append(CCFLAGS = '-O2')
167
168 debug = env.Clone(BUILD = 'debug')
169 # OSX gcc does not understand gdb flag as it is actually llvm
170 debug.Append(CCFLAGS = ['-DPGM_DEBUG', '-g'], LINKFLAGS = '-g')
171
172 profile = env.Clone(BUILD = 'profile')
173 profile.Append(CCFLAGS = ['-O2','-pg'], LINKFLAGS = '-pg')
174
175 thirtytwo = release.Clone(BUILD = 'thirtytwo')
176 thirtytwo.Append(CCFLAGS = '-m32', LINKFLAGS = '-m32')
177
178 # choose and environment to build
179 if env['BUILD'] == 'release':
180 Export({'env':release})
181 elif env['BUILD'] == 'profile':
182 Export({'env':profile})
183 elif env['BUILD'] == 'thirtytwo':
184 Export({'env':thirtytwo})
185 else:
186 Export({'env':debug})
187
188 #-----------------------------------------------------------------------------
189 # Re-analyse dependencies
190
191 Import('env')
192
193 # vanilla environment
194 if env['WITH_GLIB'] == 'true':
195 # You may need to add -I${includedir} to Cflags in glib-2.0.pc for gi18n-lib
196 env['GLIB_FLAGS'] = env.ParseFlags('!pkg-config --cflags --libs glib-2.0 gthread-2.0');
197 else:
198 env['GLIB_FLAGS'] = '';
199
200 # l10n
201 if env['WITH_GETTEXT'] == 'true':
202 env.Append(CCFLAGS = '-DHAVE_GETTEXT');
203
204 # instrumentation
205 if env['WITH_HTTP'] == 'true' and env['WITH_HISTOGRAMS'] == 'true':
206 env.Append(CCFLAGS = '-DUSE_HISTOGRAMS');
207
208 # managed environment for libpgmsnmp, libpgmhttp
209 if env['WITH_SNMP'] == 'true':
210 env['SNMP_FLAGS'] = env.ParseFlags('!net-snmp-config --cflags --agent-libs');
211
212 def restore_env(env, backup):
213 for var in backup.keys():
214 env[var] = backup[var];
215
216 def CheckSNMP(context):
217 context.Message('Checking Net-SNMP...');
218 # backup = context.env.Clone().Dictionary();
219 lastASFLAGS = context.env.get('ASFLAGS', '');
220 lastCCFLAGS = context.env.get('CCFLAGS', '');
221 lastCFLAGS = context.env.get('CFLAGS', '');
222 lastCPPDEFINES = context.env.get('CPPDEFINES', '');
223 lastCPPFLAGS = context.env.get('CPPFLAGS', '');
224 lastCPPPATH = context.env.get('CPPPATH', '');
225 lastLIBPATH = context.env.get('LIBPATH', '');
226 lastLIBS = context.env.get('LIBS', '');
227 lastLINKFLAGS = context.env.get('LINKFLAGS', '');
228 lastRPATH = context.env.get('RPATH', '');
229 context.env.MergeFlags(env['SNMP_FLAGS']);
230 result = context.TryLink("""
231 int main(int argc, char**argv)
232 {
233 init_agent("PGM");
234 return 0;
235 }
236 """, '.c');
237 # context.env.Replace(**backup);
238 context.env.Replace(ASFLAGS = lastASFLAGS,
239 CCFLAGS = lastCCFLAGS,
240 CFLAGS = lastCFLAGS,
241 CPPDEFINES = lastCPPDEFINES,
242 CPPFLAGS = lastCPPFLAGS,
243 CPPPATH = lastCPPPATH,
244 LIBPATH = lastLIBPATH,
245 LIBS = lastLIBS,
246 LINKFLAGS = lastLINKFLAGS,
247 RPATH = lastRPATH);
248 context.Result(not result);
249 return result;
250
251 def CheckCheck(context):
252 context.Message('Checking Check unit test framework...');
253 result = context.TryAction('pkg-config --cflags --libs check')[0];
254 context.Result(result);
255 return result;
256
257 def CheckEventFD(context):
258 context.Message('Checking eventfd...');
259 result = context.TryLink("""
260 #include <sys/eventfd.h>
261 int main(int argc, char**argv)
262 {
263 eventfd(0,0);
264 return 0;
265 }
266 """, '.c')
267 context.Result(result);
268 return result;
269
270 tests = {
271 'CheckCheck': CheckCheck,
272 'CheckEventFD': CheckEventFD
273 }
274 if env['WITH_SNMP'] == 'true':
275 tests['CheckSNMP'] = CheckSNMP;
276 conf = Configure(env, custom_tests = tests);
277
278 if env['WITH_SNMP'] == 'true' and not conf.CheckSNMP():
279 print 'Net-SNMP libraries not compatible.';
280 Exit(1);
281
282 if env['WITH_CHECK'] == 'true' and conf.CheckCheck():
283 print 'Enabling Check unit tests.';
284 conf.env['CHECK'] = 'true';
285 env['CHECK_FLAGS'] = env.ParseFlags('!pkg-config --cflags --libs check');
286 else:
287 print 'Disabling Check unit tests.';
288 conf.env['CHECK'] = 'false';
289
290 if conf.CheckEventFD():
291 print 'Enabling kernel eventfd notification mechanism.';
292 conf.env.Append(CCFLAGS = '-DHAVE_EVENTFD');
293
294 env = conf.Finish();
295
296 # add builder to create PIC static libraries for including in shared libraries
297 action_list = [ Action("$ARCOM", "$ARCOMSTR") ];
298 if env.Detect('ranlib'):
299 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR");
300 action_list.append(ranlib_action);
301 pic_lib = Builder( action = action_list,
302 emitter = '$LIBEMITTER',
303 prefix = '$LIBPREFIX',
304 suffix = '$LIBSUFFIX',
305 src_suffix = '$OBJSUFFIX',
306 src_builder = 'SharedObject')
307 env.Append(BUILDERS = {'StaticSharedLibrary': pic_lib});
308
309
310 #-----------------------------------------------------------------------------
311
312 ref_node = 'ref/' + env['BUILD'] + '-' + platform.system() + '-' + platform.machine() + '/';
313 BuildDir(ref_node, '.', duplicate=0)
314
315 env.Append(CPPPATH = os.getcwd() + '/include');
316 env.Append(LIBPATH = os.getcwd() + '/' + ref_node);
317
318 if env['WITH_GLIB'] == 'true':
319 SConscript(ref_node + 'SConscript.libpgmex');
320 SConscript(ref_node + 'SConscript.libpgm');
321 if env['WITH_HTTP'] == 'true':
322 SConscript(ref_node + 'SConscript.libpgmhttp');
323 if env['WITH_SNMP'] == 'true':
324 SConscript(ref_node + 'SConscript.libpgmsnmp');
325 if env['WITH_TEST'] == 'true':
326 SConscript(ref_node + 'test/SConscript');
327 if env['WITH_EXAMPLES'] == 'true':
328 SConscript(ref_node + 'examples/SConscript');
329
330 # end of file