! 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
+combinators.short-circuit environment fry io io.encodings.utf8
+io.launcher kernel locals make sequences sets splitting system
unicode ;
IN: alien.libraries.finder.linux
: ldconfig-matches? ( lib triple -- ? )
{ [ name-matches? ] [ arch-matches? ] } 2&& ;
+: 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 [ lines ] with-process-reader* 2drop
+ "lib" name append '[ _ swap subseq? ] find nip
+ ] [ f ] if* ;
+
PRIVATE>
M: linux find-library*
- "lib" prepend load-ldconfig-cache
- [ ldconfig-matches? ] with find nip ?last ;
+ { [ find-ldconfig ] [ find-ld ] } 1|| ;