module Distribution.Simple.Program.Ld (
combineObjectFiles,
) where
import Distribution.Simple.Program.Types
( ConfiguredProgram(..) )
import Distribution.Simple.Program.Run
( programInvocation, multiStageProgramInvocation
, runProgramInvocation )
import Distribution.Verbosity
( Verbosity )
import System.Directory
( renameFile )
import System.FilePath
( (<.>) )
combineObjectFiles :: Verbosity -> ConfiguredProgram
-> FilePath -> [FilePath] -> IO ()
combineObjectFiles verbosity ld target files =
let simpleArgs = ["-r", "-o", target]
initialArgs = ["-r", "-o", target]
middleArgs = ["-r", "-o", target, tmpfile]
finalArgs = middleArgs
simple = programInvocation ld simpleArgs
initial = programInvocation ld initialArgs
middle = programInvocation ld middleArgs
final = programInvocation ld finalArgs
invocations = multiStageProgramInvocation
simple (initial, middle, final) files
in run invocations
where
tmpfile = target <.> "tmp"
run [] = return ()
run [inv] = runProgramInvocation verbosity inv
run (inv:invs) = do runProgramInvocation verbosity inv
renameFile target tmpfile
run invs