[project @ 2000-07-24 15:16:44 by simonmar]
[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                 hs_libraries    :: [String],
9                 extra_libraries :: [String],
10                 include_dirs    :: [String],
11                 c_includes      :: [String],
12                 package_deps    :: [String],
13                 extra_ghc_opts  :: [String],
14                 extra_cc_opts   :: [String],
15                 extra_ld_opts   :: [String]
16                 }
17   deriving (Read, Show)
18
19 listPkgs :: [(String,Package)] -> String
20 listPkgs pkgs = render (fsep (punctuate comma (map (text . fst) pkgs)))
21
22 dumpPackages :: [(String,Package)] -> String
23 dumpPackages pkgs = 
24    render (brackets (vcat (punctuate comma (map dumpPkg pkgs))))
25
26 dumpPkg :: (String,Package) -> Doc
27 dumpPkg (name, pkg) =
28    parens (hang (text (show name) <> comma) 2 (dumpPkgGuts pkg))
29
30 dumpPkgGuts :: Package -> Doc
31 dumpPkgGuts pkg =
32    text "Package" $$ nest 3 (braces (
33       sep (punctuate comma [
34          dumpField "import_dirs"     (import_dirs     pkg),
35          dumpField "library_dirs"    (library_dirs    pkg),
36          dumpField "hs_libraries"    (hs_libraries    pkg),
37          dumpField "extra_libraries" (extra_libraries pkg),
38          dumpField "include_dirs"    (include_dirs    pkg),
39          dumpField "c_includes"      (c_includes      pkg),
40          dumpField "package_deps"    (package_deps    pkg),
41          dumpField "extra_ghc_opts"  (extra_ghc_opts  pkg),
42          dumpField "extra_cc_opts"   (extra_cc_opts   pkg),
43          dumpField "extra_ld_opts"   (extra_ld_opts   pkg)
44       ])))
45
46 dumpField :: String -> [String] -> Doc
47 dumpField name val =
48    hang (text name <+> equals) 2
49         (brackets (sep (punctuate comma (map (text . show) val))))