1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-24 12:20:20 +02:00

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
This commit is contained in:
Mike Gran 2021-03-13 09:09:30 -08:00
parent db9725fd02
commit 5a1e78a278
3 changed files with 64 additions and 1 deletions

View file

@ -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