1 ! Copyright (C) 2013 Björn Lindqvist, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: 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@
21 " " split1 [ "()" in? ] trim "," split
22 [ [ blank? ] trim ] map
23 [ ": Linux" swap subseq? ] reject
27 : load-ldconfig-cache ( -- seq )
28 "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
29 rest parse-ldconfig-lines ;
31 : ldconfig-arch ( -- str )
32 mach-map cpu of { "libc6" } or ;
34 : name-matches? ( lib triple -- ? )
35 first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
37 : arch-matches? ( lib triple -- ? )
38 [ drop ldconfig-arch ] [ second swap subset? ] bi* ;
40 : ldconfig-matches? ( lib triple -- ? )
41 { [ name-matches? ] [ arch-matches? ] } 2&& ;
45 M: linux find-library*
46 "lib" prepend load-ldconfig-cache
47 [ ldconfig-matches? ] with find nip ?last ;