Commit 7661c319 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Clean up build rules.

parent 0da69088
......@@ -53,7 +53,7 @@ libraryPackage name stage settings =
)]
commonCcArgs :: Args
commonCcArgs = when Validating $ args "-Werror" "-Wall"
commonCcArgs = when Validating $ arg ["-Werror", "-Wall"]
commonLdArgs :: Args
commonLdArgs = mempty -- TODO: Why empty? Perhaps drop it altogether?
......
{-# LANGUAGE NoImplicitPrelude, ScopedTypeVariables #-}
module Package.Data (buildPackageData) where
import Package.Base
libraryArgs :: [Way] -> Args
libraryArgs ways =
let argEnable x suffix = arg $ (if x then "--enable-" else "--disable-") ++ suffix
in mconcat
[ argEnable False "library-for-ghci" -- TODO: why always disable?
, argEnable (vanilla `elem` ways) "library-vanilla"
, when (ghcWithInterpreter && not DynamicGhcPrograms && vanilla `elem` ways) $
argEnable True "library-for-ghci"
, argEnable (profiling `elem` ways) "library-profiling"
, argEnable (dynamic `elem` ways) "shared"
]
libraryArgs ways =
argEnable False "library-for-ghci" -- TODO: why always disable?
<> argEnable (vanilla `elem` ways) "library-vanilla"
<> when (ghcWithInterpreter && not DynamicGhcPrograms && vanilla `elem` ways) (argEnable True "library-for-ghci")
<> argEnable (profiling `elem` ways) "library-profiling"
<> argEnable (dynamic `elem` ways) "shared"
where
argEnable x suffix = arg $ (if x then "--enable-" else "--disable-") ++ suffix
configureArgs :: Stage -> Settings -> Args
configureArgs stage settings =
let argConf key as = unless (null <$> as) $ joinArgs "--configure-option=" key "=" (as :: Args)
let argConf key as = do
s <- unwords <$> arg as
unless (null s) $ arg $ "--configure-option=" ++ key ++ "=" ++ s
cflags = commonCcArgs `filterOut` "-Werror" <+> ConfCcArgs stage <+> customCcArgs settings <+> commonCcWarninigArgs
ldflags = commonLdArgs <+> ConfGccLinkerArgs stage <+> customLdArgs settings
cppflags = commonCppArgs <+> ConfCppArgs stage <+> customCppArgs settings
cflags = joinArgsSpaced (commonCcArgs `filterOut` ["-Werror"])
(ConfCcArgs stage)
(customCcArgs settings)
(commonCcWarninigArgs)
ldflags = joinArgsSpaced commonLdArgs (ConfGccLinkerArgs stage) (customLdArgs settings)
cppflags = joinArgsSpaced commonCppArgs (ConfCppArgs stage) (customCppArgs settings)
in mconcat
[ argConf "CFLAGS" cflags
, argConf "LDFLAGS" ldflags
, argConf "CPPFLAGS" cppflags
, joinArgs "--gcc-options=" cflags " " ldflags
, argConf "--with-iconv-includes" $ arg IconvIncludeDirs
, argConf "--with-iconv-libraries" $ arg IconvLibDirs
, argConf "--with-gmp-includes" $ arg GmpIncludeDirs
, argConf "--with-gmp-libraries" $ arg GmpLibDirs
, when CrossCompiling $ argConf "--host" $ arg TargetPlatformFull -- TODO: why not host?
, argConf "--with-cc" $ arg Gcc
]
in argConf "CFLAGS" cflags
<> argConf "LDFLAGS" ldflags
<> argConf "CPPFLAGS" cppflags
<> arg (concat <$> "--gcc-options=" <+> cflags <+> " " <+> ldflags)
<> argConf "--with-iconv-includes" IconvIncludeDirs
<> argConf "--with-iconv-libraries" IconvLibDirs
<> argConf "--with-gmp-includes" GmpIncludeDirs
<> argConf "--with-gmp-libraries" GmpLibDirs
<> when CrossCompiling (argConf "--host" TargetPlatformFull) -- TODO: why not host?
<> argConf "--with-cc" Gcc
buildPackageData :: Package -> TodoItem -> Rules ()
buildPackageData pkg @ (Package name path _) (stage, dist, settings) =
......@@ -57,30 +51,28 @@ buildPackageData pkg @ (Package name path _) (stage, dist, settings) =
postProcessPackageData $ path </> dist </> "package-data.mk"
where
cabalArgs, ghcPkgArgs :: Args
cabalArgs = mconcat
[ args "configure" path dist
cabalArgs = arg ["configure", path, dist]
-- this is a positional argument, hence:
-- * if it is empty, we need to emit one empty string argument
-- * if there are many, we must collapse them into one space-separated string
, joinArgsSpaced "" (customDllArgs settings)
, with $ Ghc stage -- TODO: used to be stage01 (using max Stage1 GHC)
, with $ GhcPkg stage
<> arg (unwords <$> customDllArgs settings)
<> with (Ghc stage) -- TODO: used to be stage01 (using max Stage1 GHC)
<> with (GhcPkg stage)
, customConfArgs settings
, libraryArgs =<< ways settings
<> customConfArgs settings
<> (libraryArgs =<< ways settings)
, when hsColourSrcs $ with HsColour
, configureArgs stage settings
<> when hsColourSrcs (with HsColour)
<> configureArgs stage settings
, when (stage == Stage0) $ bootPkgConstraints
, with Gcc
, when (stage /= Stage0) $ with Ld
<> when (stage == Stage0) bootPkgConstraints
<> with Gcc
<> when (stage /= Stage0) (with Ld)
, with Ar
, with Alex
, with Happy
] -- TODO: reorder with's
<> with Ar
<> with Alex
<> with Happy -- TODO: reorder with's
ghcPkgArgs = args "update" "--force"
(when (stage == Stage0) $ arg "--package-db=libraries/bootstrapping.conf")
(path </> dist </> "inplace-pkg-config")
ghcPkgArgs = arg ["update", "--force"]
<> when (stage == Stage0) (arg "--package-db=libraries/bootstrapping.conf")
<> arg (path </> dist </> "inplace-pkg-config")
......@@ -88,14 +88,14 @@ buildPackageDependencies pkg @ (Package name path _) (stage, dist, settings) =
return $ prefix ++ buildDir </> suffix
, map (\d -> "-I" ++ path </> d) <$> filter isRelative <$> arg (IncludeDirs pkgData)
, map (\d -> "-I" ++ d) <$> filter isAbsolute <$> arg (IncludeDirs pkgData)
, args "-optP-include" ("-optP" ++ buildDir </> "build/autogen/cabal_macros.h")
, arg ["-optP-include", "-optP" ++ buildDir </> "build/autogen/cabal_macros.h"]
, if usePackageKey
then map ("-package-key " ++) <$> arg (DepKeys pkgData)
else map ("-package " ++) <$> arg (Deps pkgData)
, arg "-no-user-package-db"
, args "-odir" (buildDir </> "build")
, args "-stubdir" (buildDir </> "build")
, joinArgsSpaced "-dep-makefile" out
, arg ["-odir" , buildDir </> "build"]
, arg ["-stubdir", buildDir </> "build"]
, arg $ "-dep-makefile " ++ out
, concatMap (\w -> ["-dep-suffix", suffix w]) <$> ways settings
, arg "-include-pkg-deps"
, arg $ map normalise srcs
......
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