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 [ "OS ABI:" head? not ] filter
26 : load-ldconfig-cache ( -- seq )
27 "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
28 rest parse-ldconfig-lines ;
30 : ldconfig-arch ( -- str )
31 mach-map cpu of { "libc6" } or ;
33 : name-matches? ( lib triple -- ? )
34 first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
36 : arch-matches? ( lib triple -- ? )
37 [ drop ldconfig-arch ] [ second swap subset? ] bi* ;
39 : ldconfig-matches? ( lib triple -- ? )
40 { [ name-matches? ] [ arch-matches? ] } 2&& ;
42 : ldconfig-find-soname ( lib -- seq )
43 load-ldconfig-cache [ ldconfig-matches? ] with filter
48 M: linux find-library*
49 "lib" prepend ldconfig-find-soname [
50 { [ exists? ] [ file-info regular-file? ] } 1&&