diff options
author | Tristan Gingold <tgingold@free.fr> | 2023-01-22 09:42:09 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2023-01-22 09:42:09 +0100 |
commit | 55dfa111c5eeedc0ffc59282992169ad7bf571af (patch) | |
tree | 00d38a48165f8f8ceae5642dbf920f6d99335068 | |
parent | eaf79618a20465ef015cca2810f6f139bd9b0cf0 (diff) | |
download | ghdl-55dfa111c5eeedc0ffc59282992169ad7bf571af.tar.gz ghdl-55dfa111c5eeedc0ffc59282992169ad7bf571af.tar.bz2 ghdl-55dfa111c5eeedc0ffc59282992169ad7bf571af.zip |
Add scripts/win-dll.py and adjust Makefile.in
-rw-r--r-- | Makefile.in | 25 | ||||
-rw-r--r-- | scripts/win-dll.py | 58 | ||||
-rw-r--r-- | setup-standalone.in | 7 |
3 files changed, 79 insertions, 11 deletions
diff --git a/Makefile.in b/Makefile.in index bbc7003d6..6bff65f45 100644 --- a/Makefile.in +++ b/Makefile.in @@ -50,6 +50,7 @@ sundials_ldflags=@sundials_ldflags@ INSTALL_PROGRAM=install -m 755 INSTALL_DATA=install -m 644 +PYTHON=python3 PWD=$(CURDIR) DESTDIR= bindir=$(prefix)/bin @@ -226,8 +227,8 @@ uninstall.mcode.program: install.mcode: install.mcode.program install.vhdllib install.mcode.deps.dll: - for f in $$(ldd ghdl_mcode$(EXEEXT) | sed -n -e '/Windows/d' -e 's/.*=> \(.*\) .*/\1/p'); do \ - $(INSTALL_PROGRAM) -p $$f "$(DESTDIR)$(bindir)/"; \ + for f in $$($(PYTHON) $(srcdir)/scripts/win-dll.py ghdl_mcode$(EXEEXT)); do \ + $(INSTALL_PROGRAM) -p $$f "$(DESTDIR)$(bindir)/"; \ done uninstall.mcode: uninstall.mcode.program uninstall.vhdllib @@ -514,8 +515,12 @@ install.libghdl.false: install.libghdl: install.libghdl.$(enable_libghdl) copy.libghdl.deps.dll: - for f in $$(ldd lib/$(libghdl_name) | sed -n -e '/Windows/d' -e 's/.*=> \(.*\) .*/\1/p'); do \ - $(INSTALL_PROGRAM) -p $$f "lib/"; \ + $(MKDIR) -p bin + ldd lib/$(libghdl_name) +# Set IFS to handle CR-LF end of lines + IFS=$$'\r\n\t '; \ + for f in $$($(PYTHON) $(srcdir)/scripts/win-dll.py lib/$(libghdl_name)); do\ + $(INSTALL_PROGRAM) -p $$f "bin/"; \ done copy.libghdl.deps.dylib: @@ -676,8 +681,8 @@ setup-standalone.py: $(srcdir)/setup-standalone.in ) > $@ python-wheel: setup-standalone.py lib/$(libghdl_name) libs copy.libghdl.deps$(SOEXT) - rm -rf dist-wheel - mkdir dist-wheel + $(RM) -rf dist-wheel + $(MKDIR) dist-wheel # Copy pyGHDL $(CP) -Rp $(srcdir)/pyGHDL dist-wheel/ # Copy libraries @@ -687,8 +692,12 @@ python-wheel: setup-standalone.py lib/$(libghdl_name) libs copy.libghdl.deps$(SO $(LIBDST_DIR)/$$d/* dist-wheel/pyGHDL/lib/ghdl/$$d; \ done # Copy libghdl - $(INSTALL_PROGRAM) -p lib/lib*$(SOEXT) dist-wheel/pyGHDL/lib/ - + $(INSTALL_PROGRAM) -p lib/$(libghdl_name) dist-wheel/pyGHDL/lib/ +# Copy dll + if ls bin/lib*.dll 2> /dev/null; then \ + $(MKDIR) -p dist-wheel/pyGHDL/bin; \ + $(INSTALL_PROGRAM) -p bin/lib*.dll dist-wheel/pyGHDL/bin; \ + fi ####################### clean ############################################ diff --git a/scripts/win-dll.py b/scripts/win-dll.py new file mode 100644 index 000000000..e77e7ed12 --- /dev/null +++ b/scripts/win-dll.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# Get non-system DLL dependencies +import pefile +import os +import os.path +import sys + +def is_system(filename): + """Return true if the file is a system file. Very ad-hoc.""" + return filename.startswith('/c/Windows') + +def get_imports(filename): + """Return list of dll imports""" + if is_system(filename): + return [] + with pefile.PE(filename) as pe: + try: + imports = pe.DIRECTORY_ENTRY_IMPORT + except AttributeError: + imports = [] + return [e.dll.decode() for e in imports] + +def search_dll(name, libraries_path): + """Search :param name: in :param libraries_path:""" + for path in libraries_path: + filename = os.path.join(path, name) + if os.path.isfile(filename): + return filename + return None + +def get_dependencies(name, libraries_path, cache): + """Return the non-system dll dependencies of :param name:""" + deps = get_imports(name) + res = [] + for lib in deps: + if lib in cache: + continue + # Search on the path + filename = search_dll(lib, libraries_path) + # Always add in the cache + cache[lib] = filename + if filename is not None: + if not is_system(filename): + res.append(filename) + res.extend(get_dependencies(filename, libraries_path, cache)) + return res + +if __name__ == '__main__': + if len(sys.argv) != 2: + print('usage: {} ldd-file'.format(sys.argv[0])) + sys.exit(1) + + libraries_path = os.environ['PATH'].split(os.pathsep) + filename = sys.argv[1] + cache = {} + res = get_dependencies(filename, libraries_path, cache) + for f in res: + print(f) diff --git a/setup-standalone.in b/setup-standalone.in index 7c7c8d4ff..1cbd6a86f 100644 --- a/setup-standalone.in +++ b/setup-standalone.in @@ -1,4 +1,4 @@ -# ============================================================================= +# == -*- python -*- =========================================================== # ____ _ _ ____ _ # _ __ _ _ / ___| | | | _ \| | # | '_ \| | | | | _| |_| | | | | | @@ -33,7 +33,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ # -from setuptools import setup, find_packages, Distribution +from setuptools import setup, find_namespace_packages, Distribution from pathlib import Path from pyTooling.Packaging import loadRequirementsFile @@ -55,6 +55,7 @@ package_data=[] package_data.extend(glob.glob(dist_dir+"/lib/ghdl/**/*.vhdl", recursive=True)) package_data.extend(glob.glob(dist_dir+"/lib/ghdl/**/*.cf", recursive=True)) package_data.extend(glob.glob(dist_dir+"/lib/lib*" + soext)) +package_data.extend(glob.glob(dist_dir+"/bin/lib*" + soext)) package_data=[x[len(dist_dir)+1:] for x in package_data] setup( @@ -70,7 +71,7 @@ setup( project_urls={"Documentation": "https://ghdl.github.io/ghdl", "Source Code": "https://github.com/ghdl/ghdl", "Issue Tracker": "https://github.com/ghdl/ghdl/issues"}, - packages=find_packages("dist-wheel"), + packages=find_namespace_packages("dist-wheel"), package_dir={"": "dist-wheel"}, classifiers=[ "Programming Language :: Python :: 3 :: Only", |