- -- install signal handlers
- main_thread <- myThreadId
-#ifndef mingw32_TARGET_OS
- let sig_handler = Catch (throwTo main_thread
- (DynException (toDyn Interrupted)))
- installHandler sigQUIT sig_handler Nothing
- installHandler sigINT sig_handler Nothing
-#endif
-
- pgm <- getProgName
- writeIORef v_Prog_name pgm
-
- argv <- getArgs
-
- -- grab any -B options from the command line first
- argv' <- setTopDir argv
- top_dir <- readIORef v_TopDir
-
- let installed s = top_dir ++ '/':s
- inplace s = top_dir ++ '/':cCURRENT_DIR ++ '/':s
-
- installed_pkgconfig = installed ("package.conf")
- inplace_pkgconfig = inplace (cGHC_DRIVER_DIR ++ "/package.conf.inplace")
-
- -- discover whether we're running in a build tree or in an installation,
- -- by looking for the package configuration file.
- am_installed <- doesFileExist installed_pkgconfig
-
- if am_installed
- then writeIORef v_Path_package_config installed_pkgconfig
- else do am_inplace <- doesFileExist inplace_pkgconfig
- if am_inplace
- then writeIORef v_Path_package_config inplace_pkgconfig
- else throwDyn (OtherError "can't find package.conf")
-
- -- set the location of our various files
- if am_installed
- then do writeIORef v_Path_usage (installed "ghc-usage.txt")
- writeIORef v_Pgm_L (installed "unlit")
- writeIORef v_Pgm_m (installed "ghc-asm")
- writeIORef v_Pgm_s (installed "ghc-split")
-
- else do writeIORef v_Path_usage (inplace (cGHC_DRIVER_DIR ++ "/ghc-usage.txt"))
- writeIORef v_Pgm_L (inplace cGHC_UNLIT)
- writeIORef v_Pgm_m (inplace cGHC_MANGLER)
- writeIORef v_Pgm_s (inplace cGHC_SPLIT)
-
- -- read the package configuration
- conf_file <- readIORef v_Path_package_config
- contents <- readFile conf_file
- let pkg_details = read contents -- ToDo: faster
- writeIORef v_Package_details pkg_details
-
- -- find the phase to stop after (i.e. -E, -C, -c, -S flags)
- (flags2, mode, stop_flag) <- getGhcMode argv'
- writeIORef v_GhcMode mode
-
- -- process all the other arguments, and get the source files
- non_static <- processArgs static_flags flags2 []
-
- -- find the build tag, and re-process the build-specific options
- more_opts <- findBuildTag
- way_non_static <- processArgs static_flags more_opts []
-
- -- give the static flags to hsc
+ 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