diff options
-rw-r--r-- | python/libghdl/__init__.py | 29 | ||||
-rw-r--r-- | src/ghdldrv/ghdllocal.ads | 2 | ||||
-rw-r--r-- | src/vhdl/libghdl/libghdl.adb | 5 | ||||
-rw-r--r-- | src/vhdl/libghdl/libghdl.ads | 3 |
4 files changed, 26 insertions, 13 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')) diff --git a/src/ghdldrv/ghdllocal.ads b/src/ghdldrv/ghdllocal.ads index a5c6fb7ef..c59cf25a1 100644 --- a/src/ghdldrv/ghdllocal.ads +++ b/src/ghdldrv/ghdllocal.ads @@ -48,7 +48,7 @@ package Ghdllocal is -- getenv ("GHDL_PREFIX"). Set by Setup_Libraries. Prefix_Env : String_Access := null; - -- Installation prefix (deduced from executable path). + -- Installation prefix (deduced from executable path and without bin/). Exec_Prefix : String_Access; -- Path prefix for libraries. diff --git a/src/vhdl/libghdl/libghdl.adb b/src/vhdl/libghdl/libghdl.adb index b0442b9f4..51cd0dd02 100644 --- a/src/vhdl/libghdl/libghdl.adb +++ b/src/vhdl/libghdl/libghdl.adb @@ -98,6 +98,11 @@ package body Libghdl is return Ghdlcomp.Compile_Analyze_File2 (File (1 .. Len)); end Analyze_File; + procedure Set_Exec_Prefix (Prefix : Thin_String_Ptr; Len : Natural) is + begin + Ghdllocal.Exec_Prefix := new String'(Prefix (1 .. Len)); + end Set_Exec_Prefix; + Gnat_Version : constant String := "unknown compiler version" & ASCII.NUL; pragma Export (C, Gnat_Version, "__gnat_version"); begin diff --git a/src/vhdl/libghdl/libghdl.ads b/src/vhdl/libghdl/libghdl.ads index dbc6b260e..c4edfb9a1 100644 --- a/src/vhdl/libghdl/libghdl.ads +++ b/src/vhdl/libghdl/libghdl.ads @@ -25,6 +25,9 @@ package Libghdl is -- --ieee). Return 0 for success. function Set_Option (Opt : Thin_String_Ptr; Len : Natural) return Integer; + -- Set the prefix (used to locate libraries). + procedure Set_Exec_Prefix (Prefix : Thin_String_Ptr; Len : Natural); + -- To be called before Analyze_File to initialize analysis. procedure Analyze_Init; |