[project @ 2001-06-15 08:29:57 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / Packages.lhs
1 %
2 % (c) The University of Glasgow, 2000
3 %
4 \section{Package manipulation}
5
6 \begin{code}
7 module Packages ( PackageConfig(..), 
8                   defaultPackageConfig,
9                   mungePackagePaths,
10                   showPackages
11                 )
12 where
13
14 #include "HsVersions.h"
15 import Pretty
16
17 import SysTools         ( dosifyPath )
18 import CmdLineOpts      ( dynFlag, verbosity )
19 import DriverUtil       ( my_prefix_match )
20 import ErrUtils         ( dumpIfSet )
21 import Outputable       ( docToSDoc, trace )
22 \end{code}
23
24 \begin{code}
25 #define WANT_PRETTY
26 -- Yes, do generate pretty-printing stuff for packages
27
28 -- There's a blob of code shared with ghc-pkg, 
29 -- so we just include it from there 
30 #include "../utils/ghc-pkg/Package.hs"
31 \end{code}
32
33 %*********************************************************
34 %*                                                       *
35 \subsection{Load the config file}
36 %*                                                       *
37 %*********************************************************
38
39 \begin{code}
40 mungePackagePaths :: String -> [PackageConfig] -> [PackageConfig]
41 -- a) replace the string "$libdir" at the beginning of a path with the
42 --    current libdir (obtained from the -B option).
43 -- b) dosify the paths [paths in the package-conf file aren't DOS style]
44 mungePackagePaths top_dir ps = map munge_pkg ps
45  where 
46   munge_pkg p = p{ import_dirs  = munge_paths (import_dirs p),
47                    include_dirs = munge_paths (include_dirs p),
48                    library_dirs = munge_paths (library_dirs p) }
49
50   munge_paths = map munge_path
51
52   munge_path p 
53           | Just p' <- my_prefix_match "$libdir" p = dosifyPath (top_dir ++ p')
54           | otherwise                              = trace ("not: " ++ p) p
55 \end{code}
56
57
58 %*********************************************************
59 %*                                                       *
60 \subsection{Display results}
61 %*                                                       *
62 %*********************************************************
63
64 \begin{code}
65 showPackages :: [PackageConfig] -> IO ()
66 -- Show package info on console, if verbosity is >=2
67 showPackages ps
68   = do  { verb <- dynFlag verbosity
69         ; dumpIfSet (verb >= 2) "Packages"
70                     (docToSDoc (vcat (map dumpPkgGuts ps)))
71         }
72 \end{code}