-- -----------------------------------------------------------------------------
-- Building

-- |Building a package for Hugs.
buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo
                      -> Library            -> ComponentLocalBuildInfo -> IO ()
buildLib verbosity pkg_descr lbi lib _clbi = do
    let pref = scratchDir lbi
    createDirectoryIfMissingVerbose verbosity True pref
    copyFileVerbose verbosity (autogenModulesDir lbi </> paths_modulename)
                              (pref </> paths_modulename)
    compileBuildInfo verbosity pref [] (libModules lib) (libBuildInfo lib) lbi
  where
    paths_modulename = ModuleName.toFilePath (autogenModuleName pkg_descr)
                         <.> ".hs"
    --TODO: switch to using autogenModulesDir as a search dir, rather than
    --      always copying the file over.

-- |Building an executable for Hugs.
buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo
                      -> Library            -> ComponentLocalBuildInfo -> IO ()
buildLib verbosity pkg_descr lbi lib _clbi = do
    let pref = scratchDir lbi
    createDirectoryIfMissingVerbose verbosity True pref
    copyFileVerbose verbosity (autogenModulesDir lbi </> paths_modulename)
                              (pref </> paths_modulename)
    compileBuildInfo verbosity pref [] (libModules lib) (libBuildInfo lib) lbi
  where
    paths_modulename = ModuleName.toFilePath (autogenModuleName pkg_descr)
                         <.> ".hs"
    --TODO: switch to using autogenModulesDir as a search dir, rather than
    --      always copying the file over.

-- |Building an executable for Hugs.
buildLib verbosity pkg_descr lbi lib _clbi = do
    let pref = scratchDir lbi
    createDirectoryIfMissingVerbose verbosity True pref
    copyFileVerbose verbosity (autogenModulesDir lbi </> paths_modulename)
                              (pref </> paths_modulename)
    compileBuildInfo verbosity pref [] (libModules lib) (libBuildInfo lib) lbi
  where
    paths_modulename = ModuleName.toFilePath (autogenModuleName pkg_descr)
                         <.> ".hs"
    --TODO: switch to using autogenModulesDir as a search dir, rather than
    --      always copying the file over.

-- |Building an executable for Hugs.