forked from kuno/GeoIP
-
Notifications
You must be signed in to change notification settings - Fork 5
/
wscript
165 lines (141 loc) · 5.55 KB
/
wscript
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
import Options
import Utils
import os
from os import popen, unlink, symlink, getcwd
from os import name as platform
from os.path import exists
from shutil import rmtree
srcdir = "."
blddir = "build"
VERSION = "0.1"
# Bundled geoip library
BUNDLED_GEOIP_VERSION = '1.4.8'
BUNDLED_GEOIP = 'GeoIP-%s' % BUNDLED_GEOIP_VERSION
BUNDLED_GEOIP_TAR = 'GeoIP-%s.tar.gz' % BUNDLED_GEOIP_VERSION
def set_options(opt):
opt.tool_options("compiler_cxx")
opt.add_option( '--geoip'
, action='store'
, default=None
, help='Directory prefix containing geoip "lib" and "include" files'
, dest='shared_geoip_dir'
)
opt.add_option( '--shared-geoip'
, action='store_true'
, default=False
, help='Build dynamically against external install of geoip (default False - build uses internal copy)'
, dest='shared_geoip'
)
def configure_geoip():
if not Options.options.shared_geoip:
Utils.pprint('GREEN','configuring internal geoip dep')
os.chdir('deps')
if not os.fs.exists(BUNDLED_GEOIP):
os.system('tar xzf %s' % BUNDLED_GEOIP_TAR)
os.chdir(BUNDLED_GEOIP)
cxxflags = ''
if os.environ.has_key('CFLAGS'):
cxxflags += os.environ['CFLAGS']
cxxflags += ' '
if os.environ.has_key('CXXFLAGS'):
cxxflags += os.environ['CXXFLAGS']
# LINKFLAGS appear to be picked up automatically...
os.system("CFLAGS='%s -fPIC -O3 -DNDEBUG -Wall' ./configure --disable-dependency-tracking --enable-static --disable-shared" % cxxflags)
os.chdir('../../')
def configure(conf):
conf.check_tool("compiler_cxx")
conf.check_tool("node_addon")
configure_geoip()
geoip_includes = []
geoip_libpath = []
auto_configured = False
o = Options.options
geoip_dir = o.shared_geoip_dir
shared_geoip = o.shared_geoip
if geoip_dir:
norm_path = os.path.realpath(geoip_dir)
if norm_path.endswith('lib') or norm_path.endswith('include'):
norm_path = os.path.dirname(norm_path)
geoip_includes = [os.path.join('%s' % norm_path,'include'),
os.path.join('%s' % norm_path,'lib/geoip/include')
]
geoip_libpath = [os.path.join('%s' % norm_path,'lib')]
elif shared_geoip:
if not auto_configured:
# reasonable defaults for searching
geoip_includes = ['/usr/local/include',
'/usr/local/lib/geoip/include',
'/usr/include',
'/usr/lib/geoip/include',
]
geoip_libpath = ['/usr/local/lib','/usr/lib']
elif not shared_geoip:
auto_configured = True
geoip_includes = ['-I../deps/%s/libGeoIP' % BUNDLED_GEOIP]
geoip_libpath = ['-L../deps/%s/libGeoIP/.libs' % BUNDLED_GEOIP]
if not auto_configured:
if not conf.check_cxx(lib='geoip', header_name='GeoIP.h',
uselib_store='GEOIP',
includes=geoip_includes,
libpath=geoip_libpath):
conf.fatal("\n\n Cannot find libGeoIP, required for GeoIP,\n please install from:\n 'http://nih.at/geoip/'\n (see README.md for more info)\n")
else:
Utils.pprint('GREEN', 'Sweet, found viable libGeoIP dependency')
# strip paths that don't exist, turn into proper flags
new_inc = []
for i in geoip_includes:
if os.fs.exists(i):
new_inc.append('-I%s' % i)
geoip_includes = new_inc
new_inc = []
for i in geoip_libpath:
if os.fs.exists(i):
new_inc.append('-L%s' % i)
geoip_libpath = new_inc
linkflags = []
if os.environ.has_key('LINKFLAGS'):
linkflags = os.environ['LINKFLAGS'].split(' ')
linkflags.extend(geoip_libpath)
if shared_geoip:
if '-lGeoIP' not in linkflags:
linkflags.append('-lGeoIP')
elif Options.platform == 'darwin':
linkflags.append('-Wl,-search_paths_first')
conf.env.append_value("LINKFLAGS", linkflags)
cxxflags = geoip_includes
conf.env.append_value("CXXFLAGS", cxxflags)
#ldflags = []
#conf.env.append_value("LDFLAGS", ldflags)
def build_geoip():
if not Options.options.shared_geoip:
os.chdir('deps/%s' % BUNDLED_GEOIP)
os.system('make')
os.chdir('../../')
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
build_geoip()
obj.uselib = "GEOIP"
obj.target = "geoip"
obj.source = ['src/init.cc',
'src/netspeed.cc',
'src/country6.cc',
'src/country.cc',
'src/region.cc',
'src/city6.cc',
'src/city.cc',
'src/org.cc',
'src/utils.cc',
'src/global.cc']
obj.lib = ["GeoIP"]
def clean(bld):
if not Options.options.shared_geoip:
rmtree('deps/%s' % BUNDLED_GEOIP, ignore_errors = True)
rmtree('build', ignore_errors = True)
def link(bld):
# HACK to get binding.node out of build directory.
# better way to do this?
if Options.commands['clean']:
if exists(getcwd() + '/geoip.node'): unlink('geoip.node')
else:
if exists(getcwd() + '/build/default/geoip.node') and not exists(getcwd() + 'geoip.node'):
symlink(getcwd()+'/build/default/geoip.node', getcwd() + 'geoip.node')