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