Commit e993517a authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add optional 'n' parameter to configure -O flag, ie -O0 -O1 -O2

No change to the defaults.
parent 1957c176
......@@ -48,6 +48,10 @@ module Distribution.Simple.Compiler (
-- * Support for package databases
PackageDB(..),
-- * Support for optimisation levels
OptimisationLevel(..),
flagToOptimisationLevel,
-- * Support for language extensions
Flag,
extensionsToFlags,
......@@ -90,6 +94,30 @@ data PackageDB = GlobalPackageDB
| SpecificPackageDB FilePath
deriving (Show, Read)
-- ------------------------------------------------------------
-- * Optimisation levels
-- ------------------------------------------------------------
-- | Some compilers support optimising. Some have different levels.
-- For compliers that do not the level is just capped to the level
-- they do support.
--
data OptimisationLevel = NoOptimisation
| NormalOptimisation
| MaximumOptimisation
deriving (Show, Read, Enum, Bounded)
flagToOptimisationLevel :: Maybe String -> OptimisationLevel
flagToOptimisationLevel Nothing = NormalOptimisation
flagToOptimisationLevel (Just s) = case reads s of
[(i, "")]
| i >= fromEnum (minBound :: OptimisationLevel)
&& i <= fromEnum (maxBound :: OptimisationLevel)
-> toEnum i
| otherwise -> error $ "Bad optimisation level: " ++ show i
++ ". Valid values are 0..2"
_ -> error $ "Can't parse optimisation level " ++ s
-- ------------------------------------------------------------
-- * Extensions
-- ------------------------------------------------------------
......
......@@ -585,7 +585,10 @@ ghcOptions lbi bi odir
++ (if compilerVersion c >= Version [6,8] []
then ["-stubdir", odir] else [])
++ (concat [ ["-package", showPackageId pkg] | pkg <- packageDeps lbi ])
++ (if withOptimization lbi then ["-O"] else [])
++ (case withOptimization lbi of
NoOptimisation -> []
NormalOptimisation -> ["-O"]
MaximumOptimisation -> ["-O2"])
++ hcOptions GHC bi
++ extensionsToFlags c (extensions bi)
where c = compiler lbi
......@@ -609,7 +612,9 @@ ghcCcOptions lbi bi odir
= ["-I" ++ dir | dir <- includeDirs bi]
++ concat [ ["-package", showPackageId pkg] | pkg <- packageDeps lbi ]
++ ["-optc" ++ opt | opt <- ccOptions bi]
++ (if withOptimization lbi then ["-optc-O2"] else [])
++ (case withOptimization lbi of
NoOptimisation -> []
_ -> ["-optc-O2"])
++ ["-odir", odir]
mkGHCiLibName :: FilePath -- ^file Prefix
......
......@@ -60,7 +60,8 @@ import Distribution.Simple.Setup (CopyDest(..))
import Distribution.Simple.Program (ProgramConfiguration)
import Distribution.PackageDescription (PackageDescription(..))
import Distribution.Package (PackageIdentifier(..), Package(..))
import Distribution.Simple.Compiler (Compiler(..), PackageDB)
import Distribution.Simple.Compiler
( Compiler(..), PackageDB, OptimisationLevel )
import Distribution.Simple.PackageIndex (PackageIndex)
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
......@@ -96,7 +97,7 @@ data LocalBuildInfo = LocalBuildInfo {
withProfLib :: Bool, -- ^Whether to build profiling versions of libs.
withSharedLib :: Bool, -- ^Whether to build shared versions of libs.
withProfExe :: Bool, -- ^Whether to build executables for profiling.
withOptimization :: Bool, -- ^Whether to build with optimization (if available).
withOptimization :: OptimisationLevel, -- ^Whether to build with optimization (if available).
withGHCiLib :: Bool, -- ^Whether to build libs suitable for use with GHCi.
splitObjs :: Bool, -- ^Use -split-objs with GHC, if available
progPrefix :: PathTemplate, -- ^Prefix to be prepended to installed executables
......
......@@ -68,7 +68,8 @@ module Distribution.Simple.Setup (
import Distribution.Simple.Command
import Distribution.Simple.Compiler
( CompilerFlavor(..), defaultCompilerFlavor, PackageDB(..) )
( CompilerFlavor(..), defaultCompilerFlavor, PackageDB(..)
, OptimisationLevel(..), flagToOptimisationLevel )
import Distribution.Simple.Utils (wrapText)
import Distribution.Simple.Program (Program(..), ProgramConfiguration,
knownPrograms)
......@@ -213,7 +214,7 @@ data ConfigFlags = ConfigFlags {
configSharedLib :: Flag Bool, -- ^Build shared library
configProfExe :: Flag Bool, -- ^Enable profiling in the executables.
configConfigureArgs :: [String], -- ^Extra arguments to @configure@
configOptimization :: Flag Bool, -- ^Enable optimization.
configOptimization :: Flag OptimisationLevel, -- ^Enable optimization.
configProgPrefix :: Flag PathTemplate, -- ^Installed executable prefix.
configProgSuffix :: Flag PathTemplate, -- ^Installed executable suffix.
configInstallDirs :: InstallDirs (Flag PathTemplate), -- ^Installation paths
......@@ -236,7 +237,7 @@ defaultConfigFlags progConf = emptyConfigFlags {
configProfLib = Flag False,
configSharedLib = Flag False,
configProfExe = Flag False,
configOptimization = Flag True,
configOptimization = Flag NormalOptimisation,
configProgPrefix = Flag (toPathTemplate ""),
configProgSuffix = Flag (toPathTemplate ""),
configVerbose = Flag normal,
......@@ -394,16 +395,21 @@ configureCommand progConf = makeCommand name shortDesc longDesc defaultFlags opt
,option "O" ("enable-optimization": case showOrParseArgs of
-- Allow British English spelling:
ShowArgs -> []; ParseArgs -> ["enable-optimisation"])
"Build with optimization"
"Build with optimization (n is 0--2, default is 1)"
configOptimization (\v flags -> flags { configOptimization = v })
trueArg
(optArg "n" (Flag . flagToOptimisationLevel)
(\f -> case f of
Flag NoOptimisation -> []
Flag NormalOptimisation -> [Nothing]
Flag MaximumOptimisation -> [Just "2"]
_ -> []))
,option "" ("disable-optimization": case showOrParseArgs of
-- Allow British English spelling:
ShowArgs -> []; ParseArgs -> ["disable-optimisation"])
"Build without optimization"
configOptimization (\v flags -> flags { configOptimization = v })
falseArg
(noArg (Flag NoOptimisation) (\f -> case f of Flag NoOptimisation -> True; _ -> False))
,option "" ["enable-library-for-ghci"]
"compile library for use with GHCi"
......
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