X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=utils%2Fghc-cabal%2Fghc-cabal.hs;h=f724617c6a0d996430b0adc44b521ea11f8ac05d;hb=6199781240ee68bc2250a91517b1cc3c7a514332;hp=1b06cf4ba8de46610f5f55b7b34cf11b9bfac1f1;hpb=da8ca5158b9421c67df854f9e66ad8ae09b3ec66;p=ghc-hetmet.git diff --git a/utils/ghc-cabal/ghc-cabal.hs b/utils/ghc-cabal/ghc-cabal.hs index 1b06cf4..f724617 100644 --- a/utils/ghc-cabal/ghc-cabal.hs +++ b/utils/ghc-cabal/ghc-cabal.hs @@ -35,9 +35,11 @@ main = do args <- getArgs "check" : dir : [] -> doCheck dir "install" : ghc : ghcpkg : topdir : directory : distDir - : myDestDir : myPrefix : myLibdir : myDocdir : args' -> + : myDestDir : myPrefix : myLibdir : myDocdir + : relocatableBuild : args' -> doInstall ghc ghcpkg topdir directory distDir - myDestDir myPrefix myLibdir myDocdir args' + myDestDir myPrefix myLibdir myDocdir + relocatableBuild args' "configure" : args' -> case break (== "--") args' of (config_args, "--" : distdir : directories) -> mapM_ (generate config_args distdir) directories @@ -52,7 +54,7 @@ syntax_error = " ghc-cabal install ...", " ghc-cabal haddock ..."] -die :: [String] -> IO () +die :: [String] -> IO a die errs = do mapM_ (hPutStrLn stderr) errs exitWith (ExitFailure 1) @@ -137,21 +139,37 @@ runHaddock distdir directory args = f pd lbi us flags doInstall :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath - -> FilePath -> FilePath -> FilePath -> FilePath -> [String] + -> FilePath -> FilePath -> FilePath -> FilePath -> String + -> [String] -> IO () -doInstall ghc ghcpkg topdir directory distDir myDestDir myPrefix myLibdir myDocdir args +doInstall ghc ghcpkg topdir directory distDir + myDestDir myPrefix myLibdir myDocdir + relocatableBuildStr args = withCurrentDirectory directory $ do - defaultMainWithHooksArgs hooks (["copy", "--builddir", distDir] - ++ (if null myDestDir then [] - else ["--destdir", myDestDir]) - ++ args) - defaultMainWithHooksArgs hooks ("register" : "--builddir" : distDir : args) - where - hooks = userHooks { - copyHook = noGhcPrimHook (modHook (copyHook userHooks)), - regHook = modHook (regHook userHooks) - } + relocatableBuild <- case relocatableBuildStr of + "YES" -> return True + "NO" -> return False + _ -> die ["Bad relocatableBuildStr: " ++ + show relocatableBuildStr] + let copyArgs = ["copy", "--builddir", distDir] + ++ (if null myDestDir + then [] + else ["--destdir", myDestDir]) + ++ args + regArgs = "register" : "--builddir" : distDir : args + copyHooks = userHooks { + copyHook = noGhcPrimHook + $ modHook False + $ copyHook userHooks + } + regHooks = userHooks { + regHook = modHook relocatableBuild + $ regHook userHooks + } + defaultMainWithHooksArgs copyHooks copyArgs + defaultMainWithHooksArgs regHooks regArgs + where noGhcPrimHook f pd lbi us flags = let pd' | packageName pd == PackageName "ghc-prim" = @@ -165,14 +183,25 @@ doInstall ghc ghcpkg topdir directory distDir myDestDir myPrefix myLibdir myDocd error "Expected a library, but none found" | otherwise = pd in f pd' lbi us flags - modHook f pd lbi us flags + modHook relocatableBuild f pd lbi us flags = do let verbosity = normal idts = installDirTemplates lbi - idts' = idts { prefix = toPathTemplate myPrefix, - libdir = toPathTemplate myLibdir, - libsubdir = toPathTemplate "$pkgid", - docdir = toPathTemplate (myDocdir "$pkg"), - htmldir = toPathTemplate "$docdir" } + idts' = idts { + prefix = toPathTemplate $ + if relocatableBuild + then "$topdir" + else myPrefix, + libdir = toPathTemplate $ + if relocatableBuild + then "$topdir" + else myLibdir, + libsubdir = toPathTemplate "$pkgid", + docdir = toPathTemplate $ + if relocatableBuild + then "$topdir/$pkg" + else (myDocdir "$pkg"), + htmldir = toPathTemplate "$docdir" + } progs = withPrograms lbi ghcProg = ConfiguredProgram { programId = programName ghcProgram, @@ -194,15 +223,15 @@ doInstall ghc ghcpkg topdir directory distDir myDestDir myPrefix myLibdir myDocd progs' = updateProgram ghcProg $ updateProgram ghcPkgProg progs instInfos <- dump verbosity ghcPkgProg GlobalPackageDB - let installedPkgs' = PackageIndex.listToInstalledPackageIndex - instInfos + let installedPkgs' = PackageIndex.fromList instInfos let mlc = libraryConfig lbi mlc' = case mlc of Just lc -> - let cipds = componentInstalledPackageDeps lc - cipds' = map (fixupPackageId instInfos) cipds + let cipds = componentPackageDeps lc + cipds' = [ (fixupPackageId instInfos ipid, pid) + | (ipid,pid) <- cipds ] in Just $ lc { - componentInstalledPackageDeps = cipds' + componentPackageDeps = cipds' } Nothing -> Nothing lbi' = lbi { @@ -306,12 +335,11 @@ generate config_args distdir directory -- stricter than gnu ld). Thus we remove the ldOptions for -- GHC's rts package: hackRtsPackage index = - case PackageIndex.lookupInstalledPackageByName index (PackageName "rts") of - [rts] -> PackageIndex.addToInstalledPackageIndex rts { Installed.ldOptions = [] } index + case PackageIndex.lookupPackageName index (PackageName "rts") of + [(_,[rts])] -> PackageIndex.insert rts{ Installed.ldOptions = [] } index _ -> error "No (or multiple) ghc rts package is registered!!" - dep_ids = map (packageId.getLocalPackageInfo lbi) $ - externalPackageDeps lbi + dep_ids = map snd (externalPackageDeps lbi) let variablePrefix = directory ++ '_':distdir let xs = [variablePrefix ++ "_VERSION = " ++ display (pkgVersion (package pd)),