Add support for relocatable builds in the new build system
authorIan Lynagh <igloo@earth.li>
Sun, 27 Sep 2009 01:06:05 +0000 (01:06 +0000)
committerIan Lynagh <igloo@earth.li>
Sun, 27 Sep 2009 01:06:05 +0000 (01:06 +0000)
ghc.mk
utils/ghc-cabal/ghc-cabal.hs

diff --git a/ghc.mk b/ghc.mk
index 3f6b615..7541a87 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -808,13 +808,15 @@ install_packages: libffi/package.conf.install rts/package.conf.install
                 $(INSTALLED_GHC_PKG_REAL) \
                 $(DESTDIR)$(topdir) \
                 libraries/$p dist-install \
                 $(INSTALLED_GHC_PKG_REAL) \
                 $(DESTDIR)$(topdir) \
                 libraries/$p dist-install \
-                '$(DESTDIR)' '$(prefix)' '$(ghclibdir)' '$(docdir)/html/libraries' &&) true
+                '$(DESTDIR)' '$(prefix)' '$(ghclibdir)' '$(docdir)/html/libraries' \
+                $(RelocatableBuild) &&) true
        "$(GHC_CABAL_INPLACE)" install \
                 $(INSTALLED_GHC_REAL) \
                 $(INSTALLED_GHC_PKG_REAL) \
                 $(DESTDIR)$(topdir) \
                 compiler stage2 \
        "$(GHC_CABAL_INPLACE)" install \
                 $(INSTALLED_GHC_REAL) \
                 $(INSTALLED_GHC_PKG_REAL) \
                 $(DESTDIR)$(topdir) \
                 compiler stage2 \
-                '$(DESTDIR)' '$(prefix)' '$(ghclibdir)' '$(docdir)/html/libraries'
+                '$(DESTDIR)' '$(prefix)' '$(ghclibdir)' '$(docdir)/html/libraries' \
+                $(RelocatableBuild)
 
 # -----------------------------------------------------------------------------
 # Binary distributions
 
 # -----------------------------------------------------------------------------
 # Binary distributions
index 1b06cf4..29e0f5c 100644 (file)
@@ -35,9 +35,11 @@ main = do args <- getArgs
               "check" : dir : [] ->
                   doCheck dir
               "install" : ghc : ghcpkg : topdir : directory : distDir
               "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
                   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
               "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-pkg> <directory> <distdir> <destdir> <prefix> <args>...",
      "        ghc-cabal haddock <distdir> <directory> <args>..."]
 
      "        ghc-cabal install <ghc-pkg> <directory> <distdir> <destdir> <prefix> <args>...",
      "        ghc-cabal haddock <distdir> <directory> <args>..."]
 
-die :: [String] -> IO ()
+die :: [String] -> IO a
 die errs = do mapM_ (hPutStrLn stderr) errs
               exitWith (ExitFailure 1)
 
 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
           = f pd lbi us flags
 
 doInstall :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath
-          -> FilePath -> FilePath -> FilePath -> FilePath -> [String]
+          -> FilePath -> FilePath -> FilePath -> FilePath -> String
+          -> [String]
           -> IO ()
           -> 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
  = 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" =
       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
                             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
        = 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,
                 progs = withPrograms lbi
                 ghcProg = ConfiguredProgram {
                               programId = programName ghcProgram,