[project @ 2000-07-08 23:06:46 by panne]
[ghc-hetmet.git] / ghc / driver / Package.hs
1 module Package where
2
3 import Pretty
4
5 data Package = Package {
6                 import_dirs    :: [String],
7                 library_dirs   :: [String],
8                 libraries      :: [String],
9                 include_dirs   :: [String],
10                 c_includes     :: [String],
11                 package_deps   :: [String],
12                 extra_ghc_opts :: [String],
13                 extra_cc_opts  :: [String],
14                 extra_ld_opts  :: [String]
15                 }
16   deriving (Read, Show)
17
18 listPkgs :: [(String,Package)] -> String
19 listPkgs pkgs = render (fsep (punctuate comma (map (text . fst) pkgs)))
20
21 dumpPackages :: [(String,Package)] -> String
22 dumpPackages pkgs = 
23    render (brackets (vcat (punctuate comma (map dumpPkg pkgs))))
24
25 dumpPkg :: (String,Package) -> Doc
26 dumpPkg (name, pkg) =
27    parens (hang (text (show name) <> comma) 2 (dumpPkgGuts pkg))
28
29 dumpPkgGuts :: Package -> Doc
30 dumpPkgGuts pkg =
31    text "Package" $$ nest 3 (braces (
32       sep (punctuate comma [
33          dumpField "import_dirs"    (import_dirs    pkg),
34          dumpField "library_dirs"   (library_dirs   pkg),
35          dumpField "libraries"      (libraries      pkg),
36          dumpField "include_dirs"   (include_dirs   pkg),
37          dumpField "c_includes"     (c_includes     pkg),
38          dumpField "package_deps"   (package_deps   pkg),
39          dumpField "extra_ghc_opts" (extra_ghc_opts pkg),
40          dumpField "extra_cc_opts"  (extra_cc_opts  pkg),
41          dumpField "extra_ld_opts"  (extra_ld_opts  pkg)
42       ])))
43
44 dumpField :: String -> [String] -> Doc
45 dumpField name val =
46    hang (text name <+> equals) 2
47         (brackets (sep (punctuate comma (map (text . show) val))))