Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added bundled version of GeoIP. shamelesly inspired by node-gzip. #27

Closed
wants to merge 3 commits into from

2 participants

@toots

No description provided.

@toots

Hi!

Any news on this? I really need it to push some code into production and I'd like to avoid publishing a new npm package just for it..

@kuno
Owner

sorry make you wating for so long time, (so far, busying on company's project)
thanks for you code
Will it cause some troubles by including libgeoip source code?
I am not a expert on license, but I really worry about that.

Hi!

The source code is actually not included in the patch but downloaded at configure/build time. Thus, licensing concerns are only restricted to linking against the library, which is already the case without my patch and shouldn't be a problem anyway..

Hey,

Sorry, I don't know what was wrong with me, the source code is included...

License for libgeoip is LGPL, which means that, among others, you are free to distribute it, so there should be no problem bundling it with your source code.

Owner

I think it's better downloading the souce code only when we need it.

what's the waf commands to build libgeoip from source code?

Downloading isn't my favorite option because URLs change, servers have downtimes and installer may not have access to internet..

In the current patch, bundled libgeoip is built by default. In order to build against a shared one, one has to do:

node-waf --shared-geoip configure

Additionally, location for the library can be specified by using the --geoip option.

@mnutt mnutt referenced this pull request in mnutt/hummingbird
Closed

GeoIP.h file not found #43

@kuno
Owner

Now we use node-gyp.

Closing.

@kuno kuno closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 16, 2011
  1. @toots
Commits on Jan 21, 2012
  1. @toots

    Call clean before building.

    toots authored
  2. @toots

    Better clean target.

    toots authored
This page is out of date. Refresh to see the latest.
Showing with 128 additions and 3 deletions.
  1. BIN  deps/GeoIP-1.4.8.tar.gz
  2. +1 −1  package.json
  3. +127 −2 wscript
View
BIN  deps/GeoIP-1.4.8.tar.gz
Binary file not shown
View
2  package.json
@@ -32,7 +32,7 @@
"benchmark":"./benchmark"
},
"engine":{"node": ">=0.6.0", "npm": "1"},
- "script":{"install": "node-waf configure build"},
+ "script":{"install": "node-waf clean configure build"},
"licences":
[
{
View
129 wscript
@@ -1,21 +1,141 @@
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.path.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")
+ 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.path.exists(i):
+ new_inc.append('-I%s' % i)
+ geoip_includes = new_inc
+
+ new_inc = []
+ for i in geoip_libpath:
+ if os.path.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',
@@ -30,6 +150,11 @@ def build(bld):
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?
Something went wrong with that request. Please try again.