Created
February 19, 2013 07:58
-
-
Save the-real-blackh/4983885 to your computer and use it in GitHub Desktop.
Add --host-os and --host-arch command-line options and "ios" os
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Cabal/Distribution/Simple/Bench.hs b/Cabal/Distribution/Simple/Bench.hs | |
index f34c888..4f1d30f 100644 | |
--- a/Cabal/Distribution/Simple/Bench.hs | |
+++ b/Cabal/Distribution/Simple/Bench.hs | |
@@ -54,7 +54,8 @@ import Distribution.Simple.InstallDirs | |
, substPathTemplate , toPathTemplate, PathTemplate ) | |
import qualified Distribution.Simple.LocalBuildInfo as LBI | |
( LocalBuildInfo(..) ) | |
-import Distribution.Simple.Setup ( BenchmarkFlags(..), fromFlag ) | |
+import Distribution.Simple.Setup | |
+ ( BenchmarkFlags(..), fromFlag, configHostPlatform ) | |
import Distribution.Simple.UserHooks ( Args ) | |
import Distribution.Simple.Utils ( die, notice, rawSystemExitCode ) | |
import Distribution.Text | |
@@ -152,5 +153,6 @@ benchOption pkg_descr lbi bm template = | |
fromPathTemplate $ substPathTemplate env template | |
where | |
env = initialPathTemplateEnv | |
- (PD.package pkg_descr) (compilerId $ LBI.compiler lbi) ++ | |
+ (PD.package pkg_descr) (compilerId $ LBI.compiler lbi) | |
+ (configHostPlatform (LBI.configFlags lbi)) ++ | |
[(BenchmarkNameVar, toPathTemplate $ PD.benchmarkName bm)] | |
diff --git a/Cabal/Distribution/Simple/Command.hs b/Cabal/Distribution/Simple/Command.hs | |
index f908ac0..bc7b7f8 100644 | |
--- a/Cabal/Distribution/Simple/Command.hs | |
+++ b/Cabal/Distribution/Simple/Command.hs | |
@@ -79,7 +79,7 @@ module Distribution.Simple.Command ( | |
-- ** OptDescr 'smart' constructors | |
MkOptDescr, | |
- reqArg, reqArg', optArg, optArg', noArg, | |
+ reqArg, reqArg', textReqArg, optArg, optArg', noArg, | |
boolOpt, boolOpt', choiceOpt, choiceOptFromEnum | |
) where | |
@@ -91,7 +91,7 @@ import Data.Maybe | |
import Data.Monoid | |
import qualified Distribution.GetOpt as GetOpt | |
import Distribution.Text | |
- ( Text(disp, parse) ) | |
+ ( Text(disp, parse), simpleParse, display ) | |
import Distribution.ParseUtils | |
import Distribution.ReadE | |
import Distribution.Simple.Utils (die, intercalate) | |
@@ -176,6 +176,14 @@ reqArg' :: Monoid b => ArgPlaceHolder -> (String -> b) -> (b -> [String]) | |
reqArg' ad mkflag showflag = | |
reqArg ad (succeedReadE mkflag) showflag | |
+textReqArg :: (Monoid b, Text b) => ArgPlaceHolder -> MkOptDescr (a -> b) (b -> a -> a) a | |
+textReqArg ad = reqArg ad parseIt formatIt | |
+ where | |
+ parseIt = ReadE $ \txt -> case simpleParse txt of | |
+ Just a -> Right a | |
+ Nothing -> Left $ "Can't parse "++ad | |
+ formatIt = (:[]) . display | |
+ | |
-- | (String -> a) variant of "optArg" | |
optArg' :: Monoid b => ArgPlaceHolder -> (Maybe String -> b) -> (b -> [Maybe String]) | |
-> MkOptDescr (a -> b) (b -> a -> a) a | |
diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs | |
index 9c3c07f..bb91225 100644 | |
--- a/Cabal/Distribution/Simple/Configure.hs | |
+++ b/Cabal/Distribution/Simple/Configure.hs | |
@@ -99,7 +99,8 @@ import Distribution.Simple.Program | |
, requireProgram, requireProgramVersion | |
, pkgConfigProgram, gccProgram, rawSystemProgramStdoutConf ) | |
import Distribution.Simple.Setup | |
- ( ConfigFlags(..), CopyDest(..), fromFlag, fromFlagOrDefault, flagToMaybe ) | |
+ ( ConfigFlags(..), CopyDest(..), fromFlag, fromFlagOrDefault, flagToMaybe | |
+ , configHostPlatform ) | |
import Distribution.Simple.InstallDirs | |
( InstallDirs(..), defaultInstallDirs, combineInstallDirs ) | |
import Distribution.Simple.LocalBuildInfo | |
@@ -114,7 +115,7 @@ import Distribution.Simple.Utils | |
, withFileContents, writeFileAtomic | |
, withTempFile ) | |
import Distribution.System | |
- ( OS(..), buildOS, Arch(..), buildArch, buildPlatform ) | |
+ ( OS(..), buildOS, Arch(..), Platform(..) ) | |
import Distribution.Version | |
( Version(..), anyVersion, orLaterVersion, withinRange, isAnyVersion ) | |
import Distribution.Verbosity | |
@@ -343,7 +344,7 @@ configure (pkg_descr0, pbi) cfg | |
case finalizePackageDescription | |
(configConfigurationsFlags cfg) | |
dependencySatisfiable | |
- Distribution.System.buildPlatform | |
+ (configHostPlatform cfg) | |
(compilerId comp) | |
(configConstraints cfg) | |
pkg_descr0'' | |
@@ -1027,7 +1028,7 @@ checkForeignDeps pkg lbi verbosity = do | |
hcDefines comp = | |
case compilerFlavor comp of | |
GHC -> | |
- let ghcOS = case buildOS of | |
+ let ghcOS = case configHostOS (configFlags lbi) of | |
Linux -> ["linux"] | |
Windows -> ["mingw32"] | |
OSX -> ["darwin"] | |
@@ -1039,8 +1040,9 @@ checkForeignDeps pkg lbi verbosity = do | |
HPUX -> ["hpux"] | |
IRIX -> ["irix"] | |
HaLVM -> [] | |
+ IOS -> ["ios"] | |
OtherOS _ -> [] | |
- ghcArch = case buildArch of | |
+ ghcArch = case configHostArch (configFlags lbi) of | |
I386 -> ["i386"] | |
X86_64 -> ["x86_64"] | |
PPC -> ["powerpc"] | |
diff --git a/Cabal/Distribution/Simple/Haddock.hs b/Cabal/Distribution/Simple/Haddock.hs | |
index 3e45ea4..7f48832 100644 | |
--- a/Cabal/Distribution/Simple/Haddock.hs | |
+++ b/Cabal/Distribution/Simple/Haddock.hs | |
@@ -70,7 +70,7 @@ import Distribution.Simple.PreProcess (ppCpp', ppUnlit | |
, preprocessComponent) | |
import Distribution.Simple.Setup | |
( defaultHscolourFlags, Flag(..), toFlag, flagToMaybe, flagToList, fromFlag | |
- , HaddockFlags(..), HscolourFlags(..) ) | |
+ , HaddockFlags(..), HscolourFlags(..), configHostPlatform ) | |
import Distribution.Simple.Build (initialBuildSteps) | |
import Distribution.Simple.InstallDirs (InstallDirs(..), PathTemplateEnv, PathTemplate, | |
PathTemplateVariable(..), | |
@@ -525,6 +525,7 @@ haddockPackageFlags lbi clbi htmlTemplate = do | |
haddockTemplateEnv :: LocalBuildInfo -> PackageIdentifier -> PathTemplateEnv | |
haddockTemplateEnv lbi pkg_id = (PrefixVar, prefix (installDirTemplates lbi)) | |
: initialPathTemplateEnv pkg_id (compilerId (compiler lbi)) | |
+ (configHostPlatform (configFlags lbi)) | |
-- -------------------------------------------------------------------------- | |
-- hscolour support | |
diff --git a/Cabal/Distribution/Simple/InstallDirs.hs b/Cabal/Distribution/Simple/InstallDirs.hs | |
index b847523..a0c827b 100644 | |
--- a/Cabal/Distribution/Simple/InstallDirs.hs | |
+++ b/Cabal/Distribution/Simple/InstallDirs.hs | |
@@ -84,7 +84,7 @@ import System.FilePath (dropDrive) | |
import Distribution.Package | |
( PackageIdentifier, packageName, packageVersion ) | |
import Distribution.System | |
- ( OS(..), buildOS, Platform(..), buildPlatform ) | |
+ ( OS(..), buildOS, Platform(..) ) | |
import Distribution.Compiler | |
( CompilerId, CompilerFlavor(..) ) | |
import Distribution.Text | |
@@ -310,10 +310,10 @@ substituteInstallDirTemplates env dirs = dirs' | |
-- | Convert from abstract install directories to actual absolute ones by | |
-- substituting for all the variables in the abstract paths, to get real | |
-- absolute path. | |
-absoluteInstallDirs :: PackageIdentifier -> CompilerId -> CopyDest | |
+absoluteInstallDirs :: PackageIdentifier -> CompilerId -> CopyDest -> Platform | |
-> InstallDirs PathTemplate | |
-> InstallDirs FilePath | |
-absoluteInstallDirs pkgId compilerId copydest dirs = | |
+absoluteInstallDirs pkgId compilerId copydest platform dirs = | |
(case copydest of | |
CopyTo destdir -> fmap ((destdir </>) . dropDrive) | |
_ -> id) | |
@@ -321,7 +321,7 @@ absoluteInstallDirs pkgId compilerId copydest dirs = | |
. fmap fromPathTemplate | |
$ substituteInstallDirTemplates env dirs | |
where | |
- env = initialPathTemplateEnv pkgId compilerId | |
+ env = initialPathTemplateEnv pkgId compilerId platform | |
-- |The location prefix for the /copy/ command. | |
@@ -336,10 +336,10 @@ data CopyDest | |
-- prevents us from making a relocatable package (also known as a \"prefix | |
-- independent\" package). | |
-- | |
-prefixRelativeInstallDirs :: PackageIdentifier -> CompilerId | |
+prefixRelativeInstallDirs :: PackageIdentifier -> CompilerId -> Platform | |
-> InstallDirTemplates | |
-> InstallDirs (Maybe FilePath) | |
-prefixRelativeInstallDirs pkgId compilerId dirs = | |
+prefixRelativeInstallDirs pkgId compilerId platform dirs = | |
fmap relative | |
. appendSubdirs combinePathTemplate | |
$ -- substitute the path template into each other, except that we map | |
@@ -349,7 +349,7 @@ prefixRelativeInstallDirs pkgId compilerId dirs = | |
prefix = PathTemplate [Variable PrefixVar] | |
} | |
where | |
- env = initialPathTemplateEnv pkgId compilerId | |
+ env = initialPathTemplateEnv pkgId compilerId platform | |
-- If it starts with $prefix then it's relative and produce the relative | |
-- path by stripping off $prefix/ or $prefix | |
@@ -421,12 +421,11 @@ substPathTemplate environment (PathTemplate template) = | |
Nothing -> [component] | |
-- | The initial environment has all the static stuff but no paths | |
-initialPathTemplateEnv :: PackageIdentifier -> CompilerId -> PathTemplateEnv | |
-initialPathTemplateEnv pkgId compilerId = | |
+initialPathTemplateEnv :: PackageIdentifier -> CompilerId -> Platform -> PathTemplateEnv | |
+initialPathTemplateEnv pkgId compilerId platform = | |
packageTemplateEnv pkgId | |
++ compilerTemplateEnv compilerId | |
- ++ platformTemplateEnv buildPlatform -- platform should be param if we want | |
- -- to do cross-platform configuation | |
+ ++ platformTemplateEnv platform | |
packageTemplateEnv :: PackageIdentifier -> PathTemplateEnv | |
packageTemplateEnv pkgId = | |
diff --git a/Cabal/Distribution/Simple/LocalBuildInfo.hs b/Cabal/Distribution/Simple/LocalBuildInfo.hs | |
index b757a89..0965fda 100644 | |
--- a/Cabal/Distribution/Simple/LocalBuildInfo.hs | |
+++ b/Cabal/Distribution/Simple/LocalBuildInfo.hs | |
@@ -86,7 +86,7 @@ import Distribution.Simple.PackageIndex | |
import Distribution.Simple.Utils | |
( die ) | |
import Distribution.Simple.Setup | |
- ( ConfigFlags ) | |
+ ( ConfigFlags, configHostPlatform ) | |
import Distribution.Text | |
( display ) | |
@@ -317,6 +317,7 @@ absoluteInstallDirs pkg lbi copydest = | |
(packageId pkg) | |
(compilerId (compiler lbi)) | |
copydest | |
+ (configHostPlatform (configFlags lbi)) | |
(installDirTemplates lbi) | |
-- |See 'InstallDirs.prefixRelativeInstallDirs' | |
@@ -326,6 +327,7 @@ prefixRelativeInstallDirs pkg_descr lbi = | |
InstallDirs.prefixRelativeInstallDirs | |
(packageId pkg_descr) | |
(compilerId (compiler lbi)) | |
+ (configHostPlatform (configFlags lbi)) | |
(installDirTemplates lbi) | |
substPathTemplate :: PackageId -> LocalBuildInfo | |
@@ -335,3 +337,4 @@ substPathTemplate pkgid lbi = fromPathTemplate | |
where env = initialPathTemplateEnv | |
pkgid | |
(compilerId (compiler lbi)) | |
+ (configHostPlatform (configFlags lbi)) | |
diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs | |
index b450d78..d3445d6 100644 | |
--- a/Cabal/Distribution/Simple/Setup.hs | |
+++ b/Cabal/Distribution/Simple/Setup.hs | |
@@ -75,7 +75,7 @@ module Distribution.Simple.Setup ( | |
BenchmarkFlags(..), emptyBenchmarkFlags, defaultBenchmarkFlags, benchmarkCommand, | |
CopyDest(..), | |
configureArgs, configureOptions, configureCCompiler, configureLinker, | |
- buildOptions, installDirsOptions, | |
+ buildOptions, installDirsOptions, configHostPlatform, | |
defaultDistPref, | |
@@ -112,6 +112,7 @@ import Distribution.Simple.Program (Program(..), ProgramConfiguration, | |
import Distribution.Simple.InstallDirs | |
( InstallDirs(..), CopyDest(..), | |
PathTemplate, toPathTemplate, fromPathTemplate ) | |
+import Distribution.System (OS, Arch, buildOS, buildArch, Platform(..)) | |
import Distribution.Verbosity | |
import Data.List ( sort ) | |
@@ -294,7 +295,9 @@ data ConfigFlags = ConfigFlags { | |
configConfigurationsFlags :: FlagAssignment, | |
configTests :: Flag Bool, -- ^Enable test suite compilation | |
configBenchmarks :: Flag Bool, -- ^Enable benchmark compilation | |
- configLibCoverage :: Flag Bool -- ^ Enable test suite program coverage | |
+ configLibCoverage :: Flag Bool, -- ^ Enable test suite program coverage | |
+ configHostOS :: OS, | |
+ configHostArch :: Arch | |
} | |
deriving (Read,Show) | |
@@ -482,6 +485,14 @@ configureOptions showOrParseArgs = | |
"dependency checking and compilation for benchmarks listed in the package description file." | |
configBenchmarks (\v flags -> flags { configBenchmarks = v }) | |
(boolOpt [] []) | |
+ ,option "" ["host-os"] | |
+ "specify host OS, i.e. OS to cross-compile to" | |
+ configHostOS (\v flags -> flags { configHostOS = v }) | |
+ (textReqArg "HOST_OS") | |
+ ,option "" ["host-arch"] | |
+ "specify host Arch, i.e. CPU to cross-compile to" | |
+ configHostArch (\v flags -> flags { configHostArch = v }) | |
+ (textReqArg "HOST_ARCH") | |
] | |
where | |
readFlagList :: String -> FlagAssignment | |
@@ -606,7 +617,9 @@ instance Monoid ConfigFlags where | |
configConfigurationsFlags = mempty, | |
configTests = mempty, | |
configLibCoverage = mempty, | |
- configBenchmarks = mempty | |
+ configBenchmarks = mempty, | |
+ configHostOS = buildOS, | |
+ configHostArch = buildArch | |
} | |
mappend a b = ConfigFlags { | |
configPrograms = configPrograms b, | |
@@ -639,7 +652,9 @@ instance Monoid ConfigFlags where | |
configConfigurationsFlags = combine configConfigurationsFlags, | |
configTests = combine configTests, | |
configLibCoverage = combine configLibCoverage, | |
- configBenchmarks = combine configBenchmarks | |
+ configBenchmarks = combine configBenchmarks, | |
+ configHostOS = combine configHostOS, | |
+ configHostArch = combine configHostArch | |
} | |
where combine field = field a `mappend` field b | |
@@ -1644,6 +1659,9 @@ splitArgs = space [] | |
word [] s = s | |
word w s = reverse w : s | |
+configHostPlatform :: ConfigFlags -> Platform | |
+configHostPlatform cfg = Platform (configHostArch cfg) (configHostOS cfg) | |
+ | |
-- The test cases kinda have to be rewritten from the ground up... :/ | |
--hunitTests :: [Test] | |
--hunitTests = | |
diff --git a/Cabal/Distribution/Simple/Test.hs b/Cabal/Distribution/Simple/Test.hs | |
index 990b3a5..c9e2ea3 100644 | |
--- a/Cabal/Distribution/Simple/Test.hs | |
+++ b/Cabal/Distribution/Simple/Test.hs | |
@@ -70,7 +70,8 @@ import Distribution.Simple.InstallDirs | |
, substPathTemplate , toPathTemplate, PathTemplate ) | |
import qualified Distribution.Simple.LocalBuildInfo as LBI | |
( LocalBuildInfo(..) ) | |
-import Distribution.Simple.Setup ( TestFlags(..), TestShowDetails(..), fromFlag ) | |
+import Distribution.Simple.Setup | |
+ ( TestFlags(..), TestShowDetails(..), fromFlag, configHostPlatform ) | |
import Distribution.Simple.Utils ( die, notice, rawSystemIOWithEnv ) | |
import Distribution.TestSuite | |
( OptionDescr(..), Options, Progress(..), Result(..), TestInstance(..) | |
@@ -430,6 +431,7 @@ testSuiteLogPath template pkg_descr lbi testLog = | |
where | |
env = initialPathTemplateEnv | |
(PD.package pkg_descr) (compilerId $ LBI.compiler lbi) | |
+ (configHostPlatform (LBI.configFlags lbi)) | |
++ [ (TestSuiteNameVar, toPathTemplate $ testSuiteName testLog) | |
, (TestSuiteResultVar, result) | |
] | |
@@ -446,7 +448,8 @@ testOption pkg_descr lbi suite template = | |
fromPathTemplate $ substPathTemplate env template | |
where | |
env = initialPathTemplateEnv | |
- (PD.package pkg_descr) (compilerId $ LBI.compiler lbi) ++ | |
+ (PD.package pkg_descr) (compilerId $ LBI.compiler lbi) | |
+ (configHostPlatform (LBI.configFlags lbi)) ++ | |
[(TestSuiteNameVar, toPathTemplate $ PD.testName suite)] | |
packageLogPath :: PathTemplate | |
@@ -458,6 +461,7 @@ packageLogPath template pkg_descr lbi = | |
where | |
env = initialPathTemplateEnv | |
(PD.package pkg_descr) (compilerId $ LBI.compiler lbi) | |
+ (configHostPlatform (LBI.configFlags lbi)) | |
-- | The filename of the source file for the stub executable associated with a | |
-- library 'TestSuite'. | |
diff --git a/Cabal/Distribution/System.hs b/Cabal/Distribution/System.hs | |
index 02d5da7..c2fd1f4 100644 | |
--- a/Cabal/Distribution/System.hs | |
+++ b/Cabal/Distribution/System.hs | |
@@ -31,6 +31,7 @@ import qualified System.Info (os, arch) | |
import qualified Data.Char as Char (toLower, isAlphaNum) | |
import Data.Maybe (fromMaybe) | |
+import Data.Monoid (Monoid(..)) | |
import Distribution.Text (Text(..), display) | |
import qualified Distribution.Compat.ReadP as Parse | |
import qualified Text.PrettyPrint as Disp | |
@@ -63,6 +64,7 @@ data OS = Linux | Windows | OSX -- teir 1 desktop OSs | |
| FreeBSD | OpenBSD | NetBSD -- other free unix OSs | |
| Solaris | AIX | HPUX | IRIX -- ageing Unix OSs | |
| HaLVM -- bare metal / VMs / hypervisors | |
+ | IOS -- mobile OSes | |
| OtherOS String | |
deriving (Eq, Ord, Show, Read) | |
@@ -75,12 +77,13 @@ knownOSs :: [OS] | |
knownOSs = [Linux, Windows, OSX | |
,FreeBSD, OpenBSD, NetBSD | |
,Solaris, AIX, HPUX, IRIX | |
- ,HaLVM] | |
+ ,HaLVM, IOS] | |
osAliases :: ClassificationStrictness -> OS -> [String] | |
osAliases Permissive Windows = ["mingw32", "cygwin32"] | |
osAliases Compat Windows = ["mingw32", "win32"] | |
osAliases _ OSX = ["darwin"] | |
+osAliases _ IOS = ["ios"] | |
osAliases Permissive FreeBSD = ["kfreebsdgnu"] | |
osAliases Permissive Solaris = ["solaris2"] | |
osAliases _ _ = [] | |
@@ -91,6 +94,11 @@ instance Text OS where | |
parse = fmap (classifyOS Compat) ident | |
+instance Monoid OS where | |
+ mempty = buildOS | |
+ a `mappend` b = if a == buildOS then b else | |
+ if b == buildOS then a else a | |
+ | |
classifyOS :: ClassificationStrictness -> String -> OS | |
classifyOS strictness s = | |
fromMaybe (OtherOS s) $ lookup (lowercase s) osMap | |
@@ -137,6 +145,11 @@ instance Text Arch where | |
parse = fmap (classifyArch Strict) ident | |
+instance Monoid Arch where | |
+ mempty = buildArch | |
+ a `mappend` b = if a == buildArch then b else | |
+ if b == buildArch then a else a | |
+ | |
classifyArch :: ClassificationStrictness -> String -> Arch | |
classifyArch strictness s = | |
fromMaybe (OtherArch s) $ lookup (lowercase s) archMap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment