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