Cabal changes to make it use toolchain versions of both GHC and GCC. --- ghc-6.10.2.orig/libraries/Cabal/Distribution/Simple/Toolchain.hs.in 1970-01-01 12:00:00.000000000 +1200 +++ ghc-6.10.2/libraries/Cabal/Distribution/Simple/Toolchain.hs.in 2009-06-18 15:54:37.000000000 +1200 @@ -0,0 +1,41 @@ +module Distribution.Simple.ToolChain where + + +data ToolChain = ToolChain { + targetGCC :: String, + targetLD :: String, + targetAR :: String, + targetRANLIB :: String, + targetSTRIP :: String, + targetCPPFLAGS :: String, + targetCFLAGS :: String, + targetLDFLAGS :: String, + localGCC :: String, + localCPPFLAGS :: String, + localCFLAGS :: String, + localLDFLAGS :: String, + toolChainGHC :: String, + toolChainGHCPKG :: String, + toolChainVersionTags :: String + } + deriving Show + +defaultToolChain :: ToolChain +defaultToolChain = ToolChain { + targetGCC = "@TARGET_GCC@", + targetLD = "@TARGET_LD@", + targetAR = "@TARGET_AR@", + targetRANLIB = "@TARGET_RANLIB@", + targetSTRIP = "@TARGET_STRIP@", + targetCPPFLAGS = "@TARGET_CPPFLAGS@", + targetCFLAGS = "@TARGET_CFLAGS@", + targetLDFLAGS = "@TARGET_LDFLAGS@", + localGCC = "@LOCAL_GCC@", + localCPPFLAGS = "@LOCAL_CPPFLAGS@", + localCFLAGS = "@LOCAL_CFLAGS@", + localLDFLAGS = "@LOCAL_LDFLAGS@", + toolChainGHC = "ghc-@ProjectVersion@@TOOLCHAIN_VERSION_TAGS@", + toolChainGHCPKG = "ghc-pkg-@ProjectVersion@@TOOLCHAIN_VERSION_TAGS@", + toolChainVersionTags = "@TOOLCHAIN_VERSION_TAGS@" + } + --- ghc-6.10.2.orig/libraries/Cabal/Cabal.cabal 2009-03-31 06:16:33.000000000 +1300 +++ ghc-6.10.2/libraries/Cabal/Cabal.cabal 2009-06-18 15:54:37.000000000 +1200 @@ -94,6 +94,7 @@ Distribution.Simple.Register, Distribution.Simple.Setup, Distribution.Simple.SrcDist, + Distribution.Simple.ToolChain, Distribution.Simple.UserHooks, Distribution.Simple.Utils, Distribution.System, --- ghc-6.10.2.orig/libraries/Cabal/Distribution/Simple/Configure.hs 2009-03-31 06:16:33.000000000 +1300 +++ ghc-6.10.2/libraries/Cabal/Distribution/Simple/Configure.hs 2009-06-18 15:54:37.000000000 +1200 @@ -109,6 +109,7 @@ , withTempFile ) import Distribution.Simple.Register ( removeInstalledConfig ) +import Distribution.Simple.ToolChain import Distribution.System ( OS(..), buildOS, buildArch ) import Distribution.Version @@ -287,6 +288,7 @@ (comp, programsConfig') <- configCompiler (flagToMaybe $ configHcFlavor cfg) (flagToMaybe $ configHcPath cfg) (flagToMaybe $ configHcPkg cfg) + (configToolChain cfg) programsConfig (lessVerbose verbosity) let version = compilerVersion comp flavor = compilerFlavor comp @@ -622,6 +624,7 @@ configCompilerAux cfg = configCompiler (flagToMaybe $ configHcFlavor cfg) (flagToMaybe $ configHcPath cfg) (flagToMaybe $ configHcPkg cfg) + (configToolChain cfg) programsConfig (fromFlag (configVerbosity cfg)) where @@ -629,13 +632,13 @@ . userSpecifyPaths (configProgramPaths cfg) $ defaultProgramConfiguration -configCompiler :: Maybe CompilerFlavor -> Maybe FilePath -> Maybe FilePath +configCompiler :: Maybe CompilerFlavor -> Maybe FilePath -> Maybe FilePath -> ToolChain -> ProgramConfiguration -> Verbosity -> IO (Compiler, ProgramConfiguration) -configCompiler Nothing _ _ _ _ = die "Unknown compiler" -configCompiler (Just hcFlavor) hcPath hcPkg conf verbosity = do +configCompiler Nothing _ _ _ _ _ = die "Unknown compiler" +configCompiler (Just hcFlavor) hcPath hcPkg toolchain conf verbosity = do case hcFlavor of - GHC -> GHC.configure verbosity hcPath hcPkg conf + GHC -> GHC.configure verbosity hcPath hcPkg toolchain conf JHC -> JHC.configure verbosity hcPath hcPkg conf Hugs -> Hugs.configure verbosity hcPath hcPkg conf NHC -> NHC.configure verbosity hcPath hcPkg conf --- ghc-6.10.2.orig/libraries/Cabal/Distribution/Simple/GHC.hs 2009-03-31 06:16:33.000000000 +1300 +++ ghc-6.10.2/libraries/Cabal/Distribution/Simple/GHC.hs 2009-06-18 15:54:37.000000000 +1200 @@ -101,10 +101,11 @@ , rawSystemProgramStdout, rawSystemProgramStdoutConf, requireProgram , userMaybeSpecifyPath, programPath, lookupProgram, addKnownProgram , ghcProgram, ghcPkgProgram, arProgram, ranlibProgram, ldProgram - , gccProgram, stripProgram ) + , gccProgram, localGccProgram, stripProgram, findProgramOnPath ) import Distribution.Simple.Compiler ( CompilerFlavor(..), CompilerId(..), Compiler(..), compilerVersion , OptimisationLevel(..), PackageDB(..), Flag, extensionsToFlags ) +import Distribution.Simple.ToolChain import Distribution.Version ( Version(..), VersionRange(..), orLaterVersion ) import Distribution.System @@ -132,9 +133,9 @@ -- ----------------------------------------------------------------------------- -- Configuring -configure :: Verbosity -> Maybe FilePath -> Maybe FilePath +configure :: Verbosity -> Maybe FilePath -> Maybe FilePath -> ToolChain -> ProgramConfiguration -> IO (Compiler, ProgramConfiguration) -configure verbosity hcPath hcPkgPath conf = do +configure verbosity hcPath hcPkgPath toolChain conf = do (ghcProg, conf') <- requireProgram verbosity ghcProgram (orLaterVersion (Version [6,4] [])) @@ -162,7 +163,7 @@ compilerId = CompilerId GHC ghcVersion, compilerExtensions = languageExtensions } - conf''' = configureToolchain ghcProg conf'' -- configure gcc and ld + conf''' = configureToolchain toolChain ghcProg conf'' -- configure gcc and ld return (comp, conf''') -- | Given something like /usr/local/bin/ghc-6.6.1(.exe) we try and find a @@ -177,11 +178,10 @@ = do let path = programPath ghcProg dir = takeDirectory path versionSuffix = takeVersionSuffix (dropExeExtension path) - guessNormal = dir "ghc-pkg" <.> exeExtension - guessVersioned = dir ("ghc-pkg" ++ versionSuffix) <.> exeExtension - guesses | null versionSuffix = [guessNormal] - | otherwise = [guessVersioned, guessNormal] - info verbosity $ "looking for package tool: ghc-pkg near compiler in " ++ dir + ghc_pkg = toolChainGHCPKG defaultToolChain + guessNormal = dir ghc_pkg <.> exeExtension + guesses = [guessNormal] + info verbosity $ "looking for package tool: "++ghc_pkg++" near compiler in " ++ dir exists <- mapM doesFileExist guesses case [ file | (file, True) <- zip guesses exists ] of [] -> return Nothing @@ -199,18 +199,37 @@ -- | Adjust the way we find and configure gcc and ld -- -configureToolchain :: ConfiguredProgram -> ProgramConfiguration +configureToolchain :: ToolChain -> ConfiguredProgram -> ProgramConfiguration -> ProgramConfiguration -configureToolchain ghcProg = +configureToolchain toolChain ghcProg = addKnownProgram gccProgram { - programFindLocation = findProg gccProgram (baseDir "gcc.exe"), - programPostConf = configureGcc + programFindLocation = findProgramOnPath $ targetGCC toolChain, + programPostConf = \_ _ -> + return $ words (targetCPPFLAGS toolChain) ++ words (targetCFLAGS toolChain) + } + . addKnownProgram localGccProgram { + programFindLocation = findProgramOnPath $ localGCC toolChain, + programPostConf = \_ _ -> + return $ words (localCPPFLAGS toolChain) ++ words (localCFLAGS toolChain) + ++ words (localLDFLAGS toolChain) } . addKnownProgram ldProgram { - programFindLocation = findProg ldProgram (libDir "ld.exe"), - programPostConf = configureLd + programFindLocation = findProgramOnPath $ targetLD toolChain, + programPostConf = \verbosity ldProg -> do + args <- configureLd verbosity ldProg + return $ args ++ words (targetLDFLAGS toolChain) + } + . addKnownProgram arProgram { + programFindLocation = findProgramOnPath $ dropExtraArgs $ targetAR toolChain + } + . addKnownProgram ranlibProgram { + programFindLocation = findProgramOnPath $ dropExtraArgs $ targetRANLIB toolChain + } + . addKnownProgram stripProgram { + programFindLocation = findProgramOnPath $ dropExtraArgs $ targetSTRIP toolChain } where + dropExtraArgs cmd = head $ words cmd ++ [""] compilerDir = takeDirectory (programPath ghcProg) baseDir = takeDirectory compilerDir libDir = baseDir "gcc-lib" @@ -253,6 +272,9 @@ return True `catchIO` (\_ -> return False) `catchExit` (\_ -> return False) + `Prelude.catch` (\exc -> do + putStrLn $ "caught unexpected " ++ show exc + return False) if ldx then return ["-x"] else return [] @@ -474,6 +496,7 @@ libBi <- hackThreadedFlag verbosity (compiler lbi) (withProfLib lbi) (libBuildInfo lib) + let frameworkArgs = concat [["-framework", f] | f <- PD.frameworks libBi] let libTargetDir = pref forceVanillaLib = TemplateHaskell `elem` extensions libBi @@ -508,7 +531,7 @@ sequence_ [do let (odir,args) = constructCcCmdLine lbi libBi pref filename verbosity createDirectoryIfMissingVerbose verbosity True odir - runGhcProg args + runGhcProg (args ++ frameworkArgs) ifSharedLib (runGhcProg (args ++ ["-fPIC", "-osuf dyn_o"])) | filename <- cSources libBi] @@ -629,6 +652,7 @@ exeBi <- hackThreadedFlag verbosity (compiler lbi) (withProfExe lbi) (buildInfo exe) + let frameworkArgs = concat [["-framework", f] | f <- PD.frameworks exeBi] -- exeNameReal, the name that GHC really uses (with .exe on Windows) let exeNameReal = exeName' <.> @@ -647,7 +671,7 @@ sequence_ [do let (odir,args) = constructCcCmdLine lbi exeBi exeDir filename verbosity createDirectoryIfMissingVerbose verbosity True odir - runGhcProg args + runGhcProg (args ++ frameworkArgs) | filename <- cSources exeBi] srcMainFile <- findFile (exeDir : hsSourceDirs exeBi) modPath @@ -663,7 +687,7 @@ ++ ["-optl" ++ opt | opt <- PD.ldOptions exeBi] ++ ["-l"++lib | lib <- extraLibs exeBi] ++ ["-L"++libDir | libDir <- extraLibDirs exeBi] - ++ concat [["-framework", f] | f <- PD.frameworks exeBi] + ++ frameworkArgs ++ if profExe then ["-prof", "-hisuf", "p_hi", --- ghc-6.10.2.orig/libraries/Cabal/Distribution/Simple/PreProcess.hs 2009-03-31 06:16:33.000000000 +1300 +++ ghc-6.10.2/libraries/Cabal/Distribution/Simple/PreProcess.hs 2009-06-18 15:54:37.000000000 +1200 @@ -80,7 +80,8 @@ ( Program(..), ConfiguredProgram(..), lookupProgram, programPath , rawSystemProgramConf, rawSystemProgram , greencardProgram, cpphsProgram, hsc2hsProgram, c2hsProgram - , happyProgram, alexProgram, haddockProgram, ghcProgram, gccProgram ) + , happyProgram, alexProgram, haddockProgram, ghcProgram, gccProgram + , localGccProgram ) import Distribution.System ( OS(OSX), buildOS ) import Distribution.Version (Version(..)) @@ -354,12 +355,12 @@ ppHsc2hs :: BuildInfo -> LocalBuildInfo -> PreProcessor ppHsc2hs bi lbi = standardPP lbi hsc2hsProgram $ - [ "--cc=" ++ programPath gccProg - , "--ld=" ++ programPath gccProg ] + [ "--cc=" ++ programPath localGccProg + , "--ld=" ++ programPath localGccProg ] -- Additional gcc options - ++ [ "--cflag=" ++ opt | opt <- programArgs gccProg ] - ++ [ "--lflag=" ++ opt | opt <- programArgs gccProg ] + ++ [ "--cflag=" ++ opt | opt <- programArgs localGccProg ] + ++ [ "--lflag=" ++ opt | opt <- programArgs localGccProg ] -- OSX frameworks: ++ [ what ++ "=-F" ++ opt @@ -390,7 +391,7 @@ ++ [ opt | opt <- Installed.ldOptions pkg ] ] where pkgs = PackageIndex.topologicalOrder (packageHacks (installedPkgs lbi)) - Just gccProg = lookupProgram gccProgram (withPrograms lbi) + Just localGccProg = lookupProgram localGccProgram (withPrograms lbi) isOSX = case buildOS of OSX -> True; _ -> False packageHacks = case compilerFlavor (compiler lbi) of GHC -> hackRtsPackage --- ghc-6.10.2.orig/libraries/Cabal/Distribution/Simple/Program.hs 2009-03-31 06:16:33.000000000 +1300 +++ ghc-6.10.2/libraries/Cabal/Distribution/Simple/Program.hs 2009-06-18 15:54:37.000000000 +1200 @@ -83,6 +83,7 @@ , hugsProgram , ffihugsProgram , gccProgram + , localGccProgram , ranlibProgram , arProgram , stripProgram @@ -106,6 +107,7 @@ import Distribution.Simple.Utils (die, debug, warn, rawSystemExit, rawSystemStdout) +import Distribution.Simple.ToolChain import Distribution.Version ( Version(..), VersionRange(AnyVersion), withinRange ) import Distribution.Text @@ -572,17 +574,20 @@ , stripProgram , ldProgram , tarProgram + , localGccProgram -- configuration tools , pkgConfigProgram ] ghcProgram :: Program ghcProgram = (simpleProgram "ghc") { + programFindLocation = findProgramOnPath (toolChainGHC defaultToolChain), programFindVersion = findProgramVersion "--numeric-version" id } ghcPkgProgram :: Program ghcPkgProgram = (simpleProgram "ghc-pkg") { + programFindLocation = findProgramOnPath (toolChainGHCPKG defaultToolChain), programFindVersion = findProgramVersion "--version" $ \str -> -- Invoking "ghc-pkg --version" gives a string like -- "GHC package manager version 6.4.1" @@ -654,6 +659,11 @@ programFindVersion = findProgramVersion "-dumpversion" id } +localGccProgram :: Program +localGccProgram = (simpleProgram "local-gcc") { + programFindVersion = findProgramVersion "-dumpversion" id + } + ranlibProgram :: Program ranlibProgram = simpleProgram "ranlib"