module Distribution.Simple.Install (
install,
) where
import Distribution.PackageDescription
import Distribution.Package (Package(..))
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.BuildPaths (haddockName, haddockPref)
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose
, installDirectoryContents, installOrdinaryFile, isInSearchPath
, die, info, notice, warn, matchDirFileGlob )
import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor )
import Distribution.Simple.Setup (CopyFlags(..), fromFlag)
import qualified Distribution.Simple.GHC as GHC
import qualified Distribution.Simple.GHCJS as GHCJS
import qualified Distribution.Simple.JHC as JHC
import qualified Distribution.Simple.LHC as LHC
import qualified Distribution.Simple.UHC as UHC
import qualified Distribution.Simple.HaskellSuite as HaskellSuite
import Control.Monad (when, unless)
import System.Directory
( doesDirectoryExist, doesFileExist )
import System.FilePath
( takeFileName, takeDirectory, (</>), isAbsolute )
import Distribution.Verbosity
import Distribution.Text
( display )
install :: PackageDescription
-> LocalBuildInfo
-> CopyFlags
-> IO ()
install pkg_descr lbi flags = do
let distPref = fromFlag (copyDistPref flags)
verbosity = fromFlag (copyVerbosity flags)
copydest = fromFlag (copyDest flags)
installDirs@(InstallDirs {
bindir = binPref,
libdir = libPref,
datadir = dataPref,
docdir = docPref,
htmldir = htmlPref,
haddockdir = interfacePref,
includedir = incPref})
= absoluteInstallDirs pkg_descr lbi copydest
dynlibPref = libPref
progPrefixPref = substPathTemplate (packageId pkg_descr) lbi (progPrefix lbi)
progSuffixPref = substPathTemplate (packageId pkg_descr) lbi (progSuffix lbi)
unless (hasLibs pkg_descr || hasExes pkg_descr) $
die "No executables and no library found. Nothing to do."
docExists <- doesDirectoryExist $ haddockPref distPref pkg_descr
info verbosity ("directory " ++ haddockPref distPref pkg_descr ++
" does exist: " ++ show docExists)
installDataFiles verbosity pkg_descr dataPref
when docExists $ do
createDirectoryIfMissingVerbose verbosity True htmlPref
installDirectoryContents verbosity
(haddockPref distPref pkg_descr) htmlPref
let haddockInterfaceFileSrc = haddockPref distPref pkg_descr
</> haddockName pkg_descr
haddockInterfaceFileDest = interfacePref </> haddockName pkg_descr
exists <- doesFileExist haddockInterfaceFileSrc
when exists $ do
createDirectoryIfMissingVerbose verbosity True interfacePref
installOrdinaryFile verbosity haddockInterfaceFileSrc
haddockInterfaceFileDest
let lfiles = licenseFiles pkg_descr
unless (null lfiles) $ do
createDirectoryIfMissingVerbose verbosity True docPref
sequence_
[ installOrdinaryFile verbosity lfile (docPref </> takeFileName lfile)
| lfile <- lfiles ]
let buildPref = buildDir lbi
when (hasLibs pkg_descr) $
notice verbosity ("Installing library in " ++ libPref)
when (hasExes pkg_descr) $ do
notice verbosity ("Installing executable(s) in " ++ binPref)
inPath <- isInSearchPath binPref
when (not inPath) $
warn verbosity ("The directory " ++ binPref
++ " is not in the system search path.")
when (hasLibs pkg_descr) $ installIncludeFiles verbosity pkg_descr incPref
withLibLBI pkg_descr lbi $
case compilerFlavor (compiler lbi) of
GHC -> GHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr
GHCJS -> GHCJS.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr
LHC -> LHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr
JHC -> JHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr
UHC -> UHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr
HaskellSuite _ -> HaskellSuite.installLib
verbosity lbi libPref dynlibPref buildPref pkg_descr
_ -> \_ _ -> die $ "installing with "
++ display (compilerFlavor (compiler lbi))
++ " is not implemented"
withExe pkg_descr $
case compilerFlavor (compiler lbi) of
GHC -> GHC.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr
GHCJS -> GHCJS.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr
LHC -> LHC.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr
JHC -> JHC.installExe verbosity binPref buildPref (progPrefixPref, progSuffixPref) pkg_descr
UHC -> \_ -> return ()
HaskellSuite {} -> \_ -> return ()
_ -> \_ -> die $ "installing with "
++ display (compilerFlavor (compiler lbi))
++ " is not implemented"
installDataFiles :: Verbosity -> PackageDescription -> FilePath -> IO ()
installDataFiles verbosity pkg_descr destDataDir =
flip mapM_ (dataFiles pkg_descr) $ \ file -> do
let srcDataDir = dataDir pkg_descr
files <- matchDirFileGlob srcDataDir file
let dir = takeDirectory file
createDirectoryIfMissingVerbose verbosity True (destDataDir </> dir)
sequence_ [ installOrdinaryFile verbosity (srcDataDir </> file')
(destDataDir </> file')
| file' <- files ]
installIncludeFiles :: Verbosity -> PackageDescription -> FilePath -> IO ()
installIncludeFiles verbosity
PackageDescription { library = Just lib } destIncludeDir = do
incs <- mapM (findInc relincdirs) (installIncludes lbi)
sequence_
[ do createDirectoryIfMissingVerbose verbosity True destDir
installOrdinaryFile verbosity srcFile destFile
| (relFile, srcFile) <- incs
, let destFile = destIncludeDir </> relFile
destDir = takeDirectory destFile ]
where
relincdirs = "." : filter (not.isAbsolute) (includeDirs lbi)
lbi = libBuildInfo lib
findInc [] file = die ("can't find include file " ++ file)
findInc (dir:dirs) file = do
let path = dir </> file
exists <- doesFileExist path
if exists then return (file, path) else findInc dirs file
installIncludeFiles _ _ _ = die "installIncludeFiles: Can't happen?"