-
- -- mkdependHS is special
- when (mode == DoMkDependHS) beginMkDependHS
-
- -- -ohi sanity checking
- 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
-
- -- 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
- let real_srcs = filter isSourceFile srcs -- filters out .a and .o that might appear
- o_file <- readIORef v_Output_file
- if (real_srcs `lengthExceeds` 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)
- 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
-
- o_files <- mapM compileFile srcs
-
- when (mode == DoMkDependHS) endMkDependHS
-
- omit_linking <- readIORef v_NoLink
- when (mode == DoLink && not omit_linking)
- (staticLink o_files [basePackage, haskell98Package])
- -- we always link in the base package in one-shot linking.
- -- any other packages required must be given using -package
- -- options on the command-line.
-
- when (mode == DoMkDLL) (doMkDLL o_files)
-
-
-
-beginMake :: [String] -> IO ()
-beginMake fileish_args = do
- -- anything that doesn't look like a Haskell source filename or
- -- a module name is passed straight through to the linker
- let (inputs, objects) = partition looks_like_an_input fileish_args
- mapM_ (add v_Ld_inputs) objects
-
- case inputs of
- [] -> throwDyn (UsageError "no input files")
- _ -> do dflags <- getDynFlags
- state <- cmInit Batch
- graph <- cmDepAnal state dflags inputs
- (_, ok_flag, _) <- cmLoadModules state dflags graph
- when (failed ok_flag) (exitWith (ExitFailure 1))
- return ()
- where
- looks_like_an_input m = haskellish_src_file m || '.' `notElem` m
-
-
-beginInteractive :: [String] -> IO ()
-#ifndef GHCI
-beginInteractive = throwDyn (CmdLineError "not built for interactive use")
-#else
-beginInteractive fileish_args
- = do state <- cmInit Interactive
-
- let (objs, mods) = partition objish_file fileish_args
-
- interactiveUI state mods objs
-#endif
-
-checkOptions :: [String] -> IO ()
-checkOptions srcs = 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
- -- and anything else that it might be worth checking for
- -- before kicking of a compilation (pipeline).
-