module Dvda.Codegen.Gcc ( compileWithGcc
) where
import System.Process(runCommand, waitForProcess)
import System.Exit(ExitCode(ExitSuccess))
import Control.Monad(when)
spewGccCall :: Bool
spewGccCall = True
gccString :: FilePath -> FilePath -> String
gccString src obj = "gcc -O2 -std=gnu99 -fPIC -shared -Wall -Wextra -Werror " ++ src ++ " -o " ++ obj
compileWithGcc :: FilePath -> FilePath -> IO ()
compileWithGcc srcname objname = do
let compileString = gccString srcname objname
when spewGccCall $ putStrLn compileString
p <- runCommand compileString
exitCode <- waitForProcess p
when (exitCode /= ExitSuccess) $ error $ "failed compiling " ++ srcname