Skip to content

Instantly share code, notes, and snippets.

@Tener
Created March 17, 2010 01:06
Show Gist options
  • Save Tener/334761 to your computer and use it in GitHub Desktop.
Save Tener/334761 to your computer and use it in GitHub Desktop.
#!/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