1 ! Copyright (C) 2013 Björn Lindqvist, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: alien.libraries alien.libraries.finder arrays assocs
4 combinators.short-circuit io io.encodings.utf8 io.files
5 io.files.info io.launcher kernel sequences sets splitting system
7 IN: alien.libraries.finder.linux
12 { ppc.64 { "libc6" "64bit" } }
13 { x86.32 { "libc6" "x32" } }
14 { x86.64 { "libc6" "x86-64" } }
17 : parse-ldconfig-lines ( string -- triple )
19 "=>" split1 [ [ blank? ] trim ] bi@
20 [ " " split1 [ "()" in? ] trim "," split ] dip 3array
23 : load-ldconfig-cache ( -- seq )
24 "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
25 rest parse-ldconfig-lines ;
27 : ldconfig-arch ( -- str )
28 mach-map cpu of { "libc6" } or ;
30 : name-matches? ( lib triple -- ? )
31 first swap ?head [ ?first CHAR: . = ] [ f ] if ;
33 : arch-matches? ( lib triple -- ? )
34 nip second ldconfig-arch subset? ;
36 : ldconfig-matches? ( lib triple -- ? )
37 { [ name-matches? ] [ arch-matches? ] } 2&& ;
39 : ldconfig-find-soname ( lib -- seq )
40 load-ldconfig-cache [ ldconfig-matches? ] with filter
45 M: linux find-library*
46 "lib" prepend ldconfig-find-soname [
47 { [ exists? ] [ file-info regular-file? ] } 1&&