-
Notifications
You must be signed in to change notification settings - Fork 32
/
SConstruct
252 lines (222 loc) · 6.58 KB
/
SConstruct
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
# This file is part of SmartSNMP
# Copyright (C) 2014, Credo Semiconductor Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import sys
sys.path.append(os.path.join(os.getcwd(), "scons_tools"))
from SCons.SConf import SConfError
from select_probe import *
from endian_probe import *
from kqueue_probe import *
from epoll_probe import *
# options
AddOption(
'--transport',
dest='transport',
default = 'built-in',
type='string',
nargs=1,
action='store',
metavar='[built-in|libevent|uloop]',
help='transport you want to use'
)
AddOption(
'--evloop',
dest='evloop',
default = 'select',
type='string',
nargs=1,
action='store',
metavar='[select|epoll|kqueue]',
help='transport you want to use'
)
AddOption(
'--with-cflags',
dest='cflags',
default = '',
type='string',
nargs=1,
action='store',
metavar='CFLAGS',
help='use CFLAGS as compile time arguments (will ignore CFLAGS env)'
)
AddOption(
'--with-ldflags',
dest='ldflags',
default = '',
type='string',
nargs=1,
action='store',
metavar='LDFLAGS',
help='use LDFLAGS as link time arguments to ld (will ignore LDFLAGS env)'
)
AddOption(
'--with-libs',
dest='libs',
default = '',
type='string',
nargs=1,
action='store',
metavar='LIBS',
help='use LIBS as link time arguments to ld'
)
AddOption(
'--with-liblua',
dest='liblua_dir',
default = '',
type='string',
nargs=1,
action='store',
metavar='DIR',
help='use liblua in DIR'
)
AddOption(
'--with-libubox',
dest='libubox_dir',
default = '',
type='string',
nargs=1,
action='store',
metavar='DIR',
help='use libubox in DIR (only for transport is uloop)'
)
AddOption(
'--with-libevent',
dest='libevent_dir',
default = '',
type='string',
nargs=1,
action='store',
metavar='DIR',
help='use libevent in DIR (only for transport is libevent)'
)
AddOption(
'--gcov',
dest='gcov',
default = '',
type='string',
nargs=1,
action='store',
metavar='[yes|no]',
help='compile C source code with gcov support'
)
env = Environment(
ENV = os.environ,
LIBS = ['m', 'dl'],
CFLAGS = ['-std=c99', '-Wall'],
)
# handle options/environment varibles.
if os.environ.has_key('CC'):
env.Replace(CC = os.environ['CC'])
# CFLAGS
if GetOption("cflags") != "":
env.Append(CFLAGS = GetOption("cflags"))
elif os.environ.has_key('CFLAGS'):
env.Append(CFLAGS = os.environ['CFLAGS'])
# LDFLAGS
if GetOption("ldflags") != "":
env.Replace(LINKFLAGS = GetOption("ldflags"))
elif os.environ.has_key('LDFLAGS'):
env.Replace(LINKFLAGS = os.environ['LDFLAGS'])
elif os.environ.has_key('LINKFLAGS'):
env.Replace(LINKFLAGS = os.environ['LINKFLAGS'])
# LIBS
if GetOption("libs") != "":
env.Append(LIBS = GetOption("libs"))
# liblua
if GetOption("liblua_dir") != "":
env.Append(LIBPATH = [GetOption("liblua_dir")])
# libevent
if GetOption("libevent_dir") != "":
env.Append(LIBPATH = [GetOption("libevent_dir")])
# libubox
if GetOption("libubox_dir") != "":
env.Append(LIBPATH = [GetOption("libubox_dir")])
# transport select
if GetOption("transport") == 'libevent':
env.Append(LIBS = ['event'])
transport_src = [env.File("core/agentx_tcp_evloop_transport.c"), env.File("core/snmp_udp_libevent_transport.c"), env.File("core/ev_loop.c")]
elif GetOption("transport") == 'uloop':
env.Append(LIBS = ['ubox'])
transport_src = [env.File("core/agentx_tcp_evloop_transport.c"), env.File("core/snmp_udp_uloop_transport.c"), env.File("core/ev_loop.c")]
elif GetOption("transport") == 'built-in' or GetOption("transport") == '':
transport_src = [env.File("core/agentx_tcp_evloop_transport.c"), env.File("core/snmp_udp_evloop_transport.c"), env.File("core/ev_loop.c")]
# built-in event loop check
if GetOption("evloop") == 'epoll':
env.Append(CFLAGS = ["-DUSE_EPOLL"])
elif GetOption("evloop") == 'kqueue':
env.Append(CFLAGS = ["-DUSE_KQUEUE"])
elif GetOption("evloop") == 'select' or GetOption("evloop") == '':
pass
else:
print "Error: Not the right event driving type"
Exit(1)
else:
print "Error: Transport not found!"
Exit(1)
# autoconf
conf = Configure(env, custom_tests = {'CheckEpoll' : CheckEpoll, 'CheckSelect' : CheckSelect, 'CheckKqueue' : CheckKqueue, 'CheckEndian' : CheckEndian})
# Endian check
endian = conf.CheckEndian()
if endian == 'Big':
env.Append(CFLAGS = ["-DBIG_ENDIAN"])
elif endian == 'Little':
env.Append(CFLAGS = ["-DLITTLE_ENDIAN"])
else:
raise SConfError("Error when testing the endian.")
# built-in event loop check
if GetOption("transport") == 'built-in' or GetOption("transport") == '':
if GetOption("evloop") == 'epoll':
if not conf.CheckEpoll():
print "Error: epoll failed"
Exit(1)
elif GetOption("evloop") == 'kqueue':
if not conf.CheckKqueue():
print "Error: Kqueue failed"
Exit(1)
elif GetOption("evloop") == 'select' or GetOption("evloop") == '':
if not conf.CheckSelect():
print "Error: select failed"
Exit(1)
else:
print "Error: Not the right event driving type"
Exit(1)
# CFLAGS
if GetOption("gcov") == "yes":
env.Append(
CFLAGS = ['-fprofile-arcs', '-ftest-coverage'],
LINKFLAGS = ['-fprofile-arcs', '-ftest-coverage'],
)
# find liblua. On Ubuntu, liblua is named liblua5.1, so we need to check this.
if conf.CheckLib('lua'):
env.Append(LIBS = ['lua'])
elif conf.CheckLib('lua5.1'):
env.Append(LIBS = ['lua5.1'])
else:
print "Error: liblua or liblua5.1 not found!"
Exit(1)
# find lua header files
if conf.CheckCHeader('lua.h'):
pass
elif conf.CheckCHeader('lua5.1/lua.h'):
env.Append(CFLAGS = ['-I/usr/include/lua5.1'])
else:
print "Error: lua.h not found"
Exit(1)
env = conf.Finish()
src = env.Glob("core/snmp_msg*.c") + env.Glob("core/snmp_*coder.c") + env.Glob("core/snmp.c") + env.Glob("core/agentx_msg*.c") + env.Glob("core/agentx_*coder.c") + env.Glob("core/agentx.c") + env.Glob("core/mib_*.c") + env.Glob("core/smartsnmp.c") + transport_src
# generate lua c module
libsmartsnmp_core = env.SharedLibrary('build/smartsnmp/core', src, SHLIBPREFIX = '')