diff options
author | Tristan Gingold <tgingold@free.fr> | 2018-03-06 18:25:04 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2018-03-06 18:25:04 +0100 |
commit | 0e9e1f63cdf19dc45804d7b8728698f879489ee9 (patch) | |
tree | 5329979b3ab5d5945f02c964baa499ca70620b00 | |
parent | 8a3986828fbb93f82d12535eb970101199ae71df (diff) | |
download | ghdl-0e9e1f63cdf19dc45804d7b8728698f879489ee9.tar.gz ghdl-0e9e1f63cdf19dc45804d7b8728698f879489ee9.tar.bz2 ghdl-0e9e1f63cdf19dc45804d7b8728698f879489ee9.zip |
Add (missing) setup.py
-rw-r--r-- | setup.py | 67 | ||||
-rw-r--r-- | src/vhdl/python/libghdl/__init__.py | 2 |
2 files changed, 68 insertions, 1 deletions
diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..65d130ea5 --- /dev/null +++ b/setup.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python + +from distutils.core import setup, Extension +from distutils.command.build import build +from distutils.errors import CompileError +import distutils.dep_util +import distutils.ccompiler +import subprocess +import os +import os.path + +class GHDLBuild(build): + def copy_if_changed(self, source, destname): + dest = os.path.join(self.build_temp, destname) + if distutils.dep_util.newer(source, dest): + print('copying ' + source) + self.copy_file(source, dest, preserve_times=0) + + def run(self): + # Run original build code + build.run(self) + + self.mkpath(self.build_temp) + + srcdir = os.path.dirname(os.path.abspath(__file__)) + relpath = os.path.relpath(srcdir, self.build_temp) + self.copy_if_changed(os.path.join(srcdir, 'src', 'version.in'), + 'version.ads') + self.copy_if_changed(os.path.join(srcdir, 'src', 'ghdldrv', + 'default_paths.ads.in'), + 'default_paths.ads') + + comp = distutils.ccompiler.new_compiler() + so_file = comp.shared_object_filename('libghdl') + + cmd = ['gnatmake', + '-aI' + os.path.join(srcdir, 'src', 'vhdl', 'python'), + '-aI' + os.path.join(srcdir, 'src', 'vhdl'), + '-aI' + os.path.join(srcdir, 'src', 'psl'), + '-aI' + os.path.join(srcdir, 'src'), + '-aI' + os.path.join(srcdir, 'src', 'ghdldrv'), + '-aI' + os.path.join(srcdir, 'src', 'grt'), + '-z', 'libghdl', + '-o', so_file, '-fPIC', '-gnat05', '-gnata', '-g', + '-bargs', '-shared', '-Llibghdl_', + '-largs', '-shared', '-v' ] + + def compile(): + print cmd + if subprocess.call(cmd, cwd=self.build_temp) != 0: + raise CompileError('compilation failure') + + self.execute(compile, [], 'Compiling ghdl') + dstdir = os.path.join(self.build_lib, 'libghdl') + self.copy_file(os.path.join(self.build_temp, so_file), dstdir) + self.copy_tree(os.path.join(srcdir, "lib",), dstdir) + +setup (name='libghdl', + version='1.0', + description = 'Interface to ghdl, a VHDL analyzer', + author = 'Tristan Gingold', + author_email = 'tgingold@free.fr', + url = 'github.com/tgingold/ghdl', + package_dir = {'libghdl' : 'src/vhdl/python/libghdl'}, + packages = ['libghdl'], + cmdclass = { + 'build': GHDLBuild}) diff --git a/src/vhdl/python/libghdl/__init__.py b/src/vhdl/python/libghdl/__init__.py index 63a34b23c..457d6f2bd 100644 --- a/src/vhdl/python/libghdl/__init__.py +++ b/src/vhdl/python/libghdl/__init__.py @@ -9,7 +9,7 @@ _ext = {'linux': '.so', 'cygwin': '.dll'} # Load the DLL. -_basedir = os.path.join(os.path.dirname(__file__), '..') +_basedir = os.path.dirname(__file__) libghdl = ctypes.CDLL(os.path.join( _basedir, 'libghdl' + _ext.get(sys.platform, '.so'))) |