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