aboutsummaryrefslogtreecommitdiffstats
path: root/python/libghdl
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-07-09 19:49:51 +0200
committerTristan Gingold <tgingold@free.fr>2019-07-09 19:49:51 +0200
commitcbcaf392226786aee517d5fe4af3e77fddc23d80 (patch)
tree06e7143d6e9f4fd85e466231dae7322fce2e5fb9 /python/libghdl
parentc42f7a633bd81d5485c728ba49c3d17ac54feb63 (diff)
downloadghdl-cbcaf392226786aee517d5fe4af3e77fddc23d80.tar.gz
ghdl-cbcaf392226786aee517d5fe4af3e77fddc23d80.tar.bz2
ghdl-cbcaf392226786aee517d5fe4af3e77fddc23d80.zip
libghdl: automatically set the prefix from shared library
Diffstat (limited to 'python/libghdl')
-rw-r--r--python/libghdl/__init__.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/python/libghdl/__init__.py b/python/libghdl/__init__.py
index 92a5ba1f0..1a8120a97 100644
--- a/python/libghdl/__init__.py
+++ b/python/libghdl/__init__.py
@@ -1,10 +1,13 @@
import ctypes
import os
import sys
-from os.path import dirname, join, exists
+from os.path import dirname, join, exists, normpath
from shutil import which
from libghdl.version import __version__
+def _to_char_p(arg):
+ return ctypes.c_char_p(arg), len(arg)
+
def _get_libghdl_name():
"""Get the name of the libghdl library (with version and extension)"""
@@ -29,12 +32,20 @@ def _check_libghdl_libdir(libdir, basename):
def _check_libghdl_bindir(bindir, basename):
if bindir is None:
return None
- return _check_libghdl_libdir(join(bindir, '..', 'lib'), basename)
+ return _check_libghdl_libdir(normpath(join(bindir, '..', 'lib')), basename)
def _get_libghdl_path():
"""Locate the directory where the shared library is"""
basename = _get_libghdl_name()
+ # Try GHDL_PREFIX
+ r = os.environ.get('GHDL_PREFIX')
+ if r is not None:
+ # GHDL_PREFIX is the prefix of the vhdl libraries, so remove the
+ # last path component.
+ r = _check_libghdl_libdir(dirname(r), basename)
+ if r is not None:
+ return r
# Try VUNIT_GHDL_PATH (path of the ghdl binary when using VUnit).
r = _check_libghdl_bindir (os.environ.get('VUNIT_GHDL_PATH'), basename)
if r is not None:
@@ -52,7 +63,7 @@ def _get_libghdl_path():
if r is not None:
return r
# Try when running from the build directory
- r = join(dirname(__file__), '..', '..', 'lib')
+ r = normpath(join(dirname(__file__), '..', '..', 'lib'))
r = _check_libghdl_libdir(r, basename)
if r is not None:
return r
@@ -67,10 +78,9 @@ libghdl = ctypes.CDLL(_libghdl_path)
# Initialize it.
libghdl.libghdl_init()
-
-def _to_char_p(arg):
- return ctypes.c_char_p(arg), len(arg)
-
+# Set the prefix in order to locate the vhdl libraries.
+libghdl.libghdl__set_exec_prefix(
+ *_to_char_p(dirname(dirname(_libghdl_path)).encode('utf-8')))
def set_option(opt):
"Set option OPT. Return true iff the option is known and handled"
@@ -87,8 +97,3 @@ def analyze_file(fname):
def disp_config():
return libghdl.ghdllocal__disp_config_prefixes()
-
-if False:
- _prefix = os.environ.get("LIBGHDL_PREFIX") or '--PREFIX=%s' % join(dirname(_libghdl_path), 'ghdl')
- # print('ghdl prefix: {}'.format(_prefix))
- set_option(_prefix.encode('utf-8'))