2014-04-28 04:41:31 -04:00
|
|
|
! Copyright (C) 2013 Björn Lindqvist, Doug Coleman.
|
2013-11-16 14:58:37 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license
|
2014-06-08 16:30:54 -04:00
|
|
|
USING: alien.libraries.finder arrays assocs
|
2013-11-16 19:33:17 -05:00
|
|
|
combinators.short-circuit io io.encodings.utf8 io.files
|
2014-04-28 04:41:31 -04:00
|
|
|
io.files.info io.launcher kernel sequences sets splitting system
|
2016-03-31 02:29:48 -04:00
|
|
|
unicode ;
|
2013-11-16 14:58:37 -05:00
|
|
|
IN: alien.libraries.finder.linux
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
CONSTANT: mach-map {
|
2014-04-28 04:41:31 -04:00
|
|
|
{ ppc.64 { "libc6" "64bit" } }
|
|
|
|
{ x86.32 { "libc6" "x32" } }
|
|
|
|
{ x86.64 { "libc6" "x86-64" } }
|
2013-11-16 14:58:37 -05:00
|
|
|
}
|
|
|
|
|
2014-04-28 04:41:31 -04:00
|
|
|
: parse-ldconfig-lines ( string -- triple )
|
|
|
|
[
|
|
|
|
"=>" split1 [ [ blank? ] trim ] bi@
|
2014-06-17 17:13:06 -04:00
|
|
|
[
|
|
|
|
" " split1 [ "()" in? ] trim "," split
|
2014-07-03 17:30:15 -04:00
|
|
|
[ [ blank? ] trim ] map
|
2017-01-24 17:45:34 -05:00
|
|
|
[ ": Linux" swap subseq? ] reject
|
2014-06-17 17:13:06 -04:00
|
|
|
] dip 3array
|
2014-04-28 04:41:31 -04:00
|
|
|
] map ;
|
|
|
|
|
|
|
|
: load-ldconfig-cache ( -- seq )
|
|
|
|
"/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
|
|
|
|
rest parse-ldconfig-lines ;
|
2013-11-16 14:58:37 -05:00
|
|
|
|
2014-04-28 04:41:31 -04:00
|
|
|
: ldconfig-arch ( -- str )
|
|
|
|
mach-map cpu of { "libc6" } or ;
|
2013-11-16 14:58:37 -05:00
|
|
|
|
2014-06-08 14:43:15 -04:00
|
|
|
: name-matches? ( lib triple -- ? )
|
2016-03-29 02:01:56 -04:00
|
|
|
first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
|
2014-06-08 14:43:15 -04:00
|
|
|
|
|
|
|
: arch-matches? ( lib triple -- ? )
|
2014-06-17 02:07:13 -04:00
|
|
|
[ drop ldconfig-arch ] [ second swap subset? ] bi* ;
|
2014-06-08 14:43:15 -04:00
|
|
|
|
2014-04-28 04:41:31 -04:00
|
|
|
: ldconfig-matches? ( lib triple -- ? )
|
2014-06-08 14:43:15 -04:00
|
|
|
{ [ name-matches? ] [ arch-matches? ] } 2&& ;
|
2013-11-16 14:58:37 -05:00
|
|
|
|
|
|
|
: ldconfig-find-soname ( lib -- seq )
|
2014-06-08 14:43:15 -04:00
|
|
|
load-ldconfig-cache [ ldconfig-matches? ] with filter
|
|
|
|
[ third ] map ;
|
2013-11-16 14:58:37 -05:00
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
2014-06-07 23:48:09 -04:00
|
|
|
M: linux find-library*
|
2014-06-08 14:43:15 -04:00
|
|
|
"lib" prepend ldconfig-find-soname [
|
2013-11-16 19:09:21 -05:00
|
|
|
{ [ exists? ] [ file-info regular-file? ] } 1&&
|
2017-02-07 13:59:24 -05:00
|
|
|
] find nip ;
|