From 0e9e1f63cdf19dc45804d7b8728698f879489ee9 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 6 Mar 2018 18:25:04 +0100 Subject: Add (missing) setup.py --- setup.py | 67 +++++++++++++++++++++++++++++++++++++ src/vhdl/python/libghdl/__init__.py | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 setup.py 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'))) -- cgit v1.2.3