Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
Move gmp build results to buildRootPath.
Browse files Browse the repository at this point in the history
See #113.
  • Loading branch information
snowleopard committed Jan 10, 2016
1 parent f84ee22 commit a850455
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 170 deletions.
2 changes: 1 addition & 1 deletion shaking-up-ghc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ executable ghc-shake
, Rules.Generators.GhcSplit
, Rules.Generators.GhcVersionH
, Rules.Generators.VersionHs
, Rules.IntegerGmp
, Rules.Gmp
, Rules.Libffi
, Rules.Library
, Rules.Oracles
Expand Down
4 changes: 2 additions & 2 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import qualified Rules
import qualified Rules.Cabal
import qualified Rules.Config
import qualified Rules.Generate
import qualified Rules.IntegerGmp
import qualified Rules.Gmp
import qualified Rules.Libffi
import qualified Rules.Oracles
import qualified Rules.Perl
Expand All @@ -22,7 +22,7 @@ main = shakeArgs options rules
, Rules.Generate.generateRules
, Rules.Perl.perlScriptRules
, Rules.generateTargets
, Rules.IntegerGmp.integerGmpRules
, Rules.Gmp.gmpRules
, Rules.Libffi.libffiRules
, Rules.Oracles.oracleRules
, Rules.packageRules ]
Expand Down
10 changes: 6 additions & 4 deletions src/Rules/Data.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Rules.Data (buildPackageData) where

import qualified System.Directory as IO

import Base
import Expression
import Extra (replace)
Expand All @@ -20,8 +22,9 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
let cabalFile = pkgCabalFile pkg
configure = pkgPath pkg -/- "configure"
dataFile = pkgDataFile stage pkg
oldPath = pkgPath pkg -/- targetDirectory stage pkg -- TODO: remove, #113

dataFile %> \_ -> do
[dataFile, oldPath -/- "package-data.mk"] &%> \_ -> do
-- The first thing we do with any package is make sure all generated
-- dependencies are in place before proceeding.
orderOnly $ generatedDependencies stage pkg
Expand All @@ -37,15 +40,14 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
orderOnly $ map (pkgDataFile stage) depPkgs

-- TODO: get rid of this, see #113
let oldPath = pkgPath pkg -/- targetDirectory stage pkg
inTreeMk = oldPath -/- takeFileName dataFile
let inTreeMk = oldPath -/- takeFileName dataFile

need [cabalFile]
buildWithResources [(resGhcCabal rs, 1)] $
fullTarget target GhcCabal [cabalFile] [inTreeMk]

-- TODO: get rid of this, see #113
copyFile inTreeMk dataFile
liftIO $ IO.copyFile inTreeMk dataFile
autogenFiles <- getDirectoryFiles oldPath ["build/autogen/*"]
createDirectory $ targetPath stage pkg -/- "build/autogen"
forM_ autogenFiles $ \file -> do
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Rules.Generators.GhcVersionH
import Rules.Generators.VersionHs
import Oracles.ModuleFiles
import Rules.Actions
import Rules.IntegerGmp
import Rules.Gmp
import Rules.Libffi
import Rules.Resources (Resources)
import Settings
Expand Down Expand Up @@ -46,7 +46,7 @@ defaultDependencies :: [FilePath]
defaultDependencies = concat
[ includesDependencies
, libffiDependencies
, integerGmpDependencies ]
, gmpDependencies ]

ghcPrimDependencies :: Stage -> [FilePath]
ghcPrimDependencies stage = ((targetPath stage ghcPrim -/- "build") -/-) <$>
Expand Down
134 changes: 134 additions & 0 deletions src/Rules/Gmp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
module Rules.Gmp (
gmpRules, gmpBuildPath, gmpObjects, gmpLibraryH, gmpDependencies
) where

import Base
import Expression
import GHC
import Oracles.Config.Setting
import Rules.Actions
import Settings.Packages.IntegerGmp
import Settings.User

gmpBase :: FilePath
gmpBase = "libraries/integer-gmp/gmp"

gmpTarget :: PartialTarget
gmpTarget = PartialTarget Stage0 integerGmp

gmpObjects :: FilePath
gmpObjects = gmpBuildPath -/- "objs"

gmpLibrary :: FilePath
gmpLibrary = gmpBuildPath -/- "libgmp.a"

gmpLibraryInTreeH :: FilePath
gmpLibraryInTreeH = gmpBuildPath -/- "include/gmp.h"

gmpLibraryH :: FilePath
gmpLibraryH = gmpBuildPath -/- "include/ghc-gmp.h"

gmpLibraryFakeH :: FilePath
gmpLibraryFakeH = gmpBase -/- "ghc-gmp.h"

gmpDependencies :: [FilePath]
gmpDependencies = [gmpLibraryH]

gmpPatches :: [FilePath]
gmpPatches = (gmpBase -/-) <$> ["gmpsrc.patch", "tarball/gmp-5.0.4.patch"]

-- TODO: See Libffi.hs about removing code duplication.
configureEnvironment :: Action [CmdOption]
configureEnvironment = do
sequence [ builderEnv "CC" $ Gcc Stage1
, builderEnv "AR" Ar
, builderEnv "NM" Nm ]
where
builderEnv var builder = do
needBuilder False builder
path <- builderPath builder
return $ AddEnv var path

configureArguments :: Action [String]
configureArguments = do
hostPlatform <- setting HostPlatform
buildPlatform <- setting BuildPlatform
return [ "--enable-shared=no"
, "--host=" ++ hostPlatform
, "--build=" ++ buildPlatform]

-- TODO: we rebuild gmp every time.
gmpRules :: Rules ()
gmpRules = do

-- TODO: split into multiple rules
gmpLibraryH %> \_ -> do
when trackBuildSystem $ need [sourcePath -/- "Rules/Gmp.hs"]

-- Do we need this step?
liftIO $ removeFiles gmpBuildPath ["//*"]

-- Note: We use a tarball like gmp-4.2.4-nodoc.tar.bz2, which is
-- gmp-4.2.4.tar.bz2 repacked without the doc/ directory contents.
-- That's because the doc/ directory contents are under the GFDL,
-- which causes problems for Debian.
tarballs <- getDirectoryFiles "" [gmpBase -/- "tarball/gmp*.tar.bz2"]
when (length tarballs /= 1) $
putError $ "gmpRules: exactly one tarball expected"
++ "(found: " ++ show tarballs ++ ")."

need tarballs

createDirectory gmpBuildPath
build $ fullTarget gmpTarget Tar tarballs [gmpBuildPath]

-- TODO: replace "patch" with PATCH_CMD
forM_ gmpPatches $ \src -> do
let patch = takeFileName src
patchPath = gmpBuildPath -/- patch
copyFile src patchPath
putBuild $ "| Apply " ++ patchPath
unit . quietly $ cmd Shell (EchoStdout False) [Cwd gmpBuildPath] "patch -p0 <" [patch]

-- TODO: What's `chmod +x libraries/integer-gmp/gmp/ln` for?

let filename = dropExtension . dropExtension . takeFileName $ head tarballs
suffix = "-nodoc-patched"
unless (suffix `isSuffixOf` filename) $
putError $ "gmpRules: expected suffix " ++ suffix
++ " (found: " ++ filename ++ ")."
let libName = take (length filename - length suffix) filename
libPath = gmpBuildPath -/- libName

envs <- configureEnvironment
args <- configureArguments
runConfigure libPath envs args

-- TODO: currently we configure integerGmp package twice -- optimise
runConfigure (pkgPath integerGmp) [] []

createDirectory $ takeDirectory gmpLibraryH
-- check whether we need to build in tree gmp
-- this is indicated by line "HaveFrameworkGMP = YES" in `config.mk`
configMk <- liftIO . readFile $ gmpBase -/- "config.mk"
if "HaveFrameworkGMP = YES" `isInfixOf` configMk
then do
putBuild "| GMP framework detected and will be used"
copyFile gmpLibraryFakeH gmpLibraryH
else do
putBuild "| No GMP framework detected; in tree GMP will be built"
runMake libPath ["MAKEFLAGS="]

copyFile (libPath -/- "gmp.h") gmpLibraryInTreeH
copyFile (libPath -/- "gmp.h") gmpLibraryH
-- TODO: why copy library, can we move it instead?
copyFile (libPath -/- ".libs/libgmp.a") gmpLibrary

createDirectory gmpObjects
build $ fullTarget gmpTarget Ar [gmpLibrary] [gmpObjects]

runBuilder Ranlib [gmpLibrary]

putSuccess "| Successfully built custom library 'integer-gmp'"

-- gmpLibraryInTreeH %> \_ -> need [gmpLibraryH]
137 changes: 0 additions & 137 deletions src/Rules/IntegerGmp.hs

This file was deleted.

Loading

0 comments on commit a850455

Please sign in to comment.