+
+-- -----------------------------------------------------------------------------
+-- Option sanity checks
+
+checkOptions :: GhcMode -> [String] -> [String] -> IO ()
+ -- Final sanity checking before kicking off a compilation (pipeline).
+checkOptions mode srcs objs = do
+ -- Complain about any unknown flags
+ let unknown_opts = [ f | f@('-':_) <- srcs ]
+ when (notNull unknown_opts) (unknownFlagsErr unknown_opts)
+
+ -- -ohi sanity check
+ ohi <- readIORef v_Output_hi
+ if (isJust ohi &&
+ (isCompManagerMode mode || 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 && not (isLinkMode mode))
+ 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 && not (isInterpretiveMode mode)
+ then throwDyn (UsageError "no input files")
+ else do
+
+ -- Verify that output files point somewhere sensible.
+ verifyOutputFiles
+
+-- -----------------------------------------------------------------------------
+-- Compile files in one-shot mode.
+
+compileFiles :: GhcMode
+ -> DynFlags
+ -> [String] -- Source files
+ -> IO [String] -- Object files
+compileFiles mode dflags srcs = mapM (compileFile mode dflags) srcs
+
+
+-- ----------------------------------------------------------------------------
+-- Run --make mode
+
+doMake :: DynFlags -> [String] -> IO ()
+doMake dflags [] = throwDyn (UsageError "no input files")
+doMake dflags srcs = do
+ state <- cmInit Batch dflags
+ graph <- cmDepAnal state srcs
+ (_, ok_flag, _) <- cmLoadModules state graph
+ when (failed ok_flag) (exitWith (ExitFailure 1))
+ return ()
+
+-- ---------------------------------------------------------------------------
+-- Various banners and verbosity output.
+
+showBanners :: GhcMode -> DynFlags -> [String] -> IO ()
+showBanners mode dflags static_opts = do
+ let verb = verbosity dflags
+
+ -- Show the GHCi banner
+# ifdef GHCI
+ when (isInteractiveMode mode && verb >= 1) $
+ hPutStrLn stdout ghciWelcomeMsg
+# endif
+
+ -- Display details of the configuration in verbose mode
+ when (verb >= 2) $
+ do hPutStr stderr "Glasgow Haskell Compiler, Version "
+ hPutStr stderr cProjectVersion
+ hPutStr stderr ", for Haskell 98, compiled by GHC version "
+ hPutStrLn stderr cBooterVersion
+
+ when (verb >= 3) $
+ dumpPackages dflags
+
+ when (verb >= 3) $
+ hPutStrLn stderr ("Hsc static flags: " ++ unwords static_opts)