f37f912934959e522178483f427946267c8b3b43
[ghc-hetmet.git] / ghc / driver / PackageSrc.hs
1 #include "../includes/config.h"
2 #include "../includes/Derived.h"
3
4 module Main (main) where
5
6 import Utils
7
8 import IO
9 import System
10 import Package
11
12 main :: IO ()
13 main = do
14   args <- getArgs
15   case args of
16      ("install":rest)  -> do { putStrLn (dumpPackages (package_details True rest)) }
17      ("in-place":rest) -> do { putStrLn (dumpPackages (package_details False rest)) }
18      _ -> do hPutStr stderr "usage: pkgconf (install | in-place) ...\n"
19              exitWith (ExitFailure 1)
20
21 -- The compiler automatically replaces the string "$libdir" at the
22 -- beginning of a path with the directory passed to the compiler via
23 -- the -B<dir> flag.  Absolute path names will be unchanged.
24 --
25 -- This is how we make package.conf independent of GHC's installation
26 -- location.
27
28 package_details :: Bool -> [String] -> [PackageConfig]
29 package_details installing
30  [ cTARGETPLATFORM
31  , cCURRENT_DIR
32  , cHaveLibGmp
33  , cLibsReadline
34  , cGHC_LIB_DIR
35  , cGHC_RUNTIME_DIR
36  , cGHC_UTILS_DIR
37  , cGHC_INCLUDE_DIR
38  ] =
39
40  [
41         Package {
42         name           = "gmp",  -- GMP is at the bottom of the heap
43         import_dirs    = [],
44         source_dirs    = [],
45         library_dirs   = if cHaveLibGmp == "YES"
46                             then []
47                             else if installing
48                                     then [ "$libdir" ]
49                                     else [ ghc_src_dir cGHC_RUNTIME_DIR ++ "/gmp" ],
50         hs_libraries   = [],
51         extra_libraries = [ "gmp" ],
52         include_dirs   = [],
53         c_includes     = [],
54         package_deps   = [],
55         extra_ghc_opts = [],
56         extra_cc_opts  = [],
57         extra_ld_opts  = []
58         },
59
60         Package {
61         name           = "rts",  -- The RTS is just another package!
62         import_dirs    = [],
63         source_dirs    = [],
64         library_dirs   = if installing
65                             then [ "$libdir" ]
66                             else [ ghc_src_dir cGHC_RUNTIME_DIR ],
67         hs_libraries      = [ "HSrts" ],
68         extra_libraries   =
69                               "m":              -- for ldexp()
70 #ifdef mingw32_TARGET_OS
71                               "winmm":          -- for the threadDelay timer
72                               "wsock32":        -- for the linker
73 #endif
74 #ifdef USING_LIBBFD
75                               "bfd": "iberty":  -- for debugging
76 #endif
77                             [],
78         include_dirs   = if installing
79                             then [ "$libdir/include"
80 #ifdef mingw32_TARGET_OS
81                                  , "$libdir/include/mingw"
82 #endif
83                                  ]
84                             else [ ghc_src_dir cGHC_INCLUDE_DIR ],
85         c_includes     = [ "Stg.h" ],           -- ha!
86         package_deps   = [ "gmp" ],
87         extra_ghc_opts = [],
88         extra_cc_opts  = [],
89                 -- the RTS forward-references to a bunch of stuff in the prelude,
90                 -- so we force it to be included with special options to ld.
91         extra_ld_opts  =
92            foldr (\ x xs -> "-u" : x : xs) []
93                  (map (
94 #ifndef LEADING_UNDERSCORE
95                           ""
96 #else
97                           "_"
98 #endif
99                           ++ ) [
100            "PrelBase_Izh_static_info"
101          , "PrelBase_Czh_static_info"
102          , "PrelFloat_Fzh_static_info"
103          , "PrelFloat_Dzh_static_info"
104          , "PrelPtr_Ptr_static_info"
105          , "PrelWord_Wzh_static_info"
106          , "PrelInt_I8zh_static_info"
107          , "PrelInt_I16zh_static_info"
108          , "PrelInt_I32zh_static_info"
109          , "PrelInt_I64zh_static_info"
110          , "PrelWord_W8zh_static_info"
111          , "PrelWord_W16zh_static_info"
112          , "PrelWord_W32zh_static_info"
113          , "PrelWord_W64zh_static_info"
114          , "PrelStable_StablePtr_static_info"
115          , "PrelBase_Izh_con_info"
116          , "PrelBase_Czh_con_info"
117          , "PrelFloat_Fzh_con_info"
118          , "PrelFloat_Dzh_con_info"
119          , "PrelPtr_Ptr_con_info"
120          , "PrelStable_StablePtr_con_info"
121          , "PrelBase_False_closure"
122          , "PrelBase_True_closure"
123          , "PrelPack_unpackCString_closure"
124          , "PrelIOBase_stackOverflow_closure"
125          , "PrelIOBase_heapOverflow_closure"
126          , "PrelIOBase_NonTermination_closure"
127          , "PrelIOBase_BlockedOnDeadMVar_closure"
128          , "PrelWeak_runFinalizzerBatch_closure"
129          , "__init_Prelude"
130          ])
131         },
132
133         Package {
134         name           = "std",  -- The Prelude & Standard Hs_libraries
135         import_dirs    = if installing
136                             then [ "$libdir/imports/std" ]
137                             else [ ghc_src_dir cGHC_LIB_DIR ++ "/std" ],
138         source_dirs    = [],
139         library_dirs   = if installing
140                             then [ "$libdir" ]
141                             else [ ghc_src_dir cGHC_LIB_DIR ++ "/std"
142                                  , ghc_src_dir cGHC_LIB_DIR ++ "/std/cbits" ],
143
144         hs_libraries      = 
145 #                           ifndef mingw32_TARGET_OS
146                             [ "HSstd" ]
147 #                           else
148                             -- This splitting is the subject of a totally 
149                             -- horrible hack, which glues HSstd1 and HSstd2 
150                             -- back into HSstd for the purposes of static linking.
151                             -- See DriverState.getPackageLibraries for details.
152                             [ "HSstd1", "HSstd2" ]
153 #                           endif
154                             ,
155         extra_libraries   = [ "HSstd_cbits" ] ++
156 #                           ifdef mingw32_TARGET_OS
157                             [ "wsock32", "msvcrt" ]
158 #                           else
159                             [ ]
160 #                           endif
161                             ,
162         include_dirs   = if installing
163                             then []
164                             else [ ghc_src_dir cGHC_LIB_DIR ++ "/std/cbits" ],
165         c_includes     = [ "HsStd.h" ],
166         package_deps   = [ "rts" ],
167         extra_ghc_opts = [],
168         extra_cc_opts  = [],
169         extra_ld_opts  = []
170         },
171
172          Package { 
173          name           = "lang",
174          import_dirs    = if installing
175                              then [ "$libdir/imports/lang" ]
176                              else [ "$libdir/hslibs/lang"
177                                   , "$libdir/hslibs/lang/monads" ],
178          source_dirs    = [],
179          library_dirs   = if installing
180                              then [ "$libdir" ]
181                              else [ "$libdir/hslibs/lang"
182                                   , "$libdir/hslibs/lang/cbits" ],
183          hs_libraries      = [ "HSlang" ],
184          extra_libraries   = [ "HSlang_cbits" ],
185          include_dirs   = if installing
186                              then []
187                              else [ "$libdir/hslibs/lang/cbits" ],
188          c_includes     = [ "HsLang.h" ],
189          package_deps   = [],
190          extra_ghc_opts = [],
191          extra_cc_opts  = [],
192          extra_ld_opts  = [
193 #ifndef LEADING_UNDERSCORE
194                           "-u", "Addr_Azh_static_info"
195 #else
196                           "-u", "_Addr_Azh_static_info"
197 #endif
198                         ]
199         },
200
201          Package {
202          name           = "concurrent",
203          import_dirs    = if installing
204                              then [ "$libdir/imports/concurrent" ]
205                              else [ "$libdir/hslibs/concurrent" ],
206          source_dirs    = [],
207          library_dirs   = if installing
208                              then [ "$libdir" ]
209                              else [ "$libdir/hslibs/concurrent" ],
210          hs_libraries      = [ "HSconcurrent" ],
211          extra_libraries   = [],
212          include_dirs   = if installing
213                              then []
214                              else [ "$libdir/hslibs/concurrent/cbits" ],
215          c_includes     = [],
216          package_deps   = [ "lang" ],
217          extra_ghc_opts = [],
218          extra_cc_opts  = [],
219          extra_ld_opts  = []
220         },
221
222          Package {
223          name           = "data",
224          import_dirs    = if installing
225                              then [ "$libdir/imports/data" ]
226                              else [ "$libdir/hslibs/data"
227                                   , "$libdir/hslibs/data/edison"
228                                   , "$libdir/hslibs/data/edison/Assoc"
229                                   , "$libdir/hslibs/data/edison/Coll"
230                                   , "$libdir/hslibs/data/edison/Seq" ],
231          source_dirs    = [],
232          library_dirs   = if installing
233                              then [ "$libdir" ]
234                              else [ "$libdir/hslibs/data" ],
235          hs_libraries      = [ "HSdata" ],
236          extra_libraries   = [],
237          include_dirs   = if installing
238                              then []
239                              else [ "$libdir/hslibs/data/cbits" ],
240          c_includes     = [],
241          package_deps   = [ "lang", "util" ],
242          extra_ghc_opts = [],
243          extra_cc_opts  = [],
244          extra_ld_opts  = []
245         },
246
247          Package {
248          name           = "net",
249          import_dirs    = if installing
250                              then [ "$libdir/imports/net" ]
251                              else [ "$libdir/hslibs/net" ],
252          source_dirs    = [],
253          library_dirs   = if installing
254                              then [ "$libdir" ]
255                              else [ "$libdir/hslibs/net"
256                                   , "$libdir/hslibs/net/cbits" ],
257          hs_libraries      = [ "HSnet" ],
258          extra_libraries   = if suffixMatch "solaris2" cTARGETPLATFORM
259                                 then [ "nsl",  "socket" ]
260                                 else []
261                              ,
262          include_dirs   = if installing
263                              then []
264                              else [ "$libdir/hslibs/net/cbits" ],
265          c_includes     = [ "HsNet.h" ],
266          package_deps   = [ "lang", "text", "concurrent" ],
267          extra_ghc_opts = [],
268          extra_cc_opts  = [],
269          extra_ld_opts  = []
270         },
271
272          Package {
273          name           = "posix",
274          import_dirs    = if installing
275                              then [ "$libdir/imports/posix" ]
276                              else [ "$libdir/hslibs/posix" ],
277          source_dirs    = [],
278          library_dirs   = if installing
279                              then [ "$libdir" ]
280                              else [ "$libdir/hslibs/posix"
281                                   , "$libdir/hslibs/posix/cbits" ],
282          hs_libraries      = [ "HSposix" ],
283          extra_libraries   = [ "HSposix_cbits" ],
284          include_dirs   = if installing
285                              then []
286                              else [ "$libdir/hslibs/posix/cbits" ],
287          c_includes     = [ "HsPosix.h" ],
288          package_deps   = [ "lang" ],
289          extra_ghc_opts = [],
290          extra_cc_opts  = [],
291          extra_ld_opts  = []
292         },
293
294          Package {
295          name           = "text",
296          import_dirs    = if installing
297                              then [ "$libdir/imports/text" ]
298                              else [ "$libdir/hslibs/text" 
299                                   , "$libdir/hslibs/text/html" 
300                                   , "$libdir/hslibs/text/HaXml/lib" 
301                                   , "$libdir/hslibs/text/parsec" ],
302          source_dirs    = [],
303          library_dirs   = if installing
304                              then [ "$libdir" ]
305                              else [ "$libdir/hslibs/text"
306                                   , "$libdir/hslibs/text/cbits" ],
307          hs_libraries      = [ "HStext" ],
308          extra_libraries   = [ "HStext_cbits" ],
309          include_dirs   = if installing
310                              then []
311                              else [ "$libdir/hslibs/text/cbits" ],
312          c_includes     = [ "HsText.h" ],
313          package_deps   = [ "lang" ],
314          extra_ghc_opts = [],
315          extra_cc_opts  = [],
316          extra_ld_opts  = []
317         },
318
319          Package {
320          name           = "util",
321          import_dirs    = if installing
322                              then [ "$libdir/imports/util" ]
323                              else [ "$libdir/hslibs/util"
324                                   , "$libdir/hslibs/util/check" ],
325          source_dirs    = [],
326          library_dirs   = if installing
327                              then [ "$libdir" ]
328                              else [ "$libdir/hslibs/util"
329                                   , "$libdir/hslibs/util/cbits" ],
330          hs_libraries      = [ "HSutil" ],
331          extra_libraries   = [ "HSutil_cbits" ] 
332 #ifndef mingw32_TARGET_OS
333                              ++ words cLibsReadline
334 #endif
335                              ,
336          include_dirs   = if installing
337                              then []
338                              else [ "$libdir/hslibs/util/cbits" ],
339          c_includes     = [ "HsUtil.h" ],
340          package_deps   = [ "lang", "concurrent"
341 #ifndef mingw32_TARGET_OS
342                             , "posix"
343 #endif
344                           ],
345          extra_ghc_opts = [],
346          extra_cc_opts  = [],
347          extra_ld_opts  = []
348         },
349
350         -- no cbits at the moment, we'll need to add one if this library
351         -- ever calls out to any C libs.
352          Package {
353          name           = "hssource",
354          import_dirs    = if installing
355                              then [ "$libdir/imports/hssource" ]
356                              else [ "$libdir/hslibs/hssource" ],
357          source_dirs    = [],
358          library_dirs   = if installing
359                              then [ "$libdir" ]
360                              else [ "$libdir/hslibs/hssource" ],
361          hs_libraries      = [ "HShssource" ],
362          extra_libraries   = [],
363          include_dirs   = [],
364          c_includes     = [],
365          package_deps   = [ "text" ],
366          extra_ghc_opts = [],
367          extra_cc_opts  = [],
368          extra_ld_opts  = []
369         },
370
371          Package {
372          name         = "greencard",
373          import_dirs    = if installing
374                              then [ "$libdir/imports/greencard" ]
375                              else [ "$libdir/green-card/lib/ghc" ],
376          source_dirs    = [],
377          library_dirs   = if installing
378                              then [ "$libdir" ]
379                              else [ "$libdir/green-card/lib/ghc" ],
380          hs_libraries      = [ "HSgreencard" ],
381          extra_libraries   = [],
382          include_dirs   = [],
383          c_includes     = [],
384          package_deps   = [ "lang" ],
385          extra_ghc_opts = [],
386          extra_cc_opts  = [],
387          extra_ld_opts  = [],
388         }
389
390 #if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
391          ,Package {
392          name         = "win32",
393          import_dirs    = if installing
394                              then [ "$libdir/imports/win32" ]
395                              else [ "$libdir/hslibs/win32" ],
396          source_dirs    = [],
397          library_dirs   = if installing
398                              then [ "$libdir" ]
399                              else [ "$libdir/hslibs/win32" ],
400          hs_libraries      = [ "HSwin321", "HSwin322" ],
401          extra_libraries   = [ "user32",  "gdi32", "winmm", 
402                                "kernel32", "advapi32" ],
403          include_dirs   = [],
404          c_includes     = [],           -- ???
405          package_deps   = [ "lang" ], -- greencard now built in
406          extra_ghc_opts = [],
407          extra_cc_opts  = [],
408          extra_ld_opts  = []
409         },
410
411          Package {
412          name           = "com",
413          import_dirs    = if installing
414                              then [ "$libdir/imports/com" ]
415                              else [ "$libdir/hdirect/lib" ],
416          source_dirs    = [],
417          library_dirs   = if installing
418                              then [ "$libdir" ]
419                              else [ "$libdir/hdirect/lib" ],
420          hs_libraries      = [ "HScom" ],
421          extra_libraries   = [ "user32",  "ole32",  "oleaut32", "advapi32" ],
422          include_dirs   = [],
423          c_includes     = [],           -- ???
424          package_deps   = [ "lang" ],
425          extra_ghc_opts = [],
426          extra_cc_opts  = [],
427          extra_ld_opts  = []
428         }
429 #endif
430
431          ,Package {
432          name           = "xlib",
433          import_dirs    = if installing
434                              then [ "$libdir/imports/xlib" ]
435                              else [ "$libdir/hslibs/xlib" ],
436          source_dirs    = [],
437          library_dirs   = if installing
438                              then [ "$libdir" ]
439                              else [ "$libdir/hslibs/xlib"
440                                   , "$libdir/hslibs/xlib/cbits" ],
441          hs_libraries      = [ "HSxlib" ],
442          extra_libraries   = [ "HSxlib_cbits", "X11" ],
443          include_dirs   = if installing
444                              then []
445                              else [ "$libdir/hslibs/xlib/cbits" ],
446          c_includes     = [ "HsXlib.h" ],
447          package_deps   = [ "greencard" ],
448          extra_ghc_opts = [],
449          extra_cc_opts  = [],
450          extra_ld_opts  = []
451         }
452
453          ,Package {
454          name           = "HGL",
455          import_dirs    = if installing
456                              then [ "$libdir/imports/HGL" ]
457                              else [ "$libdir/hslibs/graphics/lib/x11" ],
458          source_dirs    = [],
459          library_dirs   = [],
460          hs_libraries   = [ "HSHGL" ],
461          extra_libraries= [],
462          include_dirs   = [],
463          c_includes     = [],
464          package_deps   = [ "xlib", "concurrent" ],
465          extra_ghc_opts = [],
466          extra_cc_opts  = [],
467          extra_ld_opts  = []
468         }
469
470    ]
471   where
472         ghc_src_dir :: String -> String
473         ghc_src_dir path = "$libdir/" ++ cCURRENT_DIR ++ '/':path