Skip to content
Browse files

Compile using `node-gyp` instead of `node-waf`

This fixes issue #2 and also allows the module to be used by Node >=
0.9.1.
  • Loading branch information...
1 parent ca6b70f commit b18a2890bd7f13fcc2008b744a1a3f2828423237 @homme homme committed Dec 11, 2012
Showing with 162 additions and 87 deletions.
  1. +1 −0 .travis.yml
  2. +18 −15 README.md
  3. +31 −0 binding.gyp
  4. +112 −0 tools/config.py
  5. +0 −72 wscript
View
1 .travis.yml
@@ -3,6 +3,7 @@
language: node_js
node_js:
- 0.8
+ - 0.9
env:
- MAPCACHE_COMMIT=11e85095a39010f953b34077b7f0824e234e9423 # minimum supported version
- MAPCACHE_COMMIT= # repository HEAD
View
33 README.md
@@ -18,19 +18,8 @@ possible from Node with the following advantages:
* **Robustness**: The module has a suite of tests that exercises the whole
API. This suite has been run through Valgrind to check for memory leaks.
-However, the module also comes with the following caveats:
-
-* Although it has been used intensively on a number of internal projects the
- codebase is relatively immature. To date it has only been developed and used
- in a Linux environment: patches porting it to other OSes are welcome!
-* If you want raw speed use the Apache module or reverse proxy your
- `node-mapcache` app with a web accelerator such as Varnish. Having said that
- `node-mapcache` shouldn't be slow: benchmarks are welcome!
-* C/C++ is not the author's day-to-day programming language: code improvements
- are welcome!
-
-API
----
+Usage
+-----
The `node-mapcache` API is designed to be simple but flexible. It binds into
the underlying `libmapcache` library before the HTTP layer and around the
@@ -193,8 +182,12 @@ a cache request to the ImageMagick `display` program.
Requirements
------------
-* Linux OS (although it should work on other Unices)
-* Node.js 0.8
+* Linux OS (although it should work on other Unices and ports to Windows and
+ other platforms supported by both Node and Mapserver should be possible:
+ patches welcome!)
+
+* Node.js >=0.8
+
* Mapserver MapCache 0.5-dev >= commit 11e8509
Installation
@@ -242,6 +235,16 @@ instructions roughly translate to:
npm install vows
./node_modules/.bin/vows --spec ./test/mapcache-test.js
+
+Recommendations
+---------------
+
+* If you want raw speed use the Apache Mapcache module or reverse proxy your
+ `node-mapcache` app with a web accelerator such as Varnish. Having said that
+ `node-mapcache` shouldn't be slow: benchmarks are welcome!
+
+* Check out [`node-mapserv`](https://npmjs.org/package/mapserv): this can work
+ well in combination with `node-mapcache` for generating tiled maps.
Bugs
----
View
31 binding.gyp
@@ -0,0 +1,31 @@
+{
+ "targets": [
+ {
+ "target_name": "bindings",
+ "sources": [
+ "src/node-mapcache.cpp",
+ "src/mapcache.cpp",
+ "src/asynclog.cpp"
+ ],
+ "include_dirs": [
+ "<!@(python tools/config.py --include)"
+ ],
+ "conditions": [
+ ['OS=="linux"', {
+ 'ldflags': [
+ '-Wl,--no-as-needed,-lmapcache',
+ '<!@(python tools/config.py --ldflags)'
+ ],
+ 'libraries': [
+ "<!@(python tools/config.py --libraries)"
+ ],
+ 'cflags': [
+ '<!@(python tools/config.py --cflags)',
+ '-pedantic',
+ '-Wall'
+ ],
+ }],
+ ]
+ }
+ ]
+}
View
112 tools/config.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python2
+
+##############################################################################
+# Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# - Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# - Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+##############################################################################
+
+"""
+Output mapcache configuration information to `node-gyp`
+
+Configuration options are retrieved from environment variables set using `npm
+config set`. This allows for a simple `npm install mapcache` to work.
+"""
+
+from optparse import OptionParser
+import os
+import re
+
+def get_lib_dir():
+ return os.environ.get('npm_config_mapcache_lib_dir', '')
+
+def get_include_dir():
+ try:
+ build_dir = os.environ['npm_config_mapcache_build_dir']
+ except KeyError:
+ return ''
+
+ return os.path.join(build_dir, 'include')
+
+def get_cflags():
+ try:
+ build_dir = os.environ['npm_config_mapcache_build_dir']
+ except KeyError:
+ raise EnvironmentError('`npm config set mapcache:build_dir` has not been called')
+
+ makefile_inc = os.path.join(build_dir, 'Makefile.inc')
+
+ # add includes from the Makefile
+ p = re.compile('^[A-Z]+_INC *= *(.+)$') # match an include header
+ matches = []
+ with open(makefile_inc, 'r') as f:
+ for line in f:
+ match = p.match(line)
+ if match:
+ arg = match.groups()[0].strip()
+ if arg:
+ matches.append(arg)
+
+ # add debugging flags and defines
+ if 'npm_config_mapcache_debug' in os.environ:
+ matches.extend(["-DDEBUG", "-ggdb", "-pedantic"])
+
+ cflags = ' '.join(matches)
+ return cflags
+
+parser = OptionParser()
+parser.add_option("--include",
+ action="store_true", default=False,
+ help="output the mapcache include path")
+
+parser.add_option("--libraries",
+ action="store_true", default=False,
+ help="output the mapcache library link option")
+
+parser.add_option("--ldflags",
+ action="store_true", default=False,
+ help="output the mapcache library rpath option")
+
+parser.add_option("--cflags",
+ action="store_true", default=False,
+ help="output the mapcache cflag options")
+
+(options, args) = parser.parse_args()
+
+if options.include:
+ print get_include_dir()
+
+if options.libraries:
+ lib_dir = get_lib_dir()
+ if lib_dir:
+ print "-L%s" % lib_dir
+
+if options.ldflags:
+ # write the library path into the resulting binary
+ lib_dir = get_lib_dir()
+ if lib_dir:
+ print "-Wl,-rpath=%s" % lib_dir
+
+if options.cflags:
+ print get_cflags()
View
72 wscript
@@ -1,72 +0,0 @@
-import re, os, os.path
-
-def _get_mapcache_dirs(conf):
- """Get the location of the mapcache directory
-
- This is retrieved from the environment variables set by npm. This is
- only necessary as mapcache doesn't install headers or support
- pkgconfig"""
-
- try:
- build_dir = os.environ['npm_config_mapcache_build_dir']
- except KeyError:
- return conf.fatal('Mapcache build directory not found: set using `npm config set mapcache:build_dir DIR`')
-
- try:
- lib_dir = os.environ['npm_config_mapcache_lib_dir']
- except KeyError:
- return conf.fatal('Mapcache lib directory not found: set using `npm config set mapcache:lib_dir DIR`')
-
- if not os.path.isdir(build_dir):
- return conf.fatal('Mapcache build directory is not accessible: %s' % build_dir)
-
- if not os.path.isdir(lib_dir):
- return conf.fatal('Mapcache lib directory is not accessible: %s' % lib_dir)
-
- return build_dir, lib_dir
-
-def _configure_mapcache_includes(conf, build_dir):
- """Add mapcache includes from the Mapcache build directory"""
-
- makefile_inc = os.path.join(build_dir, 'Makefile.inc')
-
- # add includes from the Makefile
- p = re.compile('^[A-Z]+_INC *= *(.+)$') # match an include header
- with open(makefile_inc, 'r') as f:
- for line in f:
- match = p.match(line)
- if match:
- arg = match.groups()[0].strip()
- if arg:
- conf.env.append_value('CXXFLAGS_LIBMAPCACHE', arg)
-
- # add the include for the local mapcache headers
- include = '-I%s' % os.path.join(build_dir, 'include')
- conf.env.append_value('CXXFLAGS_LIBMAPCACHE', include)
-
- # add debugging flags and defines
- if os.environ.get('npm_config_mapcache_debug'):
- conf.env.CXXDEFINES_LIBMAPCACHE = ['DEBUG']
- conf.env.CXXFLAGS += ["-ggdb", "-pedantic"]
-
-def set_options(opt):
- opt.tool_options("compiler_cxx")
-
-def configure(conf):
- conf.check_tool("compiler_cxx")
- conf.check_tool("node_addon")
- # This will tell the compiler to link our extension with the geocache library.
- build_dir, lib_dir = _get_mapcache_dirs(conf)
- _configure_mapcache_includes(conf, build_dir)
- conf.check_cxx(lib='mapcache', libpath=lib_dir, uselib_store='LIBMAPCACHE')
-
-def build(bld):
- obj = bld.new_task_gen("cxx", "shlib", "node_addon")
- obj.cxxflags = ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"]
- obj.target = "bindings"
- obj.source = [
- "src/node-mapcache.cpp",
- "src/mapcache.cpp",
- "src/asynclog.cpp"
- ]
- obj.uselib = ['LIBMAPCACHE']

0 comments on commit b18a289

Please sign in to comment.
Something went wrong with that request. Please try again.