diff --git a/swig/Makefile.am b/swig/Makefile.am index afa74a0..ee2b9c0 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -2,7 +2,7 @@ EXTRA_DIST = \ python/prepare.sh \ - python/setup.py.in \ + python/setup.py \ python/export_wrap.cpp \ python/simstring.py \ python/sample.py \ diff --git a/swig/python/prepare.sh b/swig/python/prepare.sh index 2bf1095..4484ecf 100755 --- a/swig/python/prepare.sh +++ b/swig/python/prepare.sh @@ -1,9 +1,9 @@ -#!/bin/sh +#!/bin/sh -xe # $Id:$ -ln -s ../export.cpp -ln -s ../export.h -ln -s ../export.i +ln -sf ../export.cpp +ln -sf ../export.h +ln -sf ../export.i if [ "$1" = "--swig" ]; then diff --git a/swig/python/setup.py.in b/swig/python/setup.py similarity index 54% rename from swig/python/setup.py.in rename to swig/python/setup.py index bc2b254..135b2af 100755 --- a/swig/python/setup.py.in +++ b/swig/python/setup.py @@ -5,7 +5,9 @@ """ import sys +import os import os.path +import re def get_rootdir(): return os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')) @@ -15,10 +17,24 @@ def get_includedir(): def get_swigdir(): return os.path.join(get_rootdir(), 'swig') +def get_version(): + with open(os.path.join(get_rootdir(), 'configure.in')) as f: + for line in f: + m = re.search(r'AM_INIT_AUTOMAKE\([^,]*,\s*([^)]+)\)', line) + if m: + return m.group(1) + import os; os.environ['CC'] = 'g++'; os.environ['CXX'] = 'g++'; os.environ['CPP'] = 'g++'; os.environ['LDSHARED'] = 'g++' from distutils.core import setup, Extension +from distutils.command import build_ext as build_ext_module + +class build_ext(build_ext_module.build_ext): + def run(self): + prepare_script = os.path.abspath(os.path.join(os.path.dirname(__file__), 'prepare.sh')) + assert os.system(prepare_script + ' --swig') == 0 + build_ext_module.build_ext.run(self) simstring_module = Extension( '_simstring', @@ -27,16 +43,17 @@ def get_swigdir(): 'export_wrap.cpp', ], include_dirs=[get_includedir(),], - extra_link_args=['-shared', '-liconv', '-lpython'], + extra_link_args=['-shared'], language='c++', ) setup( - name = '@PACKAGE@', - version = '@VERSION@', + name = 'simstring', + version = get_version(), author = 'Naoaki Okazaki', description = """SimString Python module""", ext_modules = [simstring_module], py_modules = ["simstring"], + cmdclass = {'build_ext': build_ext,}, )