summaryrefslogtreecommitdiff
path: root/module/system
diff options
context:
space:
mode:
authorMike Gran <spk121@yahoo.com>2021-03-13 09:09:30 -0800
committerMike Gran <spk121@yahoo.com>2021-03-13 09:09:30 -0800
commit5a1e78a27817d339d80f28515bd8a57c7eb6b65e (patch)
treef58adbdfa1f3b6b1de9241efd1cfc27e93e0ca50 /module/system
parentdb9725fd02d49effaa9e40413b507cfd1804377e (diff)
downloadguile-5a1e78a27817d339d80f28515bd8a57c7eb6b65e.tar.gz
On Cygwin, 'lib' DLLs use 'cyg' prefix
When using automake and libtool to build DLLs on Cygwin, libtool will rename libXXX to cygXXX. 'load-foreign-library' should emulate libltdl behavior and search for DLLs using that convention. * module/system/foreign-library.scm (lib->cyg): new helper function (load-foreign-library): add rename-on-cygwin? option to rename libraries using Cygwin semantics * test-suite/tests/foreign.test: new test section 'lib->cyg' * doc/ref/api-foreign.text: document new rename-on-cygwin? option for load-foreign-library
Diffstat (limited to 'module/system')
-rw-r--r--module/system/foreign-library.scm24
1 files changed, 23 insertions, 1 deletions
diff --git a/module/system/foreign-library.scm b/module/system/foreign-library.scm
index eaeb26700..d53e293ef 100644
--- a/module/system/foreign-library.scm
+++ b/module/system/foreign-library.scm
@@ -30,6 +30,7 @@
ltdl-library-path
guile-system-extensions-path
+ lib->cyg
load-foreign-library
foreign-library?
foreign-library-pointer
@@ -152,13 +153,32 @@
'())
(guile-system-extensions-path)))
+(define (lib->cyg name)
+ "Convert a standard shared library name to a Cygwin shared library
+name."
+ (if (not name)
+ #f
+ (let ((start (1+ (or (string-index-right
+ name
+ (lambda (c) (or (char=? #\\ c) (char=? #\/ c))))
+ -1))))
+ (cond
+ ((>= (+ 3 start) (string-length name))
+ name)
+ ((string= name "lib" start (+ start 3))
+ (string-append (substring name 0 start)
+ "cyg"
+ (substring name (+ start 3))))
+ (else
+ name)))))
+
(define* (load-foreign-library #:optional filename #:key
(extensions system-library-extensions)
(search-ltdl-library-path? #t)
(search-path (default-search-path
search-ltdl-library-path?))
(search-system-paths? #t)
- (lazy? #t) (global? #f))
+ (lazy? #t) (global? #f) (rename-on-cygwin? #t))
(define (error-not-found)
(scm-error 'misc-error "load-foreign-library"
"file: ~S, message: ~S"
@@ -168,6 +188,8 @@
(logior (if lazy? RTLD_LAZY RTLD_NOW)
(if global? RTLD_GLOBAL RTLD_LOCAL)))
(define (dlopen* name) (dlopen name flags))
+ (if (and rename-on-cygwin? (string-contains %host-type "cygwin"))
+ (set! filename (lib->cyg filename)))
(make-foreign-library
filename
(cond