Created
March 17, 2010 01:06
-
-
Save Tener/334761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
-- This is a simple script to convert .a libs into .so ones. | |
-- More specifically I used it to convert static libs from LLVM for usage with GHCi. | |
import System.Directory | |
import System.FilePath | |
import System.Process | |
import Control.Applicative | |
import Data.List ( isSuffixOf ) | |
import Text.Printf | |
from = "llvm-static" -- copied contents of /usr/lib/llvm or similar | |
to = "llvm-dyn" | |
tmpdir = "tmp" | |
main = do | |
dynlibs <- filter (".a" `isSuffixOf`) <$> getDirectoryContents from | |
mapM_ onelib dynlibs | |
onelib fn = do | |
let tmp = tmpdir </> fn | |
fn_so = (dropExtension fn <.> "so") | |
createDirectoryIfMissing True tmp | |
copyFile (from </> fn) (tmp </> fn) | |
putStr (printf "Running 'ar' for %s... " fn) | |
waitForProcess =<< runProcess "ar" ["-x",fn] (Just tmp) Nothing Nothing Nothing Nothing | |
ofiles <- filter (".o" `isSuffixOf`) <$> getDirectoryContents tmp | |
waitForProcess =<< runProcess "gcc" (["-shared"] ++ ofiles ++ ["-o", fn_so]) (Just tmp) Nothing Nothing Nothing Nothing | |
copyFile (tmp </> fn_so) (to </> fn_so) | |
putStrLn "OK." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment