]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/libraries/finder/linux/linux.factor
alien.libraries.finder.linux: Remove tags like "OS ABI: Linux 2.6.24" from the `...
[factor.git] / basis / alien / libraries / finder / linux / linux.factor
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
6 unicode.categories ;
7 IN: alien.libraries.finder.linux
8
9 <PRIVATE
10
11 CONSTANT: mach-map {
12     { ppc.64 { "libc6" "64bit" } }
13     { x86.32 { "libc6" "x32" } }
14     { x86.64 { "libc6" "x86-64" } }
15 }
16
17 : parse-ldconfig-lines ( string -- triple )
18     [
19         "=>" split1 [ [ blank? ] trim ] bi@
20         [
21             " " split1 [ "()" in? ] trim "," split
22             [ "OS ABI:" head? not ] filter
23         ] dip 3array
24     ] map ;
25
26 : load-ldconfig-cache ( -- seq )
27     "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
28     rest parse-ldconfig-lines ;
29
30 : ldconfig-arch ( -- str )
31     mach-map cpu of { "libc6" } or ;
32
33 : name-matches? ( lib triple -- ? )
34     first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
35
36 : arch-matches? ( lib triple -- ? )
37     [ drop ldconfig-arch ] [ second swap subset? ] bi* ;
38
39 : ldconfig-matches? ( lib triple -- ? )
40     { [ name-matches? ] [ arch-matches? ] } 2&& ;
41
42 : ldconfig-find-soname ( lib -- seq )
43     load-ldconfig-cache [ ldconfig-matches? ] with filter
44     [ third ] map ;
45
46 PRIVATE>
47
48 M: linux find-library*
49     "lib" prepend ldconfig-find-soname [
50         { [ exists? ] [ file-info regular-file? ] } 1&&
51     ] map-find nip ;