[--make is now the default (#3515), and -fno-code works with --make (#3783) Simon Marlow **20100427122851 Ignore-this: 33330474fa4703f32bf9997462b4bf3c If the command line contains any Haskell source files, then we behave as if --make had been given. The meaning of the -c flag has changed (back): -c now selects one-shot compilation, but stops before linking. However, to retain backwards compatibility, -c is still allowed with --make, and means the same as --make -no-link. The -no-link flag has been un-deprecated. -fno-code is now allowed with --make (#3783); the fact that it was disabled before was largely accidental, it seems. We also had some regressions in this area: it seems that -fno-code was causing a .hc file to be emitted in certain cases. I've tidied up the code, there was no need for -fno-code to be a "mode" flag, as far as I can tell. -fno-code does not emit interface files, nor does it do recompilation checking, as suggested in #3783. This would make Haddock emit interface files, for example, and I'm fairly sure we don't want to do that. Compiling with -fno-code is pretty quick anyway, perhaps we can get away without recompilation checking. ] { hunk ./compiler/main/DriverPipeline.hs 829 + hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags) hunk ./compiler/main/DriverPipeline.hs 846 - let hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags) hunk ./compiler/main/DynFlags.hs 1066 - , Flag "c" (NoArg (upd $ \d -> d{ ghcLink=NoLink } )) - Supported hunk ./compiler/main/DynFlags.hs 1067 - (Deprecated "Use -c instead") + Supported hunk ./compiler/main/DynFlags.hs 1388 - , Flag "fno-code" (NoArg (setTarget HscNothing)) Supported + , Flag "fno-code" (NoArg (do upd $ \d -> d{ ghcLink=NoLink } + setTarget HscNothing)) + Supported hunk ./compiler/main/HscMain.lhs 438 - , hscBackend = genericHscBackend hscOneShotCompiler + , hscBackend = \ tc_result mod_summary mb_old_hash -> do + hsc_env <- getSession + case hscTarget (hsc_dflags hsc_env) of + HscNothing -> return (HscRecomp False ()) + _otherw -> genericHscBackend hscOneShotCompiler + tc_result mod_summary mb_old_hash hunk ./compiler/main/HscMain.lhs 544 - , hscRecompile = \mod_summary mb_old_hash -> - case ms_hsc_src mod_summary of - ExtCoreFile -> - panic "hscCompileNothing: cannot do external core" - _otherwise -> do - tc_result <- hscFileFrontEnd mod_summary - hscBackend hscNothingCompiler tc_result mod_summary mb_old_hash + , hscRecompile = genericHscRecompile hscNothingCompiler hunk ./docs/users_guide/using.xml 8 + + Getting started: compiling programs + + + In this chapter you'll find a complete reference to the GHC + command-line syntax, including all 400+ flags. It's a large and + complex system, and there are lots of details, so it can be + quite hard to figure out how to get started. With that in mind, + this introductory section provides a quick introduction to the + basic usage of GHC for compiling a Haskell program, before the + following sections dive into the full syntax. + + + + Let's create a Hello World program, and compile and run it. + First, create a file hello.hs containing + the Haskell code: + + + +main = putStrLn "Hello, World!" + + + To compile the program, use GHC like this: + + +$ ghc hello.hs + + (where $ represents the prompt: don't + type it). GHC will compile the source + file hello.hs, producing + an object + file hello.o and + an interface + file hello.hi, and then it + will link the object file to the libraries that come with GHC + to produce an executable called hello on + Unix/Linux/Mac, or hello.exe on + Windows. + + + By default GHC will be very quiet about what it is doing, only + printing error messages. If you want to see in more detail + what's going on behind the scenes, add to + the command line. + + + + Then we can run the program like this: + + + +$ ./hello +Hello World! + + + If your program contains multiple modules, then you only need to + tell GHC the name of the source file containing + the Main module, and GHC will examine + the import declarations to find the other + modules that make up the program and find their source files. + This means that, with the exception of + the Main module, every source file should be + named after the module name that it contains (with dots replaced + by directory separators). For example, the + module Data.Person would be in the + file Data/Person.hs on Unix/Linux/Mac, + or Data\Person.hs on Windows. + + + hunk ./docs/users_guide/using.xml 184 - For example, or . + For example, or . hunk ./docs/users_guide/using.xml 294 - GHC's behaviour is firstly controlled by a mode flag. Only - one of these flags may be given, but it does not necessarily need - to be the first option on the command-line. The available modes - are: + + GHC's behaviour is firstly controlled by a mode flag. Only one + of these flags may be given, but it does not necessarily need to + be the first option on the command-line. + + + + If no mode flag is present, then GHC will enter make mode + () if there are any Haskell source + files given on the command line, or else it will link the + objects named on the command line to produce an executable. + + + The available mode flags are: hunk ./docs/users_guide/using.xml 326 - ghc --make + ghc ––make hunk ./docs/users_guide/using.xml 338 + + + This mode is the default if there are any Haskell + source files mentioned on the command line, and in this case + the option can be omitted. + hunk ./docs/users_guide/using.xml 518 - When given the option, - GHC will build a multi-module Haskell program by following + In this mode, GHC will build a multi-module Haskell program by following hunk ./docs/users_guide/using.xml 529 - The command line may contain any number of source file - names or module names; GHC will figure out all the modules in - the program by following the imports from these initial modules. - It will then attempt to compile each module which is out of - date, and finally, if there is a Main module, - the program will also be linked into an executable. + + In fact, GHC enters make mode automatically if there are any + Haskell source files on the command line and no other mode is + specified, so in this case we could just type + + + +ghc Main.hs + + + Any number of source file names or module names may be + specified; GHC will figure out all the modules in the program by + following the imports from these initial modules. It will then + attempt to compile each module which is out of date, and + finally, if there is a Main module, the + program will also be linked into an executable. hunk ./ghc/Main.hs 432 +isStopLnMode :: Mode -> Bool +isStopLnMode (Right (Right (StopBefore StopLn))) = True +isStopLnMode _ = False + +isDoMakeMode :: Mode -> Bool +isDoMakeMode (Right (Right DoMake)) = True +isDoMakeMode _ = False + hunk ./ghc/Main.hs 473 - hunk ./ghc/Main.hs 485 - Nothing -> stopBeforeMode StopLn + Nothing -> doMakeMode hunk ./ghc/Main.hs 529 + , Flag "c" (PassFlag (\f -> do setMode (stopBeforeMode StopLn) f + addFlag "-no-link" f)) + Supported hunk ./ghc/Main.hs 549 - - -- -fno-code says to stop after Hsc but don't generate any code. - , Flag "fno-code" (PassFlag (\f -> do setMode (stopBeforeMode HCc) f - addFlag "-fno-code" f - addFlag "-fforce-recomp" f)) - Supported hunk ./ghc/Main.hs 559 + -- -c/--make are allowed together, and mean --make -no-link + _ | isStopLnMode oldMode && isDoMakeMode newMode + || isStopLnMode newMode && isDoMakeMode oldMode -> + ((doMakeMode, "--make"), []) + hunk ./ghc/Main.hs 605 -doMake [] = ghcError (UsageError "no input files") hunk ./ghc/Main.hs 614 + + -- if we have no haskell sources from which to do a dependency + -- analysis, then just do one-shot compilation and/or linking. + -- This means that "ghc Foo.o Bar.o -o baz" links the program as + -- we expect. + if (null hs_srcs) + then oneShot hsc_env StopLn srcs >> GHC.printWarnings + else do + }