From 53bc886e2f1f0bb3d91d3ecff0e67e6ac1a1c9b4 Mon Sep 17 00:00:00 2001
From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com>
Date: Tue, 26 Nov 2013 19:09:27 -0800
Subject: [PATCH] distutils being invoked from scons; ld is failing with
 'libhammer.a: archive has no index, run ranlib to add one'

---
 src/bindings/python/SConscript | 20 +++++++++++---------
 src/bindings/python/setup.py   | 24 ++++++++++++++++--------
 2 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/bindings/python/SConscript b/src/bindings/python/SConscript
index 0f1e9a92..0a905b7a 100644
--- a/src/bindings/python/SConscript
+++ b/src/bindings/python/SConscript
@@ -4,18 +4,20 @@ Import('env libhammer_shared testruns')
 
 pythonenv = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0)
 
-pythonenv.Append(CPPPATH = ['../../'])
-pythonenv.Append(CCFLAGS = ['-fpic', '-DSWIG', '-Wno-all', '-Wno-extra', '-Wno-error'])
-pythonenv.ParseConfig("pkg-config --cflags python")
-pythonenv.Append(LIBS = ['hammer'])
-pythonenv.Append(LIBPATH = ['../../'])
-pythonenv.Append(SWIGFLAGS = ['-DHAMMER_INTERNAL__NO_STDARG_H', '-Isrc/', '-python'])
+#pythonenv.Append(CPPPATH = ['../../'])
+#pythonenv.Append(CCFLAGS = ['-fpic', '-DSWIG', '-Wno-all', '-Wno-extra', '-Wno-error'])
+#pythonenv.ParseConfig("pkg-config --cflags python")
+#pythonenv.Append(LIBS = ['hammer'])
+#pythonenv.Append(LIBPATH = ['../../'])
+#pythonenv.Append(SWIGFLAGS = ['-DHAMMER_INTERNAL__NO_STDARG_H', '-Isrc/', '-python'])
 
-pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE"))
 
-swig = ['hammer.i']
 
-libhammer_python = pythonenv.SharedLibrary('hammer', swig, SHLIBPREFIX='_')
+swig = pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE"))
+setup = ['setup.py']
+pydir = os.path.join(env['BUILD_BASE'], 'src/bindings/python')
+#libhammer_python = pythonenv.SharedLibrary('hammer', swig, SHLIBPREFIX='_')
+libhammer_python = pythonenv.Command(None, [swig, setup], 'python ' + os.path.join(pydir, 'setup.py') + ' build_ext --swig-opts="-outdir ' + pydir + ' -DHAMMER_INTERNAL__NO_STDARG_H -Isrc"')
 Default(libhammer_python)
 
 pytestenv = pythonenv.Clone()
diff --git a/src/bindings/python/setup.py b/src/bindings/python/setup.py
index 362b2529..2f42fa06 100644
--- a/src/bindings/python/setup.py
+++ b/src/bindings/python/setup.py
@@ -3,20 +3,28 @@
 """
 setup.py for Hammer bindings
 """
-
+import os.path, sys
 from distutils.core import setup, Extension
 
 setup(name="hammer",
       version="0.9.0",
       author="Upstanding Hackers, LLC",
+      author_email="hammer@upstandinghackers.com",
+      url="https://github.com/UpstandingHackers/hammer",
       description="""The Hammer parser combinator library""",
-      ext_modules=[Extension('_hammer', ['hammer.i'],
-                             swig_opts=['-DHAMMER_INTERNAL__NO_STDARG_H', '-I../../'],
-                             define_macros = [('SWIG', None)],
-                             extra_compile_args = ['-fPIC',
-                                                   '-std=gnu99',],
-                             include_dirs=['../../'],
-                             library_dirs=['../../'],
+      ext_modules=[Extension('_hammer', [os.path.join(os.path.dirname(sys.argv[0]),
+                                                      'hammer.i')],
+                             # swig_opts is set by SConscript
+                             define_macros=[('SWIG', None)],
+                             depends=['allocator.h', 
+                                      'glue.h', 
+                                      'hammer.h',
+                                      'internal.h',],
+                             extra_compile_args=['-fPIC',
+                                                 '-std=gnu99',],
+                             include_dirs=['src'],
+                             library_dirs=['src'],
                              libraries=['hammer'],)],
+      
       py_modules=['hammer'],
 )
-- 
GitLab