From e7b14982a97dd026f4eb28c7ab286553556e2854 Mon Sep 17 00:00:00 2001
From: Berk Onat <b.onat@warwick.ac.uk>
Date: Mon, 30 Oct 2017 11:44:49 +0000
Subject: [PATCH] Correction to setup.py

---
 setup.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 61 insertions(+), 5 deletions(-)

diff --git a/setup.py b/setup.py
index 559217e..95f46b1 100644
--- a/setup.py
+++ b/setup.py
@@ -11,18 +11,38 @@ from distutils.version import LooseVersion
 
 try:
     from setuptools.command.build_ext import build_ext
-    from setuptools import setup, Extension, Command, find_packages
+    #from setuptools.command.build_ext import build_ext as _build_ext
+    from setuptools import Distribution, setup, Extension, Command, find_packages
     from setuptools.command.install import install
+    #from Cython.Build import cythonize
+    #from Cython.Distutils import build_ext as _build_ext
 except:
     from distutils.command.build_ext import build_ext
-    from distutils import setup, Extension, Command, find_packages
+    #from distutils.command.build_ext import build_ext as _build_ext
+    from distutils import Distribution, setup, Extension, Command, find_packages
     from distutils.command.install import install
+    #from Cython.Build import cythonize
+    #from Cython.Distutils import build_ext as _build_ext
     
 try:
     from setuptools.command.build_clib import build_clib as _build_clib
 except:
     from distutils.command.build_clib import build_clib as _build_clib
 
+#def use_system():
+#    install_type = os.environ.get("SODIUM_INSTALL")
+#    
+#    if install_type == "system":
+#        # If we are forcing system installs, don't compile the bundled one
+#        return True
+#    else:
+#        # By default we just use the bundled copy
+#        return False
+
+#class Distribution(Distribution):
+#    def has_c_libraries(self):
+#        return not use_system()
+
 class CMakeExtension(Extension):
     def __init__(self, name, sourcedir=''):
         Extension.__init__(self, name, sources=[])
@@ -68,6 +88,20 @@ class build_clib(_build_clib):
 
         print()  # Add an empty line for cleaner output
 
+#def build_ext(_build_ext):
+#    def run(self):
+#        buildflag = True
+#        if buildflag:
+#        #if self.distribution.has_c_libraries():
+#            build_clib = self.get_finalized_command("build_clib")
+#            self.include_dirs.append(
+#                    os.path.join(build_clib.build_clib, "include"),
+#                    )
+#            self.library_dirs.insert(0,
+#                    os.path.join(build_clib.build_clib, "lib"),
+#                    )
+#        for ext in self.extensions:
+#            return _build_ext.run(ext)
 
 def get_ext_filename_without_platform_suffix(filename):
     name, ext = os.path.splitext(filename)
@@ -168,6 +202,14 @@ def get_numpy_include():
         numpy_include = np.get_numpy_include()
     return numpy_include
 
+# from SimpleTraj setup.py (https://github.com/arose/simpletraj)
+# Needed for large-file seeking under 32bit systems (migth need for indexing and access).
+largefile_macros = [
+    ( "_LARGEFILE_SOURCE", None ),
+    ( "_LARGEFILE64_SOURCE", None ),
+    ( "_FILE_OFFSET_BITS","64" )
+]
+
 if __name__ == '__main__':
 
     libpymolfile_module = Extension(
@@ -175,9 +217,8 @@ if __name__ == '__main__':
             sources=[
                 'pymolfile/molfile/libpymolfile.i' , 
                 'pymolfile/molfile/pymolfile.cxx',
-                'build/molfile_plugins/compile/lib/libmolfile_plugin.a',
-                'build/molfile_plugins/compile/lib/libmolfile_plugin.h',
-                'build/external/tng/lib',
+                #'build/molfile_plugins/compile/lib/',
+                #'build/external/tng/lib/',
                 ],
             swig_opts=['-py3', '-Wall', '-c++'],
             library_dirs=[
@@ -187,6 +228,7 @@ if __name__ == '__main__':
             libraries=['netcdf','tng_io','expat'],
             include_dirs = [
                 get_numpy_include(),
+                #get_cmake_includes(),
                 'pymolfile/molfile',
                 'pymolfile/molfile/molfile_plugins/include',
                 'pymolfile/molfile/molfile_plugins/molfile_plugin/include',
@@ -195,11 +237,19 @@ if __name__ == '__main__':
                 ],
             extra_compile_args = [
                 '-fPIC', '-shared', '-O2', '-w'
+                #'-DNDEBUG', '-DUNIX', '-D__UNIX',  '-m64', 
+                #'-fPIC', '-O2', '-w', '-fmessage-length=0'
                 ],
             extra_link_args = [
                 'build/molfile_plugins/compile/lib/libmolfile_plugin.a'
                 ],
+            #define_macros = largefile_macros
             )
+    #if sys.version_info > (3,):
+    #    command_extension={'build_ext': BuildExtWithoutPlatformSuffix}
+    #else:
+    command_extension={}
+    #command_extension=dict(build_ext=CMakeBuild)
 
     setup(
         name = "pymolfile",
@@ -212,11 +262,17 @@ if __name__ == '__main__':
         url = "https://gitlab.mpcdf.mpg.de/berko/pymolfile",
         zip_safe = False,
         packages = find_packages(),
+        #library_dirs=[
+        #    'build/external/tng/lib'
+        #],
+        libraries = [('molfile_plugin', { 'sources' : ['build/molfile_plugins/compile/lib/libmolfile_plugin.a']})],
         cmdclass= {
             'build_clib' : build_clib,
             'build_ext'  : BuildExtWithoutPlatformSuffix,
         },
+        #distclass=Distribution,
         ext_modules = [
+            #CMakeExtension('molfile', sourcedir='pymolfile/molfile/'),
             libpymolfile_module,
         ],
         py_modules=["pymolfile"],
-- 
GitLab