{-# OPTIONS_GHC -fglasgow-exts #-} -- -- Haddock - A Haskell Documentation Tool -- -- (c) Simon Marlow 2003 -- module Main (main) where import HaddockHtml import HaddockHoogle import HaddockRename import HaddockTypes import HaddockUtil import HaddockVersion import Paths_haddock ( getDataDir ) import Binary2 import Control.Exception ( bracket, throwIO, catch, Exception(..) ) import Prelude hiding ( catch ) import Control.Monad ( when, liftM ) import Control.Monad.Writer ( Writer, runWriter, tell ) import Data.Char ( isSpace ) import Data.IORef ( writeIORef ) import Data.List ( nub, (\\), foldl', sortBy, foldl1 ) import Data.Maybe ( isJust, isNothing, maybeToList, listToMaybe ) --import Debug.Trace import System.Console.GetOpt ( getOpt, usageInfo, ArgOrder(..), OptDescr(..), ArgDescr(..) ) import System.Environment ( getArgs ) import System.IO ( stderr, IOMode(..), openFile, hClose, hGetContents, hPutStrLn ) import System.Directory ( doesFileExist, doesDirectoryExist ) #if defined(mingw32_HOST_OS) import Foreign import Foreign.C #endif import qualified Data.Map as Map import Data.Map (Map) import Data.Maybe import Data.List ( nubBy ) import Data.FunctorM ( fmapM ) import GHC import Outputable import SrcLoc import qualified Digraph as Digraph import Name import Module ( moduleString, mkModule ) import InstEnv import Class import TypeRep import Var hiding ( varName ) import TyCon import PrelNames import FastString #define FSLIT(x) (mkFastString# (x#)) import DynFlags hiding ( Option ) import Unique ( mkUnique ) import Packages ----------------------------------------------------------------------------- -- Top-level stuff type CheckedMods = [(Module, FullyCheckedMod, FilePath)] main :: IO () main = do args <- getArgs (libDir, rest) <- getLibDir args (session, ghcFlags, nonGHCOpts) <- startGHC libDir rest (flags, args) <- parseHaddockOpts nonGHCOpts handleEagerFlags flags modules <- sortAndCheckModules session ghcFlags args (ifaces, htmls) <- getIfacesAndHtmls flags ghcFlags let (modss, envs) = unzip ifaces updateHTMLXRefs htmls modss -- TODO: continue to break up the run function into parts run flags modules envs parseHaddockOpts :: [String] -> IO ([Flag], [String]) parseHaddockOpts words = case getOpt Permute (options True) words of (flags, args, []) -> return (flags, args) (_, _, errors) -> do prog <- getProgramName die (concat errors ++ usageInfo (usageHeader prog) (options False)) usageHeader :: String -> String usageHeader prog = "Usage: " ++ prog ++ " [OPTION...] file...\n" getLibDir :: [String] -> IO (String, [String]) getLibDir ("-B":dir:rest) = return (dir, rest) getLibDir (('-':'B':dir):rest) | not (null dir) = return (dir, rest) getLibDir _ = die "Missing GHC lib dir option: -B