543a48765518477f804965294052183e7dd5e39f
[ghc-hetmet.git] / ghc / compiler / main / DriverState.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverState.hs,v 1.104 2004/04/30 15:51:10 simonmar Exp $
3 --
4 -- Settings for the driver
5 --
6 -- (c) The University of Glasgow 2002
7 --
8 -----------------------------------------------------------------------------
9
10 module DriverState where
11
12 #include "../includes/config.h"
13 #include "HsVersions.h"
14
15 import ParsePkgConf     ( loadPackageConfig )
16 import SysTools         ( getTopDir )
17 import Packages
18 import CmdLineOpts
19 import DriverPhases
20 import DriverUtil
21 import UniqFM           ( eltsUFM )
22 import Util
23 import Config
24 import Panic
25
26 import DATA_IOREF       ( IORef, readIORef, writeIORef )
27 import EXCEPTION
28
29 import List
30 import Char  
31 import Monad
32 import Maybe            ( fromJust, isJust )
33 import Directory        ( doesDirectoryExist )
34
35 -----------------------------------------------------------------------------
36 -- non-configured things
37
38 cHaskell1Version = "5" -- i.e., Haskell 98
39
40 -----------------------------------------------------------------------------
41 -- GHC modes of operation
42
43 data GhcMode
44   = DoMkDependHS                        -- ghc -M
45   | DoMkDLL                             -- ghc --mk-dll
46   | StopBefore Phase                    -- ghc -E | -C | -S | -c
47   | DoMake                              -- ghc --make
48   | DoInteractive                       -- ghc --interactive
49   | DoLink                              -- [ the default ]
50   | DoEval String                       -- ghc -e
51   deriving (Eq,Show)
52
53 GLOBAL_VAR(v_GhcMode,     DoLink, GhcMode)
54 GLOBAL_VAR(v_GhcModeFlag, "",     String)
55
56 setMode :: GhcMode -> String -> IO ()
57 setMode m flag = do
58   old_mode <- readIORef v_GhcMode
59   old_flag <- readIORef v_GhcModeFlag
60   when (notNull old_flag && flag /= old_flag) $
61       throwDyn (UsageError 
62           ("cannot use `" ++ old_flag ++ "' with `" ++ flag ++ "'"))
63   writeIORef v_GhcMode m
64   writeIORef v_GhcModeFlag flag
65
66 isCompManagerMode DoMake        = True
67 isCompManagerMode DoInteractive = True
68 isCompManagerMode (DoEval _)    = True
69 isCompManagerMode _             = False
70
71 -----------------------------------------------------------------------------
72 -- Global compilation flags
73
74 -- Cpp-related flags
75 v_Hs_source_cpp_opts = global
76         [ "-D__HASKELL1__="++cHaskell1Version
77         , "-D__GLASGOW_HASKELL__="++cProjectVersionInt                          
78         , "-D__HASKELL98__"
79         , "-D__CONCURRENT_HASKELL__"
80         ]
81 {-# NOINLINE v_Hs_source_cpp_opts #-}
82
83
84 -- Keep output from intermediate phases
85 GLOBAL_VAR(v_Keep_hi_diffs,             False,          Bool)
86 GLOBAL_VAR(v_Keep_hc_files,             False,          Bool)
87 GLOBAL_VAR(v_Keep_s_files,              False,          Bool)
88 GLOBAL_VAR(v_Keep_raw_s_files,          False,          Bool)
89 GLOBAL_VAR(v_Keep_tmp_files,            False,          Bool)
90 #ifdef ILX
91 GLOBAL_VAR(v_Keep_il_files,             False,          Bool)
92 GLOBAL_VAR(v_Keep_ilx_files,            False,          Bool)
93 #endif
94
95 -- Misc
96 GLOBAL_VAR(v_Scale_sizes_by,            1.0,            Double)
97 GLOBAL_VAR(v_Static,                    True,           Bool)
98 GLOBAL_VAR(v_NoLink,                    False,          Bool)
99 GLOBAL_VAR(v_NoHsMain,                  False,          Bool)
100 GLOBAL_VAR(v_MainModIs,                 Nothing,        Maybe String)
101 GLOBAL_VAR(v_MainFunIs,                 Nothing,        Maybe String)
102 GLOBAL_VAR(v_Recomp,                    True,           Bool)
103 GLOBAL_VAR(v_Collect_ghc_timing,        False,          Bool)
104 GLOBAL_VAR(v_Do_asm_mangling,           True,           Bool)
105 GLOBAL_VAR(v_Excess_precision,          False,          Bool)
106 GLOBAL_VAR(v_Read_DotGHCi,              True,           Bool)
107
108 -- Preprocessor flags
109 GLOBAL_VAR(v_Hs_source_pp_opts, [], [String])
110
111 -----------------------------------------------------------------------------
112 -- Splitting object files (for libraries)
113
114 GLOBAL_VAR(v_Split_object_files,        False,          Bool)
115 GLOBAL_VAR(v_Split_info,                ("",0),         (String,Int))
116         -- The split prefix and number of files
117
118         
119 can_split :: Bool
120 can_split =  prefixMatch "i386"    cTARGETPLATFORM
121           || prefixMatch "alpha"   cTARGETPLATFORM
122           || prefixMatch "hppa"    cTARGETPLATFORM
123           || prefixMatch "m68k"    cTARGETPLATFORM
124           || prefixMatch "mips"    cTARGETPLATFORM
125           || prefixMatch "powerpc" cTARGETPLATFORM
126           || prefixMatch "rs6000"  cTARGETPLATFORM
127           || prefixMatch "sparc"   cTARGETPLATFORM
128
129 -----------------------------------------------------------------------------
130 -- Compiler output options
131
132 GLOBAL_VAR(v_Output_dir,  Nothing, Maybe String)
133 GLOBAL_VAR(v_Output_file, Nothing, Maybe String)
134 GLOBAL_VAR(v_Output_hi,   Nothing, Maybe String)
135
136 -- called to verify that the output files & directories
137 -- point somewhere valid. 
138 --
139 -- The assumption is that the directory portion of these output
140 -- options will have to exist by the time 'verifyOutputFiles'
141 -- is invoked.
142 -- 
143 verifyOutputFiles :: IO ()
144 verifyOutputFiles = do
145   odir <- readIORef v_Output_dir
146   when (isJust odir) $ do
147      let dir = fromJust odir
148      flg <- doesDirectoryExist dir
149      when (not flg) (nonExistentDir "-odir" dir)
150   ofile <- readIORef v_Output_file
151   when (isJust ofile) $ do
152      let fn = fromJust ofile
153      flg <- doesDirNameExist fn
154      when (not flg) (nonExistentDir "-o" fn)
155   ohi <- readIORef v_Output_hi
156   when (isJust ohi) $ do
157      let hi = fromJust ohi
158      flg <- doesDirNameExist hi
159      when (not flg) (nonExistentDir "-ohi" hi)
160  where
161    nonExistentDir flg dir = 
162      throwDyn (CmdLineError ("error: directory portion of " ++ 
163                              show dir ++ " does not exist (used with " ++ 
164                              show flg ++ " option.)"))
165
166 GLOBAL_VAR(v_Object_suf,  phaseInputExt Ln, String)
167 GLOBAL_VAR(v_HC_suf,      Nothing, Maybe String)
168 GLOBAL_VAR(v_Hi_dir,      Nothing, Maybe String)
169 GLOBAL_VAR(v_Hi_suf,      "hi",    String)
170
171 GLOBAL_VAR(v_Ld_inputs, [],      [String])
172
173 odir_ify :: String -> IO String
174 odir_ify f = do
175   odir_opt <- readIORef v_Output_dir
176   case odir_opt of
177         Nothing -> return f
178         Just d  -> return (replaceFilenameDirectory f d)
179
180 osuf_ify :: String -> IO String
181 osuf_ify f = do
182   osuf <- readIORef v_Object_suf
183   return (replaceFilenameSuffix f osuf)
184
185 GLOBAL_VAR(v_StgStats,                  False, Bool)
186
187 buildStgToDo :: IO [ StgToDo ]
188 buildStgToDo = do
189   stg_stats <- readIORef v_StgStats
190   let flags1 | stg_stats = [ D_stg_stats ]
191              | otherwise = [ ]
192
193         -- STG passes
194   ways_ <- readIORef v_Ways
195   let flags2 | WayProf `elem` ways_ = StgDoMassageForProfiling : flags1
196              | otherwise            = flags1
197
198   return flags2
199
200 -----------------------------------------------------------------------------
201 -- Paths & Libraries
202
203 split_marker = ':'   -- not configurable (ToDo)
204
205 v_Import_paths, v_Include_paths, v_Library_paths :: IORef [String]
206 GLOBAL_VAR(v_Import_paths,  ["."], [String])
207 GLOBAL_VAR(v_Include_paths, ["."], [String])
208 GLOBAL_VAR(v_Library_paths, [],  [String])
209
210 #ifdef darwin_TARGET_OS
211 GLOBAL_VAR(v_Framework_paths, [], [String])
212 GLOBAL_VAR(v_Cmdline_frameworks, [], [String])
213 #endif
214
215 addToOrDeleteDirList :: IORef [String] -> String -> IO ()
216 addToOrDeleteDirList ref ""   = writeIORef ref []
217 addToOrDeleteDirList ref path = addToDirList ref path
218
219 addToDirList :: IORef [String] -> String -> IO ()
220 addToDirList ref path
221   = do paths           <- readIORef ref
222        shiny_new_ones  <- splitUp path
223        writeIORef ref (paths ++ filter notNull shiny_new_ones)
224                 -- empty paths are ignored: there might be a trailing
225                 -- ':' in the initial list, for example.  Empty paths can
226                 -- cause confusion when they are translated into -I options
227                 -- for passing to gcc.
228   where
229     splitUp ::String -> IO [String]
230 #ifdef mingw32_TARGET_OS
231      -- 'hybrid' support for DOS-style paths in directory lists.
232      -- 
233      -- That is, if "foo:bar:baz" is used, this interpreted as
234      -- consisting of three entries, 'foo', 'bar', 'baz'.
235      -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
236      -- as four elts, "c:/foo", "c:\\foo", "x", and "/bar" --
237      -- *provided* c:/foo exists and x:/bar doesn't.
238      --
239      -- Notice that no attempt is made to fully replace the 'standard'
240      -- split marker ':' with the Windows / DOS one, ';'. The reason being
241      -- that this will cause too much breakage for users & ':' will
242      -- work fine even with DOS paths, if you're not insisting on being silly.
243      -- So, use either.
244     splitUp []         = return []
245     splitUp (x:':':div:xs) 
246       | div `elem` dir_markers = do
247           let (p,rs) = findNextPath xs
248           ps  <- splitUp rs
249            {-
250              Consult the file system to check the interpretation
251              of (x:':':div:p) -- this is arguably excessive, we
252              could skip this test & just say that it is a valid
253              dir path.
254            -}
255           flg <- doesDirectoryExist (x:':':div:p)
256           if flg then
257              return ((x:':':div:p):ps)
258            else
259              return ([x]:(div:p):ps)
260     splitUp xs = do
261       let (p,rs) = findNextPath xs
262       ps <- splitUp rs
263       return (cons p ps)
264     
265     cons "" xs = xs
266     cons x  xs = x:xs
267
268     -- will be called either when we've consumed nought or the "<Drive>:/" part of
269     -- a DOS path, so splitting is just a Q of finding the next split marker.
270     findNextPath xs = 
271         case break (`elem` split_markers) xs of
272            (p, d:ds) -> (p, ds)
273            (p, xs)   -> (p, xs)
274
275     split_markers :: [Char]
276     split_markers = [':', ';']
277
278     dir_markers :: [Char]
279     dir_markers = ['/', '\\']
280
281 #else
282     splitUp xs = return (split split_marker xs)
283 #endif
284
285 -- ----------------------------------------------------------------------------
286 -- Loading the package config file
287
288 readPackageConf :: String -> IO ()
289 readPackageConf conf_file = do
290   proto_pkg_configs <- loadPackageConfig conf_file
291   top_dir           <- getTopDir
292   let pkg_configs = mungePackagePaths top_dir proto_pkg_configs
293   extendPackageConfigMap pkg_configs
294
295 mungePackagePaths :: String -> [PackageConfig] -> [PackageConfig]
296 -- Replace the string "$libdir" at the beginning of a path
297 -- with the current libdir (obtained from the -B option).
298 mungePackagePaths top_dir ps = map munge_pkg ps
299  where 
300   munge_pkg p = p{ import_dirs  = munge_paths (import_dirs p),
301                    include_dirs = munge_paths (include_dirs p),
302                    library_dirs = munge_paths (library_dirs p),
303                    framework_dirs = munge_paths (framework_dirs p) }
304
305   munge_paths = map munge_path
306
307   munge_path p 
308           | Just p' <- maybePrefixMatch "$libdir" p = top_dir ++ p'
309           | otherwise                               = p
310
311
312 -- -----------------------------------------------------------------------------
313 -- The list of packages requested on the command line
314
315 -- The package list reflects what packages were given as command-line options,
316 -- plus their dependent packages.  It is maintained in dependency order;
317 -- earlier packages may depend on later ones, but not vice versa
318 GLOBAL_VAR(v_ExplicitPackages, initPackageList, [PackageName])
319
320 initPackageList = [basePackage, rtsPackage]
321         -- basePackage is part of this list entirely because of 
322         -- wired-in names in GHCi.  See the notes on wired-in names in
323         -- Linker.linkExpr.  By putting the base backage in initPackageList
324         -- we make sure that it'll always by linked.
325
326
327 -- add a package requested from the command-line
328 addPackage :: String -> IO ()
329 addPackage package = do
330   pkg_details <- getPackageConfigMap
331   ps  <- readIORef v_ExplicitPackages
332   ps' <- add_package pkg_details ps (mkPackageName package)
333                 -- Throws an exception if it fails
334   writeIORef v_ExplicitPackages ps'
335
336 -- internal helper
337 add_package :: PackageConfigMap -> [PackageName]
338             -> PackageName -> IO [PackageName]
339 add_package pkg_details ps p    
340   | p `elem` ps -- Check if we've already added this package
341   = return ps
342   | Just details <- lookupPkg pkg_details p
343   -- Add the package's dependents also
344   = do ps' <- foldM (add_package pkg_details) ps (packageDependents details)
345        return (p : ps')
346   | otherwise
347   = throwDyn (CmdLineError ("unknown package name: " ++ packageNameString p))
348
349
350 -- -----------------------------------------------------------------------------
351 -- Extracting information from the packages in scope
352
353 -- Many of these functions take a list of packages: in those cases,
354 -- the list is expected to contain the "dependent packages",
355 -- i.e. those packages that were found to be depended on by the
356 -- current module/program.  These can be auto or non-auto packages, it
357 -- doesn't really matter.  The list is always combined with the list
358 -- of explicit (command-line) packages to determine which packages to
359 -- use.
360
361 getPackageImportPath :: IO [String]
362 getPackageImportPath = do
363   ps <- getExplicitAndAutoPackageConfigs
364                   -- import dirs are always derived from the 'auto' 
365                   -- packages as well as the explicit ones
366   return (nub (filter notNull (concatMap import_dirs ps)))
367
368 getPackageIncludePath :: [PackageName] -> IO [String]
369 getPackageIncludePath pkgs = do
370   ps <- getExplicitPackagesAnd pkgs
371   return (nub (filter notNull (concatMap include_dirs ps)))
372
373         -- includes are in reverse dependency order (i.e. rts first)
374 getPackageCIncludes :: [PackageConfig] -> IO [String]
375 getPackageCIncludes pkg_configs = do
376   return (reverse (nub (filter notNull (concatMap c_includes pkg_configs))))
377
378 getPackageLibraryPath :: [PackageName] -> IO [String]
379 getPackageLibraryPath pkgs = do 
380   ps <- getExplicitPackagesAnd pkgs
381   return (nub (filter notNull (concatMap library_dirs ps)))
382
383 getPackageLinkOpts :: [PackageName] -> IO [String]
384 getPackageLinkOpts pkgs = do
385   ps <- getExplicitPackagesAnd pkgs
386   tag <- readIORef v_Build_tag
387   rts_tag <- readIORef v_RTS_Build_tag
388   static <- readIORef v_Static
389   let 
390         imp        = if static then "" else "_imp"
391         libs p     = map addSuffix (hACK (hs_libraries p)) ++ extra_libraries p
392         imp_libs p = map (++imp) (libs p)
393         all_opts p = map ("-l" ++) (imp_libs p) ++ extra_ld_opts p
394
395         suffix     = if null tag then "" else  '_':tag
396         rts_suffix = if null rts_tag then "" else  '_':rts_tag
397
398         addSuffix rts@"HSrts"    = rts       ++ rts_suffix
399         addSuffix other_lib      = other_lib ++ suffix
400
401   return (concat (map all_opts ps))
402   where
403
404      -- This is a totally horrible (temporary) hack, for Win32.  Problem is
405      -- that package.conf for Win32 says that the main prelude lib is 
406      -- split into HSbase1, HSbase2 and HSbase3, which is needed due to a bug
407      -- in the GNU linker (PEi386 backend). However, we still only
408      -- have HSbase.a for static linking, not HSbase{1,2,3}.a
409      -- getPackageLibraries is called to find the .a's to add to the static
410      -- link line.  On Win32, this hACK detects HSbase{1,2,3} and 
411      -- replaces them with HSbase, so static linking still works.
412      -- Libraries needed for dynamic (GHCi) linking are discovered via
413      -- different route (in InteractiveUI.linkPackage).
414      -- See driver/PackageSrc.hs for the HSbase1/HSbase2 split definition.
415      -- THIS IS A STRICTLY TEMPORARY HACK (famous last words ...)
416      -- JRS 04 Sept 01: Same appalling hack for HSwin32[1,2]
417      -- KAA 29 Mar  02: Same appalling hack for HSobjectio[1,2,3,4]
418      hACK libs
419 #      if !defined(mingw32_TARGET_OS) && !defined(cygwin32_TARGET_OS)
420        = libs
421 #      else
422        = if   "HSbase1" `elem` libs && "HSbase2" `elem` libs && "HSbase3" `elem` libs
423          then "HSbase" : filter (not.(isPrefixOf "HSbase")) libs
424          else
425          if   "HSwin321" `elem` libs && "HSwin322" `elem` libs
426          then "HSwin32" : filter (not.(isPrefixOf "HSwin32")) libs
427          else 
428          if   "HSobjectio1" `elem` libs && "HSobjectio2" `elem` libs && "HSobjectio3" `elem` libs && "HSobjectio4" `elem` libs
429          then "HSobjectio" : filter (not.(isPrefixOf "HSobjectio")) libs
430          else 
431          libs
432 #      endif
433
434 getPackageExtraGhcOpts :: IO [String]
435 getPackageExtraGhcOpts = do
436   ps <- getExplicitAndAutoPackageConfigs
437   return (concatMap extra_ghc_opts ps)
438
439 getPackageExtraCcOpts :: [PackageName] -> IO [String]
440 getPackageExtraCcOpts pkgs = do
441   ps <- getExplicitPackagesAnd pkgs
442   return (concatMap extra_cc_opts ps)
443
444 #ifdef darwin_TARGET_OS
445 getPackageFrameworkPath  :: [PackageName] -> IO [String]
446 getPackageFrameworkPath pkgs = do
447   ps <- getExplicitPackagesAnd pkgs
448   return (nub (filter notNull (concatMap framework_dirs ps)))
449
450 getPackageFrameworks  :: [PackageName] -> IO [String]
451 getPackageFrameworks pkgs = do
452   ps <- getExplicitPackagesAnd pkgs
453   return (concatMap extra_frameworks ps)
454 #endif
455
456 -- -----------------------------------------------------------------------------
457 -- Package Utils
458
459 getExplicitPackagesAnd :: [PackageName] -> IO [PackageConfig]
460 getExplicitPackagesAnd pkg_names = do
461   pkg_map <- getPackageConfigMap
462   expl <- readIORef v_ExplicitPackages
463   all_pkgs <- foldM (add_package pkg_map) expl pkg_names
464   getPackageDetails all_pkgs
465
466 -- return all packages, including both the auto packages and the explicit ones
467 getExplicitAndAutoPackageConfigs :: IO [PackageConfig]
468 getExplicitAndAutoPackageConfigs = do
469   pkg_map <- getPackageConfigMap
470   let auto_packages = [ mkPackageName (name p) | p <- eltsUFM pkg_map, auto p ]
471   getExplicitPackagesAnd auto_packages
472
473 -----------------------------------------------------------------------------
474 -- Ways
475
476 -- The central concept of a "way" is that all objects in a given
477 -- program must be compiled in the same "way".  Certain options change
478 -- parameters of the virtual machine, eg. profiling adds an extra word
479 -- to the object header, so profiling objects cannot be linked with
480 -- non-profiling objects.
481
482 -- After parsing the command-line options, we determine which "way" we
483 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
484
485 -- We then find the "build-tag" associated with this way, and this
486 -- becomes the suffix used to find .hi files and libraries used in
487 -- this compilation.
488
489 GLOBAL_VAR(v_Build_tag, "", String)
490
491 -- The RTS has its own build tag, because there are some ways that
492 -- affect the RTS only.
493 GLOBAL_VAR(v_RTS_Build_tag, "", String)
494
495 data WayName
496   = WayThreaded
497   | WayDebug
498   | WayProf
499   | WayUnreg
500   | WayTicky
501   | WayPar
502   | WayGran
503   | WaySMP
504   | WayNDP
505   | WayUser_a
506   | WayUser_b
507   | WayUser_c
508   | WayUser_d
509   | WayUser_e
510   | WayUser_f
511   | WayUser_g
512   | WayUser_h
513   | WayUser_i
514   | WayUser_j
515   | WayUser_k
516   | WayUser_l
517   | WayUser_m
518   | WayUser_n
519   | WayUser_o
520   | WayUser_A
521   | WayUser_B
522   deriving (Eq,Ord)
523
524 GLOBAL_VAR(v_Ways, [] ,[WayName])
525
526 allowed_combination way = and [ x `allowedWith` y 
527                               | x <- way, y <- way, x < y ]
528   where
529         -- Note ordering in these tests: the left argument is
530         -- <= the right argument, according to the Ord instance
531         -- on Way above.
532
533         -- debug is allowed with everything
534         _ `allowedWith` WayDebug                = True
535         WayDebug `allowedWith` _                = True
536
537         WayThreaded `allowedWith` WayProf       = True
538         WayProf `allowedWith` WayUnreg          = True
539         WayProf `allowedWith` WaySMP            = True
540         WayProf `allowedWith` WayNDP            = True
541         _ `allowedWith` _                       = False
542
543
544 findBuildTag :: IO [String]  -- new options
545 findBuildTag = do
546   way_names <- readIORef v_Ways
547   let ws = sort way_names
548   if not (allowed_combination ws)
549       then throwDyn (CmdLineError $
550                     "combination not supported: "  ++
551                     foldr1 (\a b -> a ++ '/':b) 
552                     (map (wayName . lkupWay) ws))
553       else let ways    = map lkupWay ws
554                tag     = mkBuildTag (filter (not.wayRTSOnly) ways)
555                rts_tag = mkBuildTag ways
556                flags   = map wayOpts ways
557            in do
558            writeIORef v_Build_tag tag
559            writeIORef v_RTS_Build_tag rts_tag
560            return (concat flags)
561
562 mkBuildTag :: [Way] -> String
563 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
564
565 lkupWay w = 
566    case lookup w way_details of
567         Nothing -> error "findBuildTag"
568         Just details -> details
569
570 data Way = Way {
571   wayTag     :: String,
572   wayRTSOnly :: Bool,
573   wayName    :: String,
574   wayOpts    :: [String]
575   }
576
577 way_details :: [ (WayName, Way) ]
578 way_details =
579   [ (WayThreaded, Way "thr" True "Threaded" [
580 #if defined(freebsd_TARGET_OS)
581         "-optc-pthread"
582 #endif
583         ] ),
584
585     (WayDebug, Way "debug" True "Debug" [] ),
586
587     (WayProf, Way  "p" False "Profiling"
588         [ "-fscc-profiling"
589         , "-DPROFILING"
590         , "-optc-DPROFILING"
591         , "-fvia-C" ]),
592
593     (WayTicky, Way  "t" False "Ticky-ticky Profiling"  
594         [ "-fticky-ticky"
595         , "-DTICKY_TICKY"
596         , "-optc-DTICKY_TICKY"
597         , "-fvia-C" ]),
598
599     (WayUnreg, Way  "u" False "Unregisterised" 
600         unregFlags ),
601
602     -- optl's below to tell linker where to find the PVM library -- HWL
603     (WayPar, Way  "mp" False "Parallel" 
604         [ "-fparallel"
605         , "-D__PARALLEL_HASKELL__"
606         , "-optc-DPAR"
607         , "-package concurrent"
608         , "-optc-w"
609         , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
610         , "-optl-lpvm3"
611         , "-optl-lgpvm3"
612         , "-fvia-C" ]),
613
614     -- at the moment we only change the RTS and could share compiler and libs!
615     (WayPar, Way  "mt" False "Parallel ticky profiling" 
616         [ "-fparallel"
617         , "-D__PARALLEL_HASKELL__"
618         , "-optc-DPAR"
619         , "-optc-DPAR_TICKY"
620         , "-package concurrent"
621         , "-optc-w"
622         , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
623         , "-optl-lpvm3"
624         , "-optl-lgpvm3"
625         , "-fvia-C" ]),
626
627     (WayPar, Way  "md" False "Distributed" 
628         [ "-fparallel"
629         , "-D__PARALLEL_HASKELL__"
630         , "-D__DISTRIBUTED_HASKELL__"
631         , "-optc-DPAR"
632         , "-optc-DDIST"
633         , "-package concurrent"
634         , "-optc-w"
635         , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
636         , "-optl-lpvm3"
637         , "-optl-lgpvm3"
638         , "-fvia-C" ]),
639
640     (WayGran, Way  "mg" False "GranSim"
641         [ "-fgransim"
642         , "-D__GRANSIM__"
643         , "-optc-DGRAN"
644         , "-package concurrent"
645         , "-fvia-C" ]),
646
647     (WaySMP, Way  "s" False "SMP"
648         [ "-fsmp"
649         , "-optc-pthread"
650 #ifndef freebsd_TARGET_OS
651         , "-optl-pthread"
652 #endif
653         , "-optc-DSMP"
654         , "-fvia-C" ]),
655
656     (WayNDP, Way  "ndp" False "Nested data parallelism"
657         [ "-fparr"
658         , "-fflatten"]),
659
660     (WayUser_a,  Way  "a"  False "User way 'a'"  ["$WAY_a_REAL_OPTS"]), 
661     (WayUser_b,  Way  "b"  False "User way 'b'"  ["$WAY_b_REAL_OPTS"]), 
662     (WayUser_c,  Way  "c"  False "User way 'c'"  ["$WAY_c_REAL_OPTS"]), 
663     (WayUser_d,  Way  "d"  False "User way 'd'"  ["$WAY_d_REAL_OPTS"]), 
664     (WayUser_e,  Way  "e"  False "User way 'e'"  ["$WAY_e_REAL_OPTS"]), 
665     (WayUser_f,  Way  "f"  False "User way 'f'"  ["$WAY_f_REAL_OPTS"]), 
666     (WayUser_g,  Way  "g"  False "User way 'g'"  ["$WAY_g_REAL_OPTS"]), 
667     (WayUser_h,  Way  "h"  False "User way 'h'"  ["$WAY_h_REAL_OPTS"]), 
668     (WayUser_i,  Way  "i"  False "User way 'i'"  ["$WAY_i_REAL_OPTS"]), 
669     (WayUser_j,  Way  "j"  False "User way 'j'"  ["$WAY_j_REAL_OPTS"]), 
670     (WayUser_k,  Way  "k"  False "User way 'k'"  ["$WAY_k_REAL_OPTS"]), 
671     (WayUser_l,  Way  "l"  False "User way 'l'"  ["$WAY_l_REAL_OPTS"]), 
672     (WayUser_m,  Way  "m"  False "User way 'm'"  ["$WAY_m_REAL_OPTS"]), 
673     (WayUser_n,  Way  "n"  False "User way 'n'"  ["$WAY_n_REAL_OPTS"]), 
674     (WayUser_o,  Way  "o"  False "User way 'o'"  ["$WAY_o_REAL_OPTS"]), 
675     (WayUser_A,  Way  "A"  False "User way 'A'"  ["$WAY_A_REAL_OPTS"]), 
676     (WayUser_B,  Way  "B"  False "User way 'B'"  ["$WAY_B_REAL_OPTS"]) 
677   ]
678
679 unregFlags = 
680    [ "-optc-DNO_REGS"
681    , "-optc-DUSE_MINIINTERPRETER"
682    , "-fno-asm-mangling"
683    , "-funregisterised"
684    , "-fvia-C" ]
685
686 -----------------------------------------------------------------------------
687 -- Options for particular phases
688
689 GLOBAL_VAR(v_Opt_dep,    [], [String])
690 GLOBAL_VAR(v_Anti_opt_C, [], [String])
691 GLOBAL_VAR(v_Opt_C,      [], [String])
692 GLOBAL_VAR(v_Opt_l,      [], [String])
693 GLOBAL_VAR(v_Opt_dll,    [], [String])
694
695 getStaticOpts :: IORef [String] -> IO [String]
696 getStaticOpts ref = readIORef ref >>= return . reverse