2009-07-02 19:35:02 -04:00
|
|
|
! Copyright (C) 2009 Jeremy Hughes.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-02 15:33:14 -04:00
|
|
|
USING: accessors arrays combinators fry generalizations
|
2009-07-01 18:43:51 -04:00
|
|
|
io.encodings.ascii io.files io.files.temp io.launcher kernel
|
2009-07-02 18:32:39 -04:00
|
|
|
locals sequences system ;
|
2009-07-02 18:46:19 -04:00
|
|
|
IN: alien.inline.compiler
|
2009-07-01 18:43:51 -04:00
|
|
|
|
2009-07-02 18:43:27 -04:00
|
|
|
SYMBOL: C
|
|
|
|
SYMBOL: C++
|
|
|
|
|
2009-07-01 18:43:51 -04:00
|
|
|
: library-suffix ( -- str )
|
|
|
|
os {
|
|
|
|
{ [ dup macosx? ] [ drop ".dylib" ] }
|
|
|
|
{ [ dup unix? ] [ drop ".so" ] }
|
|
|
|
{ [ dup windows? ] [ drop ".dll" ] }
|
|
|
|
} cond ;
|
|
|
|
|
2009-07-02 15:33:14 -04:00
|
|
|
: src-suffix ( lang -- str )
|
|
|
|
{
|
2009-07-02 18:32:39 -04:00
|
|
|
{ C [ ".c" ] }
|
|
|
|
{ C++ [ ".cpp" ] }
|
2009-07-02 15:33:14 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-07-02 18:32:39 -04:00
|
|
|
:: compile-to-object ( lang contents name -- )
|
|
|
|
name ".o" append temp-file
|
|
|
|
contents name lang src-suffix append temp-file
|
|
|
|
[ ascii set-file-contents ] keep 2array
|
|
|
|
{ "gcc" "-fPIC" "-c" "-o" } prepend try-process ;
|
2009-07-01 18:43:51 -04:00
|
|
|
|
2009-07-02 15:33:14 -04:00
|
|
|
: link-object ( args name -- )
|
2009-07-01 18:43:51 -04:00
|
|
|
[ "lib" prepend library-suffix append ] [ ".o" append ] bi
|
|
|
|
[ temp-file ] bi@ 2array
|
|
|
|
os {
|
|
|
|
{ [ dup linux? ]
|
2009-07-02 15:33:14 -04:00
|
|
|
[ drop { "gcc" "-shared" "-o" } ] }
|
2009-07-01 18:43:51 -04:00
|
|
|
{ [ dup macosx? ]
|
2009-07-02 15:33:14 -04:00
|
|
|
[ drop { "gcc" "-g" "-prebind" "-dynamiclib" "-o" } ] }
|
2009-07-01 18:43:51 -04:00
|
|
|
[ name>> "unimplemented for: " prepend throw ]
|
2009-07-02 15:33:14 -04:00
|
|
|
} cond prepend prepend try-process ;
|
2009-07-01 18:43:51 -04:00
|
|
|
|
2009-07-02 18:32:39 -04:00
|
|
|
:: compile-to-library ( lang args contents name -- )
|
|
|
|
lang contents name compile-to-object
|
|
|
|
args name link-object ;
|