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