]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/libraries/finder/linux/linux.factor
alien.libraries.finder: split into sub-vocabularies and implement macosx better.
[factor.git] / basis / alien / libraries / finder / linux / linux.factor
1 ! Copyright (C) 2013 Björn Lindqvist
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: alien.libraries alien.libraries.finder assocs io
5 io.encodings.utf8 io.launcher kernel sequences splitting system
6 ;
7
8 IN: alien.libraries.finder.linux
9
10 <PRIVATE
11
12 CONSTANT: mach-map {
13     { ppc.64 "libc6,64bit" }
14     { x86.32 "libc6,x86-32" }
15     { x86.64 "libc6,x86-64" }
16 }
17
18 : ldconfig-cache ( -- seq )
19     "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader rest
20     [ "=>" "" replace "\t " split harvest ] map ;
21
22 : ldconfig-filter ( -- str )
23     mach-map cpu of "libc6" or "(" ")" surround ;
24
25 : ldconfig-matches? ( lib this-lib this-arch -- ? )
26     [ start 0 = ] [ ldconfig-filter = ] bi* and ;
27
28 : ldconfig-find-soname ( lib -- seq )
29     ldconfig-cache [ first2 ldconfig-matches? ] with filter [ first ] map ;
30
31 PRIVATE>
32
33 M: linux find-library
34     "lib" ".so" surround ldconfig-find-soname
35     [ dlopen dll-valid? ] map-find nip ;
36