- -- mkdependHS is special
- when (mode == DoMkDependHS) beginMkDependHS
-
- -- make/interactive require invoking the compilation manager
- if (mode == DoMake) then beginMake srcs else do
- if (mode == DoInteractive) then beginInteractive srcs else do
-
- -- sanity checking
- o_file <- readIORef v_Output_file
- ohi <- readIORef v_Output_hi
- if length srcs > 1 && (isJust ohi || (isJust o_file && mode /= DoLink))
- then throwDyn (UsageError "can't apply -o or -ohi options to multiple source files")
- else do
-
- if null srcs then throwDyn (UsageError "no input files") else do
-
- let compileFile src = do
- writeIORef v_Driver_state saved_driver_state
- writeIORef v_DynFlags init_dyn_flags
-
- -- 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
- pp <- if not (haskellish_file src) || mode == StopBefore Hsc
- then return src else do
- phases <- genPipeline (StopBefore Hsc) stop_flag
- False{-not persistent-} defaultHscLang src
- pipeLoop phases src False{-no linking-} False{-no -o flag-}
- basename suffix
-
- -- rest of compilation
- dyn_flags <- readIORef v_DynFlags
- phases <- genPipeline mode stop_flag True (hscLang dyn_flags) pp
- r <- pipeLoop phases pp (mode==DoLink) True{-use -o flag-}
- basename suffix
- return r
-
- o_files <- mapM compileFile srcs
-
- when (mode == DoMkDependHS) endMkDependHS
- when (mode == DoLink) (doLink o_files)
-
- -- grab the last -B option on the command line, and
- -- set topDir to its value.
-setTopDir :: [String] -> IO [String]
-setTopDir args = do
- let (minusbs, others) = partition (prefixMatch "-B") args
- (case minusbs of
- [] -> writeIORef v_TopDir clibdir
- some -> writeIORef v_TopDir (drop 2 (last some)))
- return others
-
-beginMake :: [String] -> IO ()
-beginMake mods
- = do case mods of
- [] -> throwDyn (UsageError "no input files")
- [mod] -> do state <- cmInit Batch
- cmLoadModule state mod
- return ()
- _ -> throwDyn (UsageError "only one module allowed with --make")
-
-
-beginInteractive :: [String] -> IO ()
-#ifndef GHCI
-beginInteractive = throwDyn (OtherError "not build for interactive use")
-#else
-beginInteractive mods
- = do state <- cmInit Interactive
- let mod = case mods of
- [] -> Nothing
- [mod] -> Just mod
- _ -> throwDyn (UsageError
- "only one module allowed with --interactive")
- interactiveUI state mod
-#endif