Commit 176bfd4d authored by Zhen Zhang's avatar Zhen Zhang Committed by Andrey Mokhov

Add DESTDIR to command line arguments (#397)

parent c413722e
...@@ -111,7 +111,7 @@ To build a GHC source distribution tarball, run Hadrian with the `sdist-ghc` tar ...@@ -111,7 +111,7 @@ To build a GHC source distribution tarball, run Hadrian with the `sdist-ghc` tar
To build and install GHC artifacts, run the `install` target. To build and install GHC artifacts, run the `install` target.
By default, the artifacts will be installed to `<prefix>` on your system. For example, By default, the artifacts will be installed to `<prefix>` on your system. For example,
`ghc` will be installed to `/usr/local/bin`. By modifying `defaultDestDir` in `UserSettings.hs`, `ghc` will be installed to `/usr/local/bin`. By setting flag `--install-destdir=[DESTDIR]`,
you can install things to non-system path `DESTDIR/<prefix>` instead. you can install things to non-system path `DESTDIR/<prefix>` instead.
#### Testing #### Testing
......
module CommandLine ( module CommandLine (
optDescrs, cmdLineArgsMap, cmdBuildHaddock, cmdFlavour, cmdIntegerSimple, optDescrs, cmdLineArgsMap, cmdBuildHaddock, cmdFlavour, cmdIntegerSimple,
cmdProgressColour, cmdProgressInfo, cmdSkipConfigure, cmdSplitObjects cmdProgressColour, cmdProgressInfo, cmdSkipConfigure, cmdSplitObjects,
cmdInstallDestDir
) where ) where
import Data.Either import Data.Either
...@@ -14,6 +15,7 @@ import System.Environment ...@@ -14,6 +15,7 @@ import System.Environment
-- | All arguments that can be passed to Hadrian via the command line. -- | All arguments that can be passed to Hadrian via the command line.
data CommandLineArgs = CommandLineArgs data CommandLineArgs = CommandLineArgs
{ buildHaddock :: Bool { buildHaddock :: Bool
, installDestDir :: Maybe String
, flavour :: Maybe String , flavour :: Maybe String
, integerSimple :: Bool , integerSimple :: Bool
, progressColour :: UseColour , progressColour :: UseColour
...@@ -27,6 +29,7 @@ defaultCommandLineArgs :: CommandLineArgs ...@@ -27,6 +29,7 @@ defaultCommandLineArgs :: CommandLineArgs
defaultCommandLineArgs = CommandLineArgs defaultCommandLineArgs = CommandLineArgs
{ buildHaddock = False { buildHaddock = False
, flavour = Nothing , flavour = Nothing
, installDestDir = Nothing
, integerSimple = False , integerSimple = False
, progressColour = Auto , progressColour = Auto
, progressInfo = Normal , progressInfo = Normal
...@@ -39,6 +42,9 @@ readBuildHaddock = Right $ \flags -> flags { buildHaddock = True } ...@@ -39,6 +42,9 @@ readBuildHaddock = Right $ \flags -> flags { buildHaddock = True }
readFlavour :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs) readFlavour :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
readFlavour ms = Right $ \flags -> flags { flavour = lower <$> ms } readFlavour ms = Right $ \flags -> flags { flavour = lower <$> ms }
readInstallDestDir :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
readInstallDestDir ms = Right $ \flags -> flags { installDestDir = ms }
readIntegerSimple :: Either String (CommandLineArgs -> CommandLineArgs) readIntegerSimple :: Either String (CommandLineArgs -> CommandLineArgs)
readIntegerSimple = Right $ \flags -> flags { integerSimple = True } readIntegerSimple = Right $ \flags -> flags { integerSimple = True }
...@@ -80,6 +86,8 @@ optDescrs = ...@@ -80,6 +86,8 @@ optDescrs =
"Build flavour (Default, Devel1, Devel2, Perf, Prof, Quick or Quickest)." "Build flavour (Default, Devel1, Devel2, Perf, Prof, Quick or Quickest)."
, Option [] ["haddock"] (NoArg readBuildHaddock) , Option [] ["haddock"] (NoArg readBuildHaddock)
"Generate Haddock documentation." "Generate Haddock documentation."
, Option [] ["install-destdir"] (OptArg readInstallDestDir "DESTDIR")
"Installation destination directory."
, Option [] ["integer-simple"] (NoArg readIntegerSimple) , Option [] ["integer-simple"] (NoArg readIntegerSimple)
"Build GHC with integer-simple library." "Build GHC with integer-simple library."
, Option [] ["progress-colour"] (OptArg readProgressColour "MODE") , Option [] ["progress-colour"] (OptArg readProgressColour "MODE")
...@@ -107,6 +115,9 @@ cmdLineArgs = userSetting defaultCommandLineArgs ...@@ -107,6 +115,9 @@ cmdLineArgs = userSetting defaultCommandLineArgs
cmdBuildHaddock :: Action Bool cmdBuildHaddock :: Action Bool
cmdBuildHaddock = buildHaddock <$> cmdLineArgs cmdBuildHaddock = buildHaddock <$> cmdLineArgs
cmdInstallDestDir :: Action (Maybe String)
cmdInstallDestDir = installDestDir <$> cmdLineArgs
cmdFlavour :: Action (Maybe String) cmdFlavour :: Action (Maybe String)
cmdFlavour = flavour <$> cmdLineArgs cmdFlavour = flavour <$> cmdLineArgs
......
...@@ -60,6 +60,7 @@ getLibExecDir = (-/- "bin") <$> installGhcLibDir ...@@ -60,6 +60,7 @@ getLibExecDir = (-/- "bin") <$> installGhcLibDir
installLibExecScripts :: Action () installLibExecScripts :: Action ()
installLibExecScripts = do installLibExecScripts = do
libExecDir <- getLibExecDir libExecDir <- getLibExecDir
destDir <- getDestDir
installDirectory (destDir ++ libExecDir) installDirectory (destDir ++ libExecDir)
forM_ libExecScripts $ \script -> do forM_ libExecScripts $ \script -> do
installScript script (destDir ++ libExecDir) installScript script (destDir ++ libExecDir)
...@@ -72,6 +73,7 @@ installLibExecScripts = do ...@@ -72,6 +73,7 @@ installLibExecScripts = do
installLibExecs :: Action () installLibExecs :: Action ()
installLibExecs = do installLibExecs = do
libExecDir <- getLibExecDir libExecDir <- getLibExecDir
destDir <- getDestDir
installDirectory (destDir ++ libExecDir) installDirectory (destDir ++ libExecDir)
forM_ installBinPkgs $ \pkg -> do forM_ installBinPkgs $ \pkg -> do
withLatestBuildStage pkg $ \stage -> do withLatestBuildStage pkg $ \stage -> do
...@@ -88,6 +90,7 @@ installBins :: Action () ...@@ -88,6 +90,7 @@ installBins :: Action ()
installBins = do installBins = do
binDir <- setting InstallBinDir binDir <- setting InstallBinDir
libDir <- installGhcLibDir libDir <- installGhcLibDir
destDir <- getDestDir
installDirectory (destDir ++ binDir) installDirectory (destDir ++ binDir)
win <- windowsHost win <- windowsHost
when win $ when win $
...@@ -153,6 +156,7 @@ installPackages = do ...@@ -153,6 +156,7 @@ installPackages = do
ghcLibDir <- installGhcLibDir ghcLibDir <- installGhcLibDir
binDir <- setting InstallBinDir binDir <- setting InstallBinDir
destDir <- getDestDir
-- Install package.conf -- Install package.conf
let installedPackageConf = destDir ++ ghcLibDir -/- "package.conf.d" let installedPackageConf = destDir ++ ghcLibDir -/- "package.conf.d"
...@@ -271,6 +275,7 @@ installPackages = do ...@@ -271,6 +275,7 @@ installPackages = do
installCommonLibs :: Action () installCommonLibs :: Action ()
installCommonLibs = do installCommonLibs = do
ghcLibDir <- installGhcLibDir ghcLibDir <- installGhcLibDir
destDir <- getDestDir
installLibsTo inplaceLibCopyTargets (destDir ++ ghcLibDir) installLibsTo inplaceLibCopyTargets (destDir ++ ghcLibDir)
-- ref: ghc.mk -- ref: ghc.mk
...@@ -296,6 +301,7 @@ includeHSubdirs = [".", "rts", "rts/prof", "rts/storage", "stg"] ...@@ -296,6 +301,7 @@ includeHSubdirs = [".", "rts", "rts/prof", "rts/storage", "stg"]
installIncludes :: Action () installIncludes :: Action ()
installIncludes = do installIncludes = do
ghclibDir <- installGhcLibDir ghclibDir <- installGhcLibDir
destDir <- getDestDir
let ghcheaderDir = ghclibDir -/- "include" let ghcheaderDir = ghclibDir -/- "include"
installDirectory (destDir ++ ghcheaderDir) installDirectory (destDir ++ ghcheaderDir)
forM_ includeHSubdirs $ \dir -> do forM_ includeHSubdirs $ \dir -> do
......
...@@ -2,7 +2,7 @@ module Settings ( ...@@ -2,7 +2,7 @@ module Settings (
getArgs, getPackages, getLibraryWays, getRtsWays, flavour, knownPackages, getArgs, getPackages, getLibraryWays, getRtsWays, flavour, knownPackages,
findKnownPackage, getPkgData, getPkgDataList, isLibrary, stagePackages, findKnownPackage, getPkgData, getPkgDataList, isLibrary, stagePackages,
builderPath, getBuilderPath, isSpecified, latestBuildStage, programPath, builderPath, getBuilderPath, isSpecified, latestBuildStage, programPath,
programContext, integerLibraryName, destDir, stage1Only, buildDll0 programContext, integerLibraryName, getDestDir, stage1Only, buildDll0
) where ) where
import Context import Context
...@@ -103,7 +103,6 @@ programPath context@Context {..} = do ...@@ -103,7 +103,6 @@ programPath context@Context {..} = do
stage1Only :: Bool stage1Only :: Bool
stage1Only = defaultStage1Only stage1Only = defaultStage1Only
-- TODO: Set this from command line
-- | Install's DESTDIR setting. -- | Install's DESTDIR setting.
destDir :: FilePath getDestDir :: Action FilePath
destDir = defaultDestDir getDestDir = fromMaybe "" <$> cmdInstallDestDir
...@@ -62,6 +62,7 @@ rtsPackageArgs = package rts ? do ...@@ -62,6 +62,7 @@ rtsPackageArgs = package rts ? do
ffiIncludeDir <- getSetting FfiIncludeDir ffiIncludeDir <- getSetting FfiIncludeDir
ffiLibraryDir <- getSetting FfiLibDir ffiLibraryDir <- getSetting FfiLibDir
ghclibDir <- expr installGhcLibDir ghclibDir <- expr installGhcLibDir
destDir <- expr getDestDir
let cArgs = let cArgs =
[ arg "-Irts" [ arg "-Irts"
, arg $ "-I" ++ path , arg $ "-I" ++ path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment