File 0002-verilog-add-support-to-use-external-vpp-library.patch of Package mingw64-ngspice

From 53352ca9bf2c459b9fb1a5bed848d7cea9402cc7 Mon Sep 17 00:00:00 2001
From: Ralf Habacker <ralf.habacker@freenet.de>
Date: Tue, 6 Jan 2026 01:01:57 +0100
Subject: [PATCH 2/2] verilog: add support to use external vpp library

---
 configure.ac                   | 43 ++++++++++++++++++++++++++++++++++
 src/xspice/verilog/Makefile.am | 32 +++++++++++++++----------
 2 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index cf78f5acd..694db2875 100644
--- a/configure.ac
+++ b/configure.ac
@@ -293,6 +293,10 @@ AC_ARG_ENABLE([cluster],
 AC_ARG_ENABLE([cmathtests],
     [AS_HELP_STRING([--enable-cmathtests], [Enable ancient tests in src/math/cmaths])])
 
+# --with-vvp: Use external vvp library instead of dummy library in src/xspice/verilog
+AC_ARG_WITH([vvp],
+    [AS_HELP_STRING([--with-vvp[=yes/no]], [use libvvp for verilog instead of embedded dummy library. Default=no.])])
+
 # --enable-help: try to force --ansi option to the compiler
 AC_ARG_ENABLE([help],
     [AS_HELP_STRING([--enable-help], [Force building nghelp (deprecated)])])
@@ -738,6 +742,7 @@ case $with_wingui in
         ;;
     * )
 
+
 # Check for /proc (virtual process information file system)
 AC_CHECK_HEADERS([/proc/meminfo])
 
@@ -1177,6 +1182,44 @@ AC_SUBST([XSPICEDLLIBS])
 
 AM_CONDITIONAL([XSPICE_WANTED], [test "x$enable_xspice" = xyes || test "x$enable_xspice" = x])
 
+have_libvvp=no
+VVP_CFLAGS=""
+VVP_LIBS=""
+if test "x$enable_xspice" = xyes; then
+
+    # 1) Try pkg-config first
+    if test "x$PKG_CONFIG" != "x"; then
+    PKG_CHECK_MODULES([VVP], [libvvp],
+        [have_libvvp=yes],
+        [have_libvvp=no])
+    fi
+
+    # 2) Fallback to manual checks if pkg-config failed
+    if test "x$have_libvvp" != "xyes"; then
+    AC_CHECK_HEADER([libvvp.h],
+        [AC_CHECK_LIB([vvp], [vvp_init],
+        [have_libvvp=yes
+            VVP_LIBS="-lvvp"],
+        [have_libvvp=no])],
+        [have_libvvp=no])
+    fi
+
+    # 3) Enforce --with-vvp
+    if test "x$with_vvp" = "xyes"; then
+        if test "x$have_libvvp" != "xyes"; then
+            AC_MSG_FAILURE([--with-vvp was given, but external libvvp was not found])
+        fi
+    fi
+
+    AC_MSG_NOTICE([VVP support:])
+    AC_MSG_NOTICE([  libvvp requested: $with_vvp])
+    AC_MSG_NOTICE([  libvvp found:  $have_libvvp])
+fi
+AC_SUBST([VVP_CFLAGS])
+AC_SUBST([VVP_LIBS])
+AM_CONDITIONAL([WITH_VVP], [test "x$have_libvvp" == "xyes"])
+
+
 AM_CONDITIONAL([SHORT_CHECK_WANTED], [test "x$enable_shortcheck" = xyes])
 
 
diff --git a/src/xspice/verilog/Makefile.am b/src/xspice/verilog/Makefile.am
index 683e76d50..5b275d1c1 100644
--- a/src/xspice/verilog/Makefile.am
+++ b/src/xspice/verilog/Makefile.am
@@ -22,26 +22,32 @@ initdata2_DATA = ../../include/ngspice/cosim.h \
 
 # Icarus Verilog support: build two shared libraries.
 
-pkglib_LTLIBRARIES = ivlng.la ivlngvpi.la
-ivlng_la_SOURCES = icarus_shim.c icarus_shim.h coroutine_shim.h
-ivlng_la_CFLAGS = -I$(top_srcdir)/src/include
-ivlng_la_LDFLAGS = -module -shared -avoid-version
+noinst_LTLIBRARIES = libivlng.la
+libivlng_la_SOURCES = icarus_shim.c icarus_shim.h coroutine_shim.h
+libivlng_la_CFLAGS  = -I$(top_srcdir)/src/include
 
+pkglib_LTLIBRARIES = ivlngvpi.la
 ivlngvpi_la_SOURCES = vpi.c icarus_shim.h vpi_user_dummy.h coroutine.h coroutine_cosim.h
-ivlngvpi_la_CFLAGS = -I$(top_srcdir)/src/include
-ivlngvpi_la_LDFLAGS = -module -shared  -avoid-version
+ivlngvpi_la_CFLAGS  = -I$(top_srcdir)/src/include
+ivlngvpi_la_LIBADD  = libivlng.la
+ivlngvpi_la_LDFLAGS = -module -avoid-version
 
-# On Windows, symbols in DLLs must be fully resolved.
-# Create a dummy libvvp.DLL so that Icarus Verilog need not be installed
-# for building.
+if DLIBS_FULLY_RESOLVED
+ivlngvpi_la_LDFLAGS += -no-undefined
+endif
 
+if WITH_VVP
+ivlngvpi_la_CPPFLAGS = @VVP_CFLAGS@
+ivlngvpi_la_LIBADD  += @VVP_LIBS@
+else
+# Windows: create a dummy libvvp DLL so symbols are resolved
 if DLIBS_FULLY_RESOLVED
 pkglib_LTLIBRARIES += libvvp.la
 libvvp_la_SOURCES = vpi_dummy.c vpi_user_dummy.h coroutine.h coroutine_cosim.h
-libvvp_la_LDFLAGS = -no-undefined -module -shared -avoid-version
-ivlng_la_LDFLAGS += -no-undefined
-ivlngvpi_la_LIBADD = libvvp.la ivlng.la
-ivlngvpi_la_LDFLAGS += -no-undefined
+libvvp_la_LDFLAGS = -no-undefined
+
+ivlngvpi_la_LIBADD += libvvp.la
+endif
 endif
 
 # Libtool installs unwanted libraries, remove them after installation.
-- 
2.51.0

openSUSE Build Service is sponsored by