- modHook f pd lbi us flags
- = let idts = installDirTemplates lbi
- idts' = idts { prefix = toPathTemplate myPrefix,
- libdir = toPathTemplate myLibdir,
- libsubdir = toPathTemplate "$pkgid",
- docdir = toPathTemplate (myDocdir </> "$pkg"),
- htmldir = toPathTemplate "$docdir" }
- progs = withPrograms lbi
- ghcProg = ConfiguredProgram {
- programId = programName ghcProgram,
- programVersion = Nothing,
- programArgs = ["-B" ++ topdir],
- programLocation = UserSpecified ghc
- }
- ghcpkgconf = topdir </> "package.conf"
- ghcPkgProg = ConfiguredProgram {
- programId = programName ghcPkgProgram,
- programVersion = Nothing,
- programArgs = ["--global-conf",
- ghcpkgconf]
- ++ if not (null myDestDir)
- then ["--force"]
- else [],
- programLocation = UserSpecified ghcpkg
- }
- progs' = updateProgram ghcProg
- $ updateProgram ghcPkgProg progs
- lbi' = lbi {
- installDirTemplates = idts',
- withPrograms = progs'
- }
- in f pd lbi' us flags
+ modHook relocatableBuild f pd lbi us flags
+ = do let verbosity = normal
+ idts = installDirTemplates lbi
+ 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/../doc/html/libraries/$pkgid"
+ else (myDocdir </> "$pkgid"),
+ htmldir = toPathTemplate "$docdir"
+ }
+ progs = withPrograms lbi
+ ghcProg = ConfiguredProgram {
+ programId = programName ghcProgram,
+ programVersion = Nothing,
+ programDefaultArgs = ["-B" ++ topdir],
+ programOverrideArgs = [],
+ programLocation = UserSpecified ghc
+ }
+ ghcpkgconf = topdir </> "package.conf.d"
+ ghcPkgProg = ConfiguredProgram {
+ programId = programName ghcPkgProgram,
+ programVersion = Nothing,
+ programDefaultArgs = ["--global-conf",
+ ghcpkgconf]
+ ++ if not (null myDestDir)
+ then ["--force"]
+ else [],
+ programOverrideArgs = [],
+ programLocation = UserSpecified ghcpkg
+ }
+ stripProg = ConfiguredProgram {
+ programId = programName stripProgram,
+ programVersion = Nothing,
+ programDefaultArgs = [],
+ programOverrideArgs = [],
+ programLocation = UserSpecified strip
+ }
+ progs' = updateProgram ghcProg
+ $ updateProgram ghcPkgProg
+ $ updateProgram stripProg
+ progs
+ instInfos <- dump verbosity ghcPkgProg GlobalPackageDB
+ let installedPkgs' = PackageIndex.fromList instInfos
+ let mlc = libraryConfig lbi
+ mlc' = case mlc of
+ Just lc ->
+ let cipds = componentPackageDeps lc
+ cipds' = [ (fixupPackageId instInfos ipid, pid)
+ | (ipid,pid) <- cipds ]
+ in Just $ lc {
+ componentPackageDeps = cipds'
+ }
+ Nothing -> Nothing
+ lbi' = lbi {
+ libraryConfig = mlc',
+ installedPkgs = installedPkgs',
+ installDirTemplates = idts',
+ withPrograms = progs'
+ }
+ f pd lbi' us flags
+
+-- The packages are built with the package ID ending in "-inplace", but
+-- when they're installed they get the package hash appended. We need to
+-- fix up the package deps so that they use the hash package IDs, not
+-- the inplace package IDs.
+fixupPackageId :: [Installed.InstalledPackageInfo]
+ -> InstalledPackageId
+ -> InstalledPackageId
+fixupPackageId _ x@(InstalledPackageId ipi)
+ | "builtin_" `isPrefixOf` ipi = x
+fixupPackageId ipinfos (InstalledPackageId ipi)
+ = case stripPrefix (reverse "-inplace") $ reverse ipi of
+ Nothing ->
+ error ("Installed package ID doesn't end in -inplace: " ++ show ipi)
+ Just x ->
+ let ipi' = reverse ('-' : x)
+ f (ipinfo : ipinfos') = case Installed.installedPackageId ipinfo of
+ y@(InstalledPackageId ipinfoid)
+ | ipi' `isPrefixOf` ipinfoid ->
+ y
+ _ ->
+ f ipinfos'
+ f [] = error ("Installed package ID not registered: " ++ show ipi)
+ in f ipinfos