Skip to content

Commit

Permalink
Compile using node-gyp instead of node-waf
Browse files Browse the repository at this point in the history
This fixes issue #2 and also allows the module to be used by Node >=
0.9.1.
  • Loading branch information
Homme Zwaagstra committed Dec 11, 2012
1 parent ca6b70f commit b18a289
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 87 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@
language: node_js
node_js:
- 0.8
- 0.9
env:
- MAPCACHE_COMMIT=11e85095a39010f953b34077b7f0824e234e9423 # minimum supported version
- MAPCACHE_COMMIT= # repository HEAD
Expand Down
33 changes: 18 additions & 15 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
----
Expand Down
31 changes: 31 additions & 0 deletions 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'
],
}],
]
}
]
}
112 changes: 112 additions & 0 deletions 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()
72 changes: 0 additions & 72 deletions wscript

This file was deleted.

0 comments on commit b18a289

Please sign in to comment.