Fix the doc directory on Windows
[ghc-hetmet.git] / utils / ghc-cabal / ghc-cabal.hs
index 9a99ad4..fb1c870 100644 (file)
@@ -30,14 +30,14 @@ import System.FilePath
 main :: IO ()
 main = do args <- getArgs
           case args of
-              "haddock" : distDir : dir : args' ->
-                  runHaddock distDir dir args'
+              "hscolour" : distDir : dir : args' ->
+                  runHsColour distDir dir args'
               "check" : dir : [] ->
                   doCheck dir
-              "install" : ghc : ghcpkg : topdir : directory : distDir
+              "install" : ghc : ghcpkg : strip : topdir : directory : distDir
                         : myDestDir : myPrefix : myLibdir : myDocdir
                         : relocatableBuild : args' ->
-                  doInstall ghc ghcpkg topdir directory distDir
+                  doInstall ghc ghcpkg strip topdir directory distDir
                             myDestDir myPrefix myLibdir myDocdir
                             relocatableBuild args'
               "configure" : args' -> case break (== "--") args' of
@@ -52,7 +52,7 @@ syntax_error :: [String]
 syntax_error =
     ["syntax: ghc-cabal configure <configure-args> -- <distdir> <directory>...",
      "        ghc-cabal install <ghc-pkg> <directory> <distdir> <destdir> <prefix> <args>...",
-     "        ghc-cabal haddock <distdir> <directory> <args>..."]
+     "        ghc-cabal hscolour <distdir> <directory> <args>..."]
 
 die :: [String] -> IO a
 die errs = do mapM_ (hPutStrLn stderr) errs
@@ -111,38 +111,16 @@ doCheck directory
     where isFailure (PackageDistSuspicious {}) = False
           isFailure _ = True
 
-runHaddock :: FilePath -> FilePath -> [String] -> IO ()
-runHaddock distdir directory args
+runHsColour :: FilePath -> FilePath -> [String] -> IO ()
+runHsColour distdir directory args
  = withCurrentDirectory directory
- $ defaultMainWithHooksArgs hooks ("haddock" : "--builddir" : distdir : args)
-    where
-      hooks = userHooks {
-                  haddockHook = modHook (haddockHook userHooks)
-              }
-      modHook f pd lbi us flags
-       | packageName pd == PackageName "ghc-prim"
-          = let pd' = case library pd of
-                      Just lib ->
-                          let ghcPrim = fromJust (simpleParse "GHC.Prim")
-                              ems = filter (ghcPrim /=)
-                                           (exposedModules lib)
-                              lib' = lib { exposedModules = ems }
-                          in pd { library = Just lib' }
-                      Nothing ->
-                          error "Expected a library, but none found"
-                pc = withPrograms lbi
-                pc' = userSpecifyArgs "haddock"
-                          ["dist-install/build/autogen/GHC/Prim.hs"] pc
-                lbi' = lbi { withPrograms = pc' }
-            in f pd' lbi' us flags
-       | otherwise
-          = f pd lbi us flags
+ $ defaultMainArgs ("hscolour" : "--builddir" : distdir : args)
 
 doInstall :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath
-          -> FilePath -> FilePath -> FilePath -> FilePath -> String
-          -> [String]
+          -> FilePath -> FilePath -> FilePath -> FilePath -> FilePath
+          -> String -> [String]
           -> IO ()
-doInstall ghc ghcpkg topdir directory distDir
+doInstall ghc ghcpkg strip topdir directory distDir
           myDestDir myPrefix myLibdir myDocdir
           relocatableBuildStr args
  = withCurrentDirectory directory $ do
@@ -198,30 +176,41 @@ doInstall ghc ghcpkg topdir directory distDir
                             libsubdir = toPathTemplate "$pkgid",
                             docdir    = toPathTemplate $
                                             if relocatableBuild
-                                            then "$topdir/$pkg"
-                                            else (myDocdir </> "$pkg"),
+                                            then "$topdir/../doc/html/libraries/$pkgid"
+                                            else (myDocdir </> "$pkgid"),
                             htmldir   = toPathTemplate "$docdir"
                         }
                 progs = withPrograms lbi
                 ghcProg = ConfiguredProgram {
                               programId = programName ghcProgram,
                               programVersion = Nothing,
-                              programArgs = ["-B" ++ topdir],
+                              programDefaultArgs = ["-B" ++ topdir],
+                              programOverrideArgs = [],
                               programLocation = UserSpecified ghc
                           }
                 ghcpkgconf = topdir </> "package.conf.d"
                 ghcPkgProg = ConfiguredProgram {
                                  programId = programName ghcPkgProgram,
                                  programVersion = Nothing,
-                                 programArgs = ["--global-conf",
-                                                ghcpkgconf]
+                                 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 progs
+                       $ updateProgram ghcPkgProg
+                       $ updateProgram stripProg
+                         progs
             instInfos <- dump verbosity ghcPkgProg GlobalPackageDB
             let installedPkgs' = PackageIndex.fromList instInfos
             let mlc = libraryConfig lbi
@@ -302,7 +291,10 @@ generate config_args distdir directory
               let ipid = InstalledPackageId (display (packageId pd) ++ "-inplace")
               let installedPkgInfo = inplaceInstalledPackageInfo cwd distdir
                                          pd lib lbi clbi
-                  final_ipi = installedPkgInfo{ Installed.installedPackageId = ipid }
+                  final_ipi = installedPkgInfo {
+                                  Installed.installedPackageId = ipid,
+                                  Installed.haddockHTMLs = ["../" ++ display (packageId pd)]
+                              }
                   content = Installed.showInstalledPackageInfo final_ipi ++ "\n"
               writeFileAtomic (distdir </> "inplace-pkg-config") content
           _ -> error "Inconsistent lib components; can't happen?"
@@ -336,7 +328,16 @@ generate config_args distdir directory
           -- GHC's rts package:
           hackRtsPackage index =
             case PackageIndex.lookupPackageName index (PackageName "rts") of
-              [(_,[rts])] -> PackageIndex.insert rts{ Installed.ldOptions = [] } index
+              [(_,[rts])] ->
+                 PackageIndex.insert rts{
+                     Installed.ldOptions = [],
+                     Installed.libraryDirs = filter (not . ("gcc-lib" `isSuffixOf`)) (Installed.libraryDirs rts)} index
+                        -- GHC <= 6.12 had $topdir/gcc-lib in their
+                        -- library-dirs for the rts package, which causes
+                        -- problems when we try to use the in-tree mingw,
+                        -- due to accidentally picking up the incompatible
+                        -- libraries there.  So we filter out gcc-lib from
+                        -- the RTS's library-dirs here.
               _ -> error "No (or multiple) ghc rts package is registered!!"
 
           dep_ids = map snd (externalPackageDeps lbi)
@@ -344,6 +345,8 @@ generate config_args distdir directory
       let variablePrefix = directory ++ '_':distdir
       let xs = [variablePrefix ++ "_VERSION = " ++ display (pkgVersion (package pd)),
                 variablePrefix ++ "_MODULES = " ++ unwords (map display modules),
+                variablePrefix ++ "_HIDDEN_MODULES = " ++ unwords (map display (otherModules bi)),
+                variablePrefix ++ "_SYNOPSIS =" ++ synopsis pd,
                 variablePrefix ++ "_HS_SRC_DIRS = " ++ unwords (hsSourceDirs bi),
                 variablePrefix ++ "_DEPS = " ++ unwords (map display dep_ids),
                 variablePrefix ++ "_DEP_NAMES = " ++ unwords (map (display . packageName) dep_ids),
@@ -354,12 +357,14 @@ generate config_args distdir directory
                 variablePrefix ++ "_EXTRA_LIBDIRS = " ++ unwords (extraLibDirs bi),
                 variablePrefix ++ "_C_SRCS  = " ++ unwords (cSources bi),
                 variablePrefix ++ "_CMM_SRCS  = $(addprefix cbits/,$(notdir $(wildcard " ++ directory ++ "/cbits/*.cmm)))",
+                variablePrefix ++ "_DATA_FILES = "    ++ unwords (dataFiles pd),
                 -- XXX This includes things it shouldn't, like:
                 -- -odir dist-bootstrapping/build
-                variablePrefix ++ "_HC_OPTS = " ++ escape (unwords 
-                        (programArgs ghcProg
+                variablePrefix ++ "_HC_OPTS = " ++ escape (unwords
+                       (   programDefaultArgs ghcProg
                         ++ hcOptions GHC bi
-                        ++ extensionsToFlags (compiler lbi) (extensions bi))),
+                        ++ extensionsToFlags (compiler lbi) (extensions bi)
+                        ++ programOverrideArgs ghcProg)),
                 variablePrefix ++ "_CC_OPTS = " ++ unwords (ccOptions bi),
                 variablePrefix ++ "_CPP_OPTS = " ++ unwords (cppOptions bi),
                 variablePrefix ++ "_LD_OPTS = " ++ unwords (ldOptions bi),
@@ -369,6 +374,9 @@ generate config_args distdir directory
                 variablePrefix ++ "_DEP_EXTRA_LIBS = " ++ unwords (forDeps Installed.extraLibraries),
                 variablePrefix ++ "_DEP_LD_OPTS = "    ++ unwords (forDeps Installed.ldOptions)]
       writeFile (distdir ++ "/package-data.mk") $ unlines xs
+      writeFile (distdir ++ "/haddock-prologue.txt") $ 
+          if null (description pd) then synopsis pd
+                                   else description pd
   where
      escape = foldr (\c xs -> if c == '#' then '\\':'#':xs else c:xs) []
      wrap = map (\s -> "\'" ++ s ++ "\'")