+ saveDynFlags
+
+ let
+ {-
+ We split out the object files (.o, .dll) and add them
+ to v_Ld_inputs for use by the linker.
+
+ The following things should be considered compilation manager inputs:
+
+ - haskell source files (strings ending in .hs, .lhs or other
+ haskellish extension),
+
+ - module names (not forgetting hierarchical module names),
+
+ - and finally we consider everything not containing a '.' to be
+ a comp manager input, as shorthand for a .hs or .lhs filename.
+
+ Everything else is considered to be a linker object, and passed
+ straight through to the linker.
+ -}
+ looks_like_an_input m = isSourceFilename m
+ || looksLikeModuleName m
+ || '.' `notElem` m
+
+ -- To simplify the handling of filepaths, we normalise all filepaths right
+ -- away - e.g., for win32 platforms, backslashes are converted
+ -- into forward slashes.
+ normal_fileish_paths = map normalisePath fileish_args
+ (srcs, objs) = partition looks_like_an_input normal_fileish_paths
+
+ -- Note: have v_Ld_inputs maintain the order in which 'objs' occurred on
+ -- the command-line.
+ mapM_ (add v_Ld_inputs) (reverse objs)
+
+ ---------------- Display banners and configuration -----------
+ showBanners mode conf_file static_opts
+
+ ---------------- Final sanity checking -----------
+ checkOptions mode srcs objs
+
+ -- 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.
+ let def_hs_pkgs = [basePackage, haskell98Package]
+
+ ---------------- Do the business -----------
+ case mode of
+ DoMake -> doMake srcs
+
+ DoMkDependHS -> do { beginMkDependHS ;
+ compileFiles mode srcs;
+ endMkDependHS }
+ StopBefore p -> do { compileFiles mode srcs; return () }
+ DoMkDLL -> do { o_files <- compileFiles mode srcs;
+ doMkDLL o_files def_hs_pkgs }
+ DoLink -> do { o_files <- compileFiles mode srcs;
+ omit_linking <- readIORef v_NoLink;
+ when (not omit_linking)
+ (staticLink o_files def_hs_pkgs) }
+
+#ifndef GHCI
+ DoInteractive -> noInteractiveError
+ DoEval _ -> noInteractiveError
+ where
+ noInteractiveError = throwDyn (CmdLineError "not built for interactive use")
+#else
+ DoInteractive -> interactiveUI srcs Nothing
+ DoEval expr -> interactiveUI srcs (Just expr)
+#endif
+
+-- -----------------------------------------------------------------------------
+-- Option sanity checks
+
+checkOptions :: GhcMode -> [String] -> [String] -> IO ()
+ -- Final sanity checking before kicking off a compilation (pipeline).
+checkOptions mode srcs objs = do
+ -- Complain about any unknown flags
+ let unknown_opts = [ f | f@('-':_) <- srcs ]
+ when (notNull unknown_opts) (unknownFlagsErr unknown_opts)
+
+ -- -ohi sanity check
+ ohi <- readIORef v_Output_hi
+ if (isJust ohi &&
+ (mode == DoMake || isInteractive mode || srcs `lengthExceeds` 1))
+ then throwDyn (UsageError "-ohi can only be used when compiling a single source file")
+ else do
+
+ -- -o sanity checking
+ o_file <- readIORef v_Output_file
+ if (srcs `lengthExceeds` 1 && isJust o_file && mode /= DoLink && mode /= DoMkDLL)
+ then throwDyn (UsageError "can't apply -o to multiple source files")
+ else do