- -- 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
- 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)
- pp <- if not (haskellish_src_file src) || mode == StopBefore Hsc
- 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
-
- o_files <- mapM compileFile srcs
-
- when (mode == DoMkDependHS) endMkDependHS
- when (mode == DoLink) (doLink o_files)
- when (mode == DoMkDLL) (doMkDLL o_files)
-
-
-
-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
- (_, ok, _) <- cmLoadModule state mods
- when (not ok) (exitWith (ExitFailure 1))
- return ()
-
-
-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
- interactiveUI state mods libs
-#endif