+ installSignalHandlers
+
+ argv <- getArgs
+ let (minusB_args, argv') = partition (prefixMatch "-B") argv
+ top_dir <- initSysTools minusB_args
+
+ -- Read the package configuration
+ conf_file <- getPackageConfigPath
+ readPackageConf conf_file
+
+ -- Process all the other arguments, and get the source files
+ non_static <- processArgs static_flags argv' []
+ mode <- readIORef v_GhcMode
+
+ -- -O and --interactive are not a good combination
+ -- ditto with any kind of way selection
+ orig_opt_level <- readIORef v_OptLevel
+ when (orig_opt_level > 0 && mode == DoInteractive) $
+ do putStr "warning: -O conflicts with --interactive; -O turned off.\n"
+ writeIORef v_OptLevel 0
+ orig_ways <- readIORef v_Ways
+ when (notNull orig_ways && mode == DoInteractive) $
+ do throwDyn (UsageError
+ "--interactive can't be used with -prof, -ticky, -unreg or -smp.")
+
+ -- Find the build tag, and re-process the build-specific options.
+ -- Also add in flags for unregisterised compilation, if
+ -- GhcUnregisterised=YES.
+ way_opts <- findBuildTag
+ let unreg_opts | cGhcUnregisterised == "YES" = unregFlags
+ | otherwise = []
+ pkg_extra_opts <- getPackageExtraGhcOpts
+ extra_non_static <- processArgs static_flags
+ (unreg_opts ++ way_opts ++ pkg_extra_opts) []
+
+ -- Give the static flags to hsc
+ static_opts <- buildStaticHscOpts
+ writeIORef v_Static_hsc_opts static_opts
+
+ -- build the default DynFlags (these may be adjusted on a per
+ -- module basis by OPTIONS pragmas and settings in the interpreter).
+
+ core_todo <- buildCoreToDo
+ stg_todo <- buildStgToDo
+
+ -- set the "global" HscLang. The HscLang can be further adjusted on a module
+ -- by module basis, using only the -fvia-C and -fasm flags. If the global
+ -- HscLang is not HscC or HscAsm, -fvia-C and -fasm have no effect.
+ dyn_flags <- getDynFlags
+ build_tag <- readIORef v_Build_tag
+ let lang = case mode of
+ DoInteractive -> HscInterpreted
+ _other | build_tag /= "" -> HscC
+ | otherwise -> hscLang dyn_flags
+ -- for ways other that the normal way, we must
+ -- compile via C.
+
+ setDynFlags (dyn_flags{ coreToDo = core_todo,
+ stgToDo = stg_todo,
+ hscLang = lang,
+ -- leave out hscOutName for now
+ hscOutName = panic "Main.main:hscOutName not set",
+ verbosity = 1
+ })
+
+ -- The rest of the arguments are "dynamic"
+ -- Leftover ones are presumably files
+ fileish_args <- processArgs dynamic_flags (extra_non_static ++ non_static) []
+
+ -- save the "initial DynFlags" away
+ 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 = isSourceFile 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
+
+ mapM_ (add v_Ld_inputs) 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 -> throwDyn (CmdLineError "not built for interactive use")
+#else
+ DoInteractive -> interactiveUI srcs