-
Notifications
You must be signed in to change notification settings - Fork 17
/
SConstruct
286 lines (248 loc) · 6.82 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
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
280
281
282
283
284
285
286
# This file is part of SmithSNMP
# Copyright (C) 2014, Credo Semiconductor Inc.
# Copyright (C) 2015, Leo Ma <begeekmyfriend@gmail.com>
#
# 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 kqueue_probe import *
from epoll_probe import *
# options
AddOption(
'--with-agentx',
dest='agentx',
default = '',
type='string',
nargs=0,
action='store',
metavar='AGENTX',
help='enable agentx module you want to use'
)
AddOption(
'--without-trap',
dest='dis_trap',
default = '',
type='string',
nargs=0,
action='store',
metavar='TRAP',
help='disable trap module you DO NOT want to use'
)
AddOption(
'--without-crypto',
dest='dis_crypto',
default = '',
type='string',
nargs=0,
action='store',
metavar='CRYPTO',
help='disable crypto module you DO NOT want to use'
)
AddOption(
'--without-md5',
dest='dis_md5',
default = '',
type='string',
nargs=0,
action='store',
metavar='MD5',
help='disable md5 module you DO NOT want to use'
)
AddOption(
'--without-sha',
dest='dis_sha',
default = '',
type='string',
nargs=0,
action='store',
metavar='SHA',
help='disable SHA module you DO NOT want to use'
)
AddOption(
'--without-aes',
dest='dis_aes',
default = '',
type='string',
nargs=0,
action='store',
metavar='AES',
help='disable AES module you DO NOT want to use'
)
AddOption(
'--evloop',
dest='evloop',
default = 'select',
type='string',
nargs=1,
action='store',
metavar='[select|epoll|kqueue]',
help='select event loop model'
)
AddOption(
'--with-cflags',
dest='cflags',
default = '',
type='string',
nargs=1,
action='store',
metavar='CCFLAGS',
help='use CCFLAGS as compile time arguments (will ignore CCFLAGS 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'
)
env = Environment(
ENV = os.environ,
LIBS = ['m', 'dl'],
CCFLAGS = ['-std=c99', '-O2', '-Wall'],
CPPDEFINES = {'_XOPEN_SOURCE' : '600'},
)
# handle options/environment varibles.
if 'CC' in os.environ:
env.Replace(CC = os.environ['CC'])
# CCFLAGS
if GetOption("cflags") != "":
env.MergeFlags(CCFLAGS = GetOption("cflags"))
elif 'CCFLAGS' in os.environ:
env.MergeFlags(CCFLAGS = os.environ['CCFLAGS'])
elif 'CFLAGS' in os.environ:
env.MergeFlags(os.environ['CFLAGS'])
# LDFLAGS
if GetOption("ldflags") != "":
env.Replace(LINKFLAGS = GetOption("ldflags"))
elif 'LDFLAGS' in os.environ:
env.Replace(LINKFLAGS = os.environ['LDFLAGS'])
elif 'LINKFLAGS' in os.environ:
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")])
# event loop check
if GetOption("evloop") == 'epoll':
env.Append(CPPDEFINES = ["USE_EPOLL"])
elif GetOption("evloop") == 'kqueue':
env.Append(CPPDEFINES = ["USE_KQUEUE"])
elif GetOption("evloop") == 'select' or GetOption("evloop") == '':
pass
else:
print("Error: Unknown event loop model")
Exit(1)
# autoconf
conf = Configure(env, custom_tests = {'CheckEpoll' : CheckEpoll, 'CheckSelect' : CheckSelect, 'CheckKqueue' : CheckKqueue})
# endian check
if not 'BIG_ENDIAN' in env['CPPDEFINES'] and not 'LITTLE_ENDIAN' in env['CPPDEFINES']:
if sys.byteorder == "little":
env.Append(CPPDEFINES = ["LITTLE_ENDIAN"])
else:
env.Append(CPPDEFINES = ["BIG_ENDIAN"])
# event loop check
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)
# CCFLAGS
# find liblua. On Ubuntu, liblua is named liblua5.1, so we need to check this.
if not conf.CheckLib('lua') and not conf.CheckLib('lua5.1'):
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(CCFLAGS = ['-I/usr/include/lua5.1'])
else:
print("Error: lua.h not found")
Exit(1)
env = conf.Finish()
snmp_src = env.Glob("core/snmp.c") + env.Glob("core/snmp_msg*.c") + env.Glob("core/snmp_*coder.c") + env.Glob("core/snmp_*transport.c")
agentx_src = env.Glob("core/agentx.c") + env.Glob("core/agentx_msg*.c") + env.Glob("core/agentx_*coder.c") + env.Glob("core/agentx_*transport.c")
trap_src = env.Glob("core/*trap.c")
md5_src = env.Glob("3rd/crypto/openssl_md5*.c")
sha_src = env.Glob("3rd/crypto/openssl_sha*.c")
aes_src = env.Glob("3rd/crypto/openssl_aes*.c") + env.Glob("3rd/crypto/openssl_cfb*.c")
src = env.Glob("core/smithsnmp.c") + env.Glob("core/event_loop.c") + env.Glob("core/mib_*.c") + snmp_src
# AGENTX
if GetOption("agentx") != "":
src += agentx_src
env.Append(CPPDEFINES = ["USE_AGENTX"])
# DISABLE TRAP
if GetOption("dis_trap") != "":
trap_src = []
env.Append(CPPDEFINES = ["DISABLE_TRAP"])
# DISABLE CRYPTO
if GetOption("dis_crypto") != "":
md5_src = []
sha_src = []
aes_src = []
env.Append(CPPDEFINES = ["DISABLE_CRYPTO"])
# DISABLE MD5
if GetOption("dis_md5") != "":
md5_src = []
env.Append(CPPDEFINES = ["DISABLE_MD5"])
# DISABLE SHA
if GetOption("dis_sha") != "":
sha_src = []
env.Append(CPPDEFINES = ["DISABLE_SHA"])
# DISABLE AES
if GetOption("dis_aes") != "":
aes_src = []
env.Append(CPPDEFINES = ["DISABLE_AES"])
src += [trap_src, md5_src, sha_src, aes_src]
# generate lua c module
libsmithsnmp_core = env.SharedLibrary('build/smithsnmp/core', src, SHLIBPREFIX = '')