import os
import sys


flann_root = os.environ.get('FLANN_ROOT', sys.exec_prefix)
print("Compiling FLANN with FLANN_ROOT={0}".format(flann_root))

flann_include = os.path.join(flann_root, 'include')
flann_lib = os.path.join(flann_root, 'lib')


def configuration(parent_package='', top_path=None):
    import numpy
    from numpy.distutils.misc_util import Configuration

    config = Configuration('geometry/cyflann', parent_package, top_path)
    libraries = ['flann_cpp']
    if os.name == 'posix':
        libraries.append('m')

    config.add_extension("index",
           sources=["index.cxx", "cyflann_index.cc"],
           include_dirs=[numpy.get_include(), flann_include],
           libraries = libraries,
           library_dirs = [flann_lib],
           runtime_library_dirs= [flann_lib],
           extra_compile_args=["-O3"])

    return config

@@ -14,16 +14,32 @@
 ort sys%0A
+import platform%0A
 %0A%0Aflann_
@@ -471,16 +471,25 @@
 ries = %5B
+'flann', 
 'flann_c
@@ -551,16 +551,238 @@
 d('m')%0A%0A
+    # from http://stackoverflow.com/questions/19123623/python-runtime-library-dirs-doesnt-work-on-mac%0A    extra_link_args = %5B%5D%0A    if platform.system() == 'Darwin':%0A        extra_link_args.append('-Wl,-rpath,'+flann_lib)%0A%0A
     conf
@@ -988,32 +988,32 @@
  = %5Bflann_lib%5D,%0A
-
            runti
@@ -1034,32 +1034,76 @@
 s= %5Bflann_lib%5D,%0A
+           extra_link_args=extra_link_args,%0A
            extra

make library path work on OSX