-
- -- initialise the finder
- pkg_avails <- getPackageInfo
- initFinder pkg_avails
-
- -- mkdependHS is special
- when (mode == DoMkDependHS) beginMkDependHS
-
- -- -ohi sanity checking
- ohi <- readIORef v_Output_hi
- if (isJust ohi &&
- (mode == DoMake || mode == DoInteractive || length srcs > 1))
- then throwDyn (UsageError "-ohi can only be used when compiling a single source file")
- else do
-
- -- make/interactive require invoking the compilation manager
- if (mode == DoMake) then beginMake srcs else do
- if (mode == DoInteractive) then beginInteractive srcs else do
-
- -- -o sanity checking
- o_file <- readIORef v_Output_file
- if (length srcs > 1 && isJust o_file && mode /= DoLink && mode /= DoMkDLL)
- then throwDyn (UsageError "can't apply -o to multiple source files")
- else do
-
- if null srcs then throwDyn (UsageError "no input files") else do
-
- let compileFile src = do
- writeIORef v_DynFlags init_dyn_flags
-
- 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
- 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 || mode==DoMkDLL) True{-use -o flag-}
- basename suffix
- return r
-
- o_files <- mapM compileFile srcs
-
- when (mode == DoMkDependHS) endMkDependHS
- when (mode == DoLink) (doLink o_files)
- when (mode == DoMkDLL) (doMkDLL 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
- [] -> throwDyn (InstallationError ("missing -B<dir> option"))
- some -> writeIORef v_TopDir (drop 2 (last some)))
- return others
-
-beginMake :: [String] -> IO ()
-beginMake fileish_args
- = do let (objs, mods) = partition objish_file fileish_args
- mapM (add v_Ld_inputs) objs
-
- 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 (CmdLineError "not built for interactive use")
-#else
-beginInteractive fileish_args
- = do minus_ls <- readIORef v_Cmdline_libraries
-
- let (objs, mods) = partition objish_file fileish_args
- libs = map Left objs ++ map Right minus_ls
-
- state <- cmInit Interactive
- case mods of
- [] -> interactiveUI state Nothing libs
- [mod] -> interactiveUI state (Just mod) libs
- _ -> throwDyn (UsageError
- "only one module allowed with --interactive")
-#endif