43b96ec1001e399fec09111f04081d03bb0a5cff
[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 CmdLineOpts      ( dynFlag, verbosity )
18 import DriverUtil       ( my_prefix_match )
19 import ErrUtils         ( dumpIfSet )
20 import Outputable       ( docToSDoc )
21 \end{code}
22
23 \begin{code}
24 #define WANT_PRETTY
25 -- Yes, do generate pretty-printing stuff for packages
26
27 -- There's a blob of code shared with ghc-pkg, 
28 -- so we just include it from there 
29 #include "../utils/ghc-pkg/Package.hs"
30 \end{code}
31
32 %*********************************************************
33 %*                                                       *
34 \subsection{Load the config file}
35 %*                                                       *
36 %*********************************************************
37
38 \begin{code}
39 mungePackagePaths :: String -> [PackageConfig] -> [PackageConfig]
40 -- Replace the string "$libdir" at the beginning of a path
41 -- with the current libdir (obtained from the -B option).
42 mungePackagePaths top_dir ps = map munge_pkg ps
43  where 
44   munge_pkg p = p{ import_dirs  = munge_paths (import_dirs p),
45                    include_dirs = munge_paths (include_dirs p),
46                    library_dirs = munge_paths (library_dirs p),
47                    framework_dirs = munge_paths (framework_dirs p) }
48
49   munge_paths = map munge_path
50
51   munge_path p 
52           | Just p' <- my_prefix_match "$libdir" p = top_dir ++ p'
53           | otherwise                              = p
54 \end{code}
55
56
57 %*********************************************************
58 %*                                                       *
59 \subsection{Display results}
60 %*                                                       *
61 %*********************************************************
62
63 \begin{code}
64 showPackages :: [PackageConfig] -> IO ()
65 -- Show package info on console, if verbosity is >= 3
66 showPackages ps
67   = do  { verb <- dynFlag verbosity
68         ; dumpIfSet (verb >= 3) "Packages"
69                     (docToSDoc (vcat (map dumpPkgGuts ps)))
70         }
71 \end{code}