+--------------------------------------------------------------------------------------
+checkOptions :: GhcMode -> [String] -> [String] -> IO ()
+ -- Final sanity checking before kicking of a compilation (pipeline).
+checkOptions mode srcs objs = do
+ -- -ohi sanity check
+ ohi <- readIORef v_Output_hi
+ if (isJust ohi &&
+ (mode == DoMake || mode == DoInteractive || srcs `lengthExceeds` 1))
+ then throwDyn (UsageError "-ohi can only be used when compiling a single source file")
+ else do
+
+ -- -o sanity checking
+ o_file <- readIORef v_Output_file
+ if (srcs `lengthExceeds` 1 && isJust o_file && mode /= DoLink && mode /= DoMkDLL)
+ then throwDyn (UsageError "can't apply -o to multiple source files")
+ else do
+
+ -- Check that there are some input files (except in the interactive case)
+ if null srcs && null objs && mode /= DoInteractive
+ then throwDyn (UsageError "no input files")
+ else do
+
+ -- Complain about any unknown flags
+ let unknown_opts = [ f | f@('-':_) <- srcs ]
+ when (notNull unknown_opts) (unknownFlagsErr unknown_opts)
+
+ -- Verify that output files point somewhere sensible.
+ verifyOutputFiles
+
+
+--------------------------------------------------------------------------------------
+compileFiles :: GhcMode
+ -> [String] -- Source files
+ -> IO [String] -- Object files
+compileFiles mode srcs = do
+ stop_flag <- readIORef v_GhcModeFlag
+
+ -- Do the business; save the DynFlags at the
+ -- start, so we can restore them before each file
+ saveDynFlags
+ mapM (compileFile mode stop_flag) srcs
+
+
+compileFile mode stop_flag src = do
+ restoreDynFlags
+
+ exists <- doesFileExist src
+ when (not exists) $
+ throwDyn (CmdLineError ("file `" ++ src ++ "' does not exist"))
+
+ -- We compile in two stages, because the file may have an
+ -- OPTIONS pragma that affects the compilation pipeline (eg. -fvia-C)
+ let (basename, suffix) = splitFilename src
+
+ -- just preprocess (Haskell source only)
+ let src_and_suff = (src, getFileSuffix src)
+ let not_hs_file = not (haskellish_src_file src)
+ pp <- if not_hs_file || mode == StopBefore Hsc || mode == StopBefore HsPp
+ then return src_and_suff else do
+ phases <- genPipeline (StopBefore Hsc) stop_flag
+ False{-not persistent-} defaultHscLang
+ src_and_suff
+ pipeLoop phases src_and_suff False{-no linking-} False{-no -o flag-}
+ basename suffix
+
+ -- rest of compilation
+ hsc_lang <- dynFlag hscLang
+ phases <- genPipeline mode stop_flag True hsc_lang pp
+ (r,_) <- pipeLoop phases pp (mode==DoLink || mode==DoMkDLL)
+ True{-use -o flag-} basename suffix
+ return r
+
+
+--------------------------------------------------------------------------------------
+doMake :: [String] -> IO ()
+doMake [] = throwDyn (UsageError "no input files")
+doMake srcs = do
+ dflags <- getDynFlags
+ state <- cmInit Batch
+ graph <- cmDepAnal state dflags srcs
+ (_, ok_flag, _) <- cmLoadModules state dflags graph
+ when (failed ok_flag) (exitWith (ExitFailure 1))
+ return ()
+
+
+
+--------------------------------------------------------------------------------------
+showBanners :: GhcMode -> FilePath -> [String] -> IO ()
+showBanners mode conf_file static_opts = do