buildExe :: Verbosity -> PackageDescription -> LocalBuildInfo
                      -> Executable         -> ComponentLocalBuildInfo -> IO ()
buildExe verbosity pkg_descr lbi
  exe@Executable {modulePath=mainPath, buildInfo=bi} _clbi = do
    let pref = scratchDir lbi
    createDirectoryIfMissingVerbose verbosity True pref
    
    let destDir = pref </> "programs"
    let exeMods = otherModules bi
    srcMainFile <- findFile (hsSourceDirs bi) mainPath
    let exeDir = destDir </> exeName exe
    let destMainFile = exeDir </> hugsMainFilename exe
    copyModule verbosity (EnableExtension CPP `elem` allExtensions bi) bi lbi srcMainFile destMainFile
    let destPathsFile = exeDir </> paths_modulename
    copyFileVerbose verbosity (autogenModulesDir lbi </> paths_modulename)
                              destPathsFile
    compileBuildInfo verbosity exeDir 
      (maybe [] (hsSourceDirs . libBuildInfo) (library pkg_descr)) exeMods bi lbi
    compileFiles verbosity bi lbi exeDir [destMainFile, destPathsFile]

  where
    paths_modulename = ModuleName.toFilePath (autogenModuleName pkg_descr)
                         <.> ".hs"
buildExe :: Verbosity -> PackageDescription -> LocalBuildInfo
                      -> Executable         -> ComponentLocalBuildInfo -> IO ()
buildExe verbosity pkg_descr lbi
  exe@Executable {modulePath=mainPath, buildInfo=bi} _clbi = do
    let pref = scratchDir lbi
    createDirectoryIfMissingVerbose verbosity True pref
    
    let destDir = pref </> "programs"
    let exeMods = otherModules bi
    srcMainFile <- findFile (hsSourceDirs bi) mainPath
    let exeDir = destDir </> exeName exe
    let destMainFile = exeDir </> hugsMainFilename exe
    copyModule verbosity (EnableExtension CPP `elem` allExtensions bi) bi lbi srcMainFile destMainFile
    let destPathsFile = exeDir </> paths_modulename
    copyFileVerbose verbosity (autogenModulesDir lbi </> paths_modulename)
                              destPathsFile
    compileBuildInfo verbosity exeDir 
      (maybe [] (hsSourceDirs . libBuildInfo) (library pkg_descr)) exeMods bi lbi
    compileFiles verbosity bi lbi exeDir [destMainFile, destPathsFile]

  where
    paths_modulename = ModuleName.toFilePath (autogenModuleName pkg_descr)
                         <.> ".hs"
buildExe verbosity pkg_descr lbi
  exe@Executable {modulePath=mainPath, buildInfo=bi} _clbi = do
    let pref = scratchDir lbi
    createDirectoryIfMissingVerbose verbosity True pref
    
    let destDir = pref </> "programs"
    let exeMods = otherModules bi
    srcMainFile <- findFile (hsSourceDirs bi) mainPath
    let exeDir = destDir </> exeName exe
    let destMainFile = exeDir </> hugsMainFilename exe
    copyModule verbosity (EnableExtension CPP `elem` allExtensions bi) bi lbi srcMainFile destMainFile
    let destPathsFile = exeDir </> paths_modulename
    copyFileVerbose verbosity (autogenModulesDir lbi </> paths_modulename)
                              destPathsFile
    compileBuildInfo verbosity exeDir 
      (maybe [] (hsSourceDirs . libBuildInfo) (library pkg_descr)) exeMods bi lbi
    compileFiles verbosity bi lbi exeDir [destMainFile, destPathsFile]

  where
    paths_modulename = ModuleName.toFilePath (autogenModuleName pkg_descr)
                         <.> ".hs"