]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/libraries/finder/linux/linux.factor
core: subseq-index? -> subseq-of?
[factor.git] / basis / alien / libraries / finder / linux / linux.factor
index 234d688526a72b6763fcedc8b4a17fbe1f868b67..58e5050da3b201bb7994e95eb8c788cb05a3c7ca 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2013 Björn Lindqvist, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license
 USING: alien.libraries.finder arrays assocs
-combinators.short-circuit io io.encodings.utf8 io.files
-io.files.info io.launcher kernel sequences sets splitting system
-unicode.categories ;
+combinators.short-circuit environment io io.encodings.utf8
+io.launcher kernel make sequences sets splitting system
+unicode ;
 IN: alien.libraries.finder.linux
 
 <PRIVATE
@@ -16,23 +16,23 @@ CONSTANT: mach-map {
 
 : parse-ldconfig-lines ( string -- triple )
     [
-        "=>" split1 [ [ blank? ] trim ] bi@
+        "=>" split1 [ [ unicode:blank? ] trim ] bi@
         [
             " " split1 [ "()" in? ] trim "," split
-            [ [ blank? ] trim ] map
-            [ "OS ABI:" head? ] reject
+            [ [ unicode:blank? ] trim ] map
+            [ ": Linux" subseq-of? ] reject
         ] dip 3array
     ] map ;
 
 : load-ldconfig-cache ( -- seq )
-    "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
-    rest parse-ldconfig-lines ;
+    "/sbin/ldconfig -p" utf8 [ read-lines ] with-process-reader*
+    2drop [ f ] [ rest parse-ldconfig-lines ] if-empty ;
 
 : ldconfig-arch ( -- str )
     mach-map cpu of { "libc6" } or ;
 
 : name-matches? ( lib triple -- ? )
-    first swap ?head [ ?first ".-" member? ] [ drop f ] if ;
+    first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
 
 : arch-matches? ( lib triple -- ? )
     [ drop ldconfig-arch ] [ second swap subset? ] bi* ;
@@ -40,13 +40,20 @@ CONSTANT: mach-map {
 : ldconfig-matches? ( lib triple -- ? )
     { [ name-matches? ] [ arch-matches? ] } 2&& ;
 
-: ldconfig-find-soname ( lib -- seq )
-    load-ldconfig-cache [ ldconfig-matches? ] with filter
-    [ third ] map ;
+: find-ldconfig ( name -- path/f )
+    "lib" prepend load-ldconfig-cache
+    [ ldconfig-matches? ] with find nip ?last ;
+
+:: find-ld ( name -- path/f )
+    "LD_LIBRARY_PATH" os-env [
+        [
+            "ld" , "-t" , ":" split [ "-L" , , ] each
+            "-o" , "/dev/null" , "-l" name append ,
+        ] { } make utf8 [ read-lines ] with-process-reader* 2drop
+        "lib" name append '[ _ subseq-of? ] find nip
+    ] [ f ] if* ;
 
 PRIVATE>
 
 M: linux find-library*
-    "lib" prepend ldconfig-find-soname [
-        { [ exists? ] [ file-info regular-file? ] } 1&&
-    ] map-find nip ;
+    { [ find-ldconfig ] [ find-ld ] } 1|| ;