]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/libraries/libraries.factor
alien.libraries: add a "deploy-library" word that marks a library to have its dll...
[factor.git] / basis / alien / libraries / libraries.factor
index 0d255b8d076b67ce5b0435eb9e5c346bd91133ea..6f80900da0c54a1e72832dc58c4162e081455e73 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.strings assocs io.backend
-kernel namespaces destructors ;
+kernel namespaces destructors sequences system io.pathnames ;
 IN: alien.libraries
 
 : dlopen ( path -- dll ) native-string>alien (dlopen) ;
@@ -9,11 +9,15 @@ IN: alien.libraries
 : dlsym ( name dll -- alien ) [ string>symbol ] dip (dlsym) ;
 
 SYMBOL: libraries
+SYMBOL: deploy-libraries
 
 libraries [ H{ } clone ] initialize
+deploy-libraries [ V{ } clone ] initialize
 
 TUPLE: library path abi dll ;
 
+ERROR: no-library name ;
+
 : library ( name -- library ) libraries get at ;
 
 : <library> ( path abi -- library )
@@ -31,4 +35,20 @@ M: library dispose dll>> [ dispose ] when* ;
 
 : add-library ( name path abi -- )
     [ 2drop remove-library ]
-    [ <library> swap libraries get set-at ] 3bi ;
\ No newline at end of file
+    [ <library> swap libraries get set-at ] 3bi ;
+
+: deploy-library ( name -- )
+    dup libraries get key?
+    [ deploy-libraries get 2dup member? [ 2drop ] [ push ] if ]
+    [ no-library ] if ;
+
+<PRIVATE
+HOOK: >deployed-library-path os ( path -- path' )
+
+M: windows >deployed-library-path
+    file-name ;
+M: unix >deployed-library-path
+    file-name "$ORIGIN" prepend-path ;
+M: macosx >deployed-library-path
+    file-name "@executable_path/../Frameworks" prepend-path ;
+PRIVATE>