--- old-Y/ghc/compiler/main/GHC.hs 2005-10-24 22:40:44.000000000 +0200
+++ new-Y/ghc/compiler/main/GHC.hs 2005-10-24 20:23:09.000000000 +0200
@@ -346,26 +346,47 @@
-- Flags & settings
-- | Grabs the DynFlags from the Session
getSessionDynFlags :: Session -> IO DynFlags
getSessionDynFlags s = withSession s (return . hsc_dflags)
-- | Updates the DynFlags in a Session
setSessionDynFlags :: Session -> DynFlags -> IO ()
setSessionDynFlags s dflags = modifySession s (\h -> h{ hsc_dflags = dflags })
+-- | Get the name of the top-level module (could be changed by -main-is)
+getMainMod :: DynFlags -> String
+getMainMod dflags = mainModIs dflags `orElse` "Main"
+
-- | Messages during compilation (eg. warnings and progress messages)
-- are reported using this callback. By default, these messages are
-- printed to stderr.
setMsgHandler :: (String -> IO ()) -> IO ()
setMsgHandler = ErrUtils.setMsgHandler
+-- | If there is no -o option, guess the name of target executable
+-- by using top-level source file name as a base.
+guessOutputFile :: Session -> IO ()
+guessOutputFile s = modifySession s $ \env ->
+ let dflags = hsc_dflags env
+ mod_graph = hsc_mod_graph env
+ mainModuleSrcPath, guessedName :: Maybe String
+ mainModuleSrcPath = do
+ let isMain = (== getMainMod dflags) . moduleUserString . ms_mod
+ [ms] <- return (filter isMain mod_graph)
+ ml_hs_file (ms_location ms)
+ guessedName = fmap (fst . splitFilename) mainModuleSrcPath
+ in
+ case outputFile dflags of
+ Just _ -> env
+ Nothing -> env { hsc_dflags = dflags { outputFile = guessedName } }
+
-- -----------------------------------------------------------------------------
-- Targets
-- ToDo: think about relative vs. absolute file paths. And what
-- happens when the current directory changes.
-- | Sets the targets for this session. Each target may be a module name
-- or a filename. The targets correspond to the set of root modules for
-- the program\/library. Unloading the current program is achieved by
-- setting the current set of targets to be empty, followed by load.
@@ -479,20 +500,21 @@
-- Dependency analysis first. Note that this fixes the module graph:
-- even if we don't get a fully successful upsweep, the full module
-- graph is still retained in the Session. We can tell which modules
-- were successfully loaded by inspecting the Session's HPT.
mb_graph <- depanal s [] False
case mb_graph of
Left msgs -> do msg_act msgs; return Failed
Right mod_graph -> loadMsgs2 s how_much msg_act mod_graph
loadMsgs2 s@(Session ref) how_much msg_act mod_graph = do
+ guessOutputFile s
hsc_env <- readIORef ref
let hpt1 = hsc_HPT hsc_env
let dflags = hsc_dflags hsc_env
let ghci_mode = ghcMode dflags -- this never changes
-- The "bad" boot modules are the ones for which we have
-- B.hs-boot in the module graph, but no B.hs
-- The downsweep should have ensured this does not happen
-- (see msDeps)
@@ -608,23 +630,22 @@
cleanTempFilesExcept dflags (ppFilesFromSummaries modsDone)
-- Issue a warning for the confusing case where the user
-- said '-o foo' but we're not going to do any linking.
-- We attempt linking if either (a) one of the modules is
-- called Main, or (b) the user said -no-hs-main, indicating
-- that main() is going to come from somewhere else.
--
let ofile = outputFile dflags
let no_hs_main = dopt Opt_NoHsMain dflags
- let mb_main_mod = mainModIs dflags
let
- main_mod = mb_main_mod `orElse` "Main"
+ main_mod = getMainMod dflags
a_root_is_Main
= any ((==main_mod).moduleUserString.ms_mod)
mod_graph
do_linking = a_root_is_Main || no_hs_main
when (ghci_mode == BatchCompile && isJust ofile && not do_linking) $
debugTraceMsg dflags 1 ("Warning: output was redirected with -o, " ++
"but no output will be generated\n" ++
"because there is no " ++ main_mod ++ " module.")
diff -rN -u10 old-Y/ghc/docs/users_guide/separate_compilation.xml new-Y/ghc/docs/users_guide/separate_compilation.xml
--- old-Y/ghc/docs/users_guide/separate_compilation.xml 2005-10-24 22:40:44.000000000 +0200
+++ new-Y/ghc/docs/users_guide/separate_compilation.xml 2005-10-24 22:37:10.000000000 +0200
@@ -246,20 +246,37 @@
file, the extension ".exe" is added
if the specified filename does not already have an
extension. Thus
ghc -o foo Main.hs
will compile and link the module
Main.hs, and put the resulting
executable in foo.exe (not
foo).
+
+ If you use ghc --make and you don't
+ use the , the name GHC will choose
+ for the executable will be based on the name of the file
+ containing the module Main.
+ Note that with GHC the Main module doesn't
+ have to be put in file Main.hs.
+ Thus both
+
+ ghc --make Prog
+
+ and
+
+ ghc --make Prog.hs
+
+ will produce Prog (or
+ Prog.exe if you are on Windows).dirRedirects object files to directory