- -- perform some checks of the options set / report unknowns.
- checkOptions srcs
-
- verb <- dynFlag verbosity
-
- -- Show the GHCi banner
-# ifdef GHCI
- when (mode == DoInteractive && 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 >= 2)
- (hPutStrLn stderr ("Using package config file: " ++ conf_file))
-
- pkg_details <- getPackageConfigMap
- showPackages pkg_details
-
- when (verb >= 3)
- (hPutStrLn stderr ("Hsc static flags: " ++ unwords static_opts))
-
- -- 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