1 -----------------------------------------------------------------------------
2 -- $Id: DriverFlags.hs,v 1.107 2002/12/12 17:36:18 simonmar Exp $
6 -- (c) Simon Marlow 2000
8 -----------------------------------------------------------------------------
11 processArgs, OptKind(..), static_flags, dynamic_flags,
17 #include "HsVersions.h"
18 #include "../includes/config.h"
20 import MkIface ( showIface )
31 import DATA_IOREF ( readIORef, writeIORef )
33 import System ( exitWith, ExitCode(..) )
39 -----------------------------------------------------------------------------
42 -- Flag parsing is now done in stages:
44 -- * parse the initial list of flags and remove any flags understood
45 -- by the driver only. Determine whether we're in multi-compilation
46 -- or single-compilation mode (done in Main.main).
48 -- * gather the list of "static" hsc flags, and assign them to the global
49 -- static hsc flags variable.
51 -- * build the inital DynFlags from the remaining flags.
53 -- * complain if we've got any flags left over.
55 -- * for each source file: grab the OPTIONS, and build a new DynFlags
56 -- to pass to the compiler.
58 -----------------------------------------------------------------------------
59 -- Process command-line
62 = NoArg (IO ()) -- flag with no argument
63 | HasArg (String -> IO ()) -- flag has an argument (maybe prefix)
64 | SepArg (String -> IO ()) -- flag has a separate argument
65 | Prefix (String -> IO ()) -- flag is a prefix only
66 | OptPrefix (String -> IO ()) -- flag may be a prefix
67 | AnySuffix (String -> IO ()) -- flag is a prefix, pass whole arg to fn
68 | PassFlag (String -> IO ()) -- flag with no arg, pass flag to fn
69 | PrefixPred (String -> Bool) (String -> IO ())
70 | AnySuffixPred (String -> Bool) (String -> IO ())
72 processArgs :: [(String,OptKind)] -> [String] -> [String]
73 -> IO [String] -- returns spare args
74 processArgs _spec [] spare = return (reverse spare)
76 processArgs spec args@(('-':arg):args') spare = do
77 case findArg spec arg of
78 Just (rest,action) -> do args' <- processOneArg action rest args
79 processArgs spec args' spare
80 Nothing -> processArgs spec args' (('-':arg):spare)
82 processArgs spec (arg:args) spare =
83 processArgs spec args (arg:spare)
85 processOneArg :: OptKind -> String -> [String] -> IO [String]
86 processOneArg action rest (dash_arg@('-':arg):args) =
90 then io >> return args
91 else unknownFlagErr dash_arg
95 then fio rest >> return args
97 [] -> unknownFlagErr dash_arg
98 (arg1:args1) -> fio arg1 >> return args1
102 [] -> unknownFlagErr dash_arg
103 (arg1:args1) -> fio arg1 >> return args1
107 then fio rest >> return args
108 else unknownFlagErr dash_arg
112 then fio rest >> return args
113 else unknownFlagErr dash_arg
115 OptPrefix fio -> fio rest >> return args
117 AnySuffix fio -> fio dash_arg >> return args
119 AnySuffixPred p fio -> fio dash_arg >> return args
123 then unknownFlagErr dash_arg
124 else fio dash_arg >> return args
126 findArg :: [(String,OptKind)] -> String -> Maybe (String,OptKind)
128 = case [ (remove_spaces rest, k)
130 Just rest <- [my_prefix_match pat arg],
136 arg_ok (NoArg _) rest arg = null rest
137 arg_ok (HasArg _) rest arg = True
138 arg_ok (SepArg _) rest arg = null rest
139 arg_ok (Prefix _) rest arg = notNull rest
140 arg_ok (PrefixPred p _) rest arg = notNull rest && p rest
141 arg_ok (OptPrefix _) rest arg = True
142 arg_ok (PassFlag _) rest arg = null rest
143 arg_ok (AnySuffix _) rest arg = True
144 arg_ok (AnySuffixPred p _) rest arg = p arg
146 -----------------------------------------------------------------------------
149 -- note that ordering is important in the following list: any flag which
150 -- is a prefix flag (i.e. HasArg, Prefix, OptPrefix, AnySuffix) will override
151 -- flags further down the list with the same prefix.
154 [ ------- help / version ----------------------------------------------
155 ( "?" , NoArg showGhcUsage)
156 , ( "-help" , NoArg showGhcUsage)
157 , ( "-print-libdir" , NoArg (do getTopDir >>= putStrLn
158 exitWith ExitSuccess))
159 , ( "-version" , NoArg (do putStrLn (cProjectName
160 ++ ", version " ++ cProjectVersion)
161 exitWith ExitSuccess))
162 , ( "-numeric-version", NoArg (do putStrLn cProjectVersion
163 exitWith ExitSuccess))
165 ------- interfaces ----------------------------------------------------
166 , ( "-show-iface" , HasArg (\f -> do showIface f
167 exitWith ExitSuccess))
169 ------- verbosity ----------------------------------------------------
170 , ( "n" , NoArg setDryRun )
172 ------- primary modes ------------------------------------------------
173 , ( "M" , PassFlag (setMode DoMkDependHS))
174 , ( "E" , PassFlag (setMode (StopBefore Hsc)))
175 , ( "C" , PassFlag (\f -> do setMode (StopBefore HCc) f
177 , ( "S" , PassFlag (setMode (StopBefore As)))
178 , ( "c" , PassFlag (setMode (StopBefore Ln)))
179 , ( "-make" , PassFlag (setMode DoMake))
180 , ( "-interactive" , PassFlag (setMode DoInteractive))
181 , ( "-mk-dll" , PassFlag (setMode DoMkDLL))
183 -- -fno-code says to stop after Hsc but don't generate any code.
184 , ( "fno-code" , PassFlag (\f -> do setMode (StopBefore HCc) f
186 writeIORef v_Recomp False))
188 ------- GHCi -------------------------------------------------------
189 , ( "ignore-dot-ghci", NoArg (writeIORef v_Read_DotGHCi False) )
190 , ( "read-dot-ghci" , NoArg (writeIORef v_Read_DotGHCi True) )
192 ------- recompilation checker --------------------------------------
193 , ( "recomp" , NoArg (writeIORef v_Recomp True) )
194 , ( "no-recomp" , NoArg (writeIORef v_Recomp False) )
196 ------- ways --------------------------------------------------------
197 , ( "prof" , NoArg (addNoDups v_Ways WayProf) )
198 , ( "unreg" , NoArg (addNoDups v_Ways WayUnreg) )
199 , ( "ticky" , NoArg (addNoDups v_Ways WayTicky) )
200 , ( "parallel" , NoArg (addNoDups v_Ways WayPar) )
201 , ( "gransim" , NoArg (addNoDups v_Ways WayGran) )
202 , ( "smp" , NoArg (addNoDups v_Ways WaySMP) )
203 , ( "debug" , NoArg (addNoDups v_Ways WayDebug) )
204 , ( "ndp" , NoArg (addNoDups v_Ways WayNDP) )
207 ------ Debugging ----------------------------------------------------
208 , ( "dppr-noprags", PassFlag (add v_Opt_C) )
209 , ( "dppr-debug", PassFlag (add v_Opt_C) )
210 , ( "dppr-user-length", AnySuffix (add v_Opt_C) )
211 -- rest of the debugging flags are dynamic
213 --------- Profiling --------------------------------------------------
214 , ( "auto-dicts" , NoArg (add v_Opt_C "-fauto-sccs-on-dicts") )
215 , ( "auto-all" , NoArg (add v_Opt_C "-fauto-sccs-on-all-toplevs") )
216 , ( "auto" , NoArg (add v_Opt_C "-fauto-sccs-on-exported-toplevs") )
217 , ( "caf-all" , NoArg (add v_Opt_C "-fauto-sccs-on-individual-cafs") )
218 -- "ignore-sccs" doesn't work (ToDo)
220 , ( "no-auto-dicts" , NoArg (add v_Anti_opt_C "-fauto-sccs-on-dicts") )
221 , ( "no-auto-all" , NoArg (add v_Anti_opt_C "-fauto-sccs-on-all-toplevs") )
222 , ( "no-auto" , NoArg (add v_Anti_opt_C "-fauto-sccs-on-exported-toplevs") )
223 , ( "no-caf-all" , NoArg (add v_Anti_opt_C "-fauto-sccs-on-individual-cafs") )
225 ------- Miscellaneous -----------------------------------------------
226 , ( "no-link-chk" , NoArg (return ()) ) -- ignored for backwards compat
227 , ( "no-hs-main" , NoArg (writeIORef v_NoHsMain True) )
229 ------- Output Redirection ------------------------------------------
230 , ( "odir" , HasArg (writeIORef v_Output_dir . Just) )
231 , ( "o" , SepArg (writeIORef v_Output_file . Just) )
232 , ( "osuf" , HasArg (writeIORef v_Object_suf) )
233 , ( "hcsuf" , HasArg (writeIORef v_HC_suf . Just) )
234 , ( "hisuf" , HasArg (writeIORef v_Hi_suf) )
235 , ( "hidir" , HasArg (writeIORef v_Hi_dir . Just) )
236 , ( "buildtag" , HasArg (writeIORef v_Build_tag) )
237 , ( "tmpdir" , HasArg setTmpDir)
238 , ( "ohi" , HasArg (writeIORef v_Output_hi . Just) )
241 , ( "keep-hc-file" , AnySuffix (\_ -> writeIORef v_Keep_hc_files True) )
242 , ( "keep-s-file" , AnySuffix (\_ -> writeIORef v_Keep_s_files True) )
243 , ( "keep-raw-s-file", AnySuffix (\_ -> writeIORef v_Keep_raw_s_files True) )
245 , ( "keep-il-file" , AnySuffix (\_ -> writeIORef v_Keep_il_files True) )
246 , ( "keep-ilx-file" , AnySuffix (\_ -> writeIORef v_Keep_ilx_files True) )
248 , ( "keep-tmp-files" , AnySuffix (\_ -> writeIORef v_Keep_tmp_files True) )
250 , ( "split-objs" , NoArg (if can_split
251 then do writeIORef v_Split_object_files True
252 add v_Opt_C "-fglobalise-toplev-names"
253 else hPutStrLn stderr
254 "warning: don't know how to split \
255 \object files on this architecture"
258 ------- Include/Import Paths ----------------------------------------
259 , ( "i" , OptPrefix (addToDirList v_Import_paths) )
260 , ( "I" , Prefix (addToDirList v_Include_paths) )
262 ------- Libraries ---------------------------------------------------
263 , ( "L" , Prefix (addToDirList v_Library_paths) )
264 , ( "l" , AnySuffix (\s -> add v_Opt_l s >> add v_Opt_dll s) )
266 #ifdef darwin_TARGET_OS
267 ------- Frameworks --------------------------------------------------
268 -- -framework-path should really be -F ...
269 , ( "framework-path" , HasArg (addToDirList v_Framework_paths) )
270 , ( "framework" , HasArg (add v_Cmdline_frameworks) )
272 ------- Packages ----------------------------------------------------
273 , ( "package-name" , HasArg (\s -> add v_Opt_C ("-inpackage="++s)) )
275 , ( "package-conf" , HasArg (readPackageConf) )
276 , ( "package" , HasArg (addPackage) )
277 , ( "syslib" , HasArg (addPackage) ) -- for compatibility w/ old vsns
279 ------- Specific phases --------------------------------------------
280 , ( "pgmP" , HasArg setPgmP )
281 , ( "pgmF" , HasArg setPgmF )
282 , ( "pgmc" , HasArg setPgmc )
283 , ( "pgmm" , HasArg setPgmm )
284 , ( "pgms" , HasArg setPgms )
285 , ( "pgma" , HasArg setPgma )
286 , ( "pgml" , HasArg setPgml )
288 , ( "pgmI" , HasArg setPgmI )
289 , ( "pgmi" , HasArg setPgmi )
292 , ( "optdep" , HasArg (add v_Opt_dep) )
293 , ( "optl" , HasArg (add v_Opt_l) )
294 , ( "optdll" , HasArg (add v_Opt_dll) )
296 ----- Linker --------------------------------------------------------
297 , ( "static" , NoArg (writeIORef v_Static True) )
298 , ( "dynamic" , NoArg (writeIORef v_Static False) )
299 , ( "rdynamic" , NoArg (return ()) ) -- ignored for compat w/ gcc
301 ----- RTS opts ------------------------------------------------------
302 , ( "H" , HasArg (setHeapSize . fromIntegral . decodeSize) )
303 , ( "Rghc-timing" , NoArg (enableTimingStats) )
305 ------ Compiler flags -----------------------------------------------
306 , ( "O2-for-C" , NoArg (writeIORef v_minus_o2_for_C True) )
307 , ( "O" , NoArg (setOptLevel 1))
308 , ( "Onot" , NoArg (setOptLevel 0))
309 , ( "O" , PrefixPred (all isDigit) (setOptLevel . read))
311 , ( "fno-asm-mangling" , NoArg (writeIORef v_Do_asm_mangling False) )
313 , ( "fmax-simplifier-iterations",
314 Prefix (writeIORef v_MaxSimplifierIterations . read) )
317 SepArg (\s -> writeIORef v_RuleCheck (Just s)) )
319 , ( "fusagesp" , NoArg (do writeIORef v_UsageSPInf True
320 add v_Opt_C "-fusagesp-on") )
322 , ( "fexcess-precision" , NoArg (do writeIORef v_Excess_precision True
323 add v_Opt_C "-fexcess-precision"))
325 -- Optimisation flags are treated specially, so the normal
326 -- -fno-* pattern below doesn't work. We therefore allow
327 -- certain optimisation passes to be turned off explicitly:
328 , ( "fno-strictness" , NoArg (writeIORef v_Strictness False) )
329 , ( "fno-cse" , NoArg (writeIORef v_CSE False) )
331 -- All other "-fno-<blah>" options cancel out "-f<blah>" on the hsc cmdline
332 , ( "fno-", PrefixPred (\s -> isStaticHscFlag ("f"++s))
333 (\s -> add v_Anti_opt_C ("-f"++s)) )
335 -- Pass all remaining "-f<blah>" options to hsc
336 , ( "f", AnySuffixPred (isStaticHscFlag) (add v_Opt_C) )
341 ( "cpp", NoArg (updDynFlags (\s -> s{ cppFlag = True })) )
342 , ( "F", NoArg (updDynFlags (\s -> s{ ppFlag = True })) )
343 , ( "#include", HasArg (addCmdlineHCInclude) )
345 , ( "v", OptPrefix (setVerbosity) )
347 , ( "optL", HasArg (addOpt_L) )
348 , ( "optP", HasArg (addOpt_P) )
349 , ( "optF", HasArg (addOpt_F) )
350 , ( "optc", HasArg (addOpt_c) )
351 , ( "optm", HasArg (addOpt_m) )
352 , ( "opta", HasArg (addOpt_a) )
354 , ( "optI", HasArg (addOpt_I) )
355 , ( "opti", HasArg (addOpt_i) )
358 ------ HsCpp opts ---------------------------------------------------
359 -- With a C compiler whose system() doesn't use a UNIX shell (i.e.
360 -- mingwin gcc), -D and -U args must *not* be quoted, as the quotes
361 -- will be interpreted as part of the arguments, and not stripped;
362 -- on all other systems, quoting is necessary, to avoid interpretation
363 -- of shell metacharacters in the arguments (e.g. green-card's
364 -- -DBEGIN_GHC_ONLY='}-' trick).
365 #ifndef mingw32_HOST_OS
366 , ( "D", Prefix (\s -> addOpt_P ("-D'"++s++"'") ) )
367 , ( "U", Prefix (\s -> addOpt_P ("-U'"++s++"'") ) )
369 , ( "D", Prefix (\s -> addOpt_P ("-D"++s) ) )
370 , ( "U", Prefix (\s -> addOpt_P ("-U"++s) ) )
373 ------ Debugging ----------------------------------------------------
374 , ( "dstg-stats", NoArg (writeIORef v_StgStats True) )
376 , ( "ddump-absC", NoArg (setDynFlag Opt_D_dump_absC) )
377 , ( "ddump-asm", NoArg (setDynFlag Opt_D_dump_asm) )
378 , ( "ddump-cpranal", NoArg (setDynFlag Opt_D_dump_cpranal) )
379 , ( "ddump-deriv", NoArg (setDynFlag Opt_D_dump_deriv) )
380 , ( "ddump-ds", NoArg (setDynFlag Opt_D_dump_ds) )
381 , ( "ddump-flatC", NoArg (setDynFlag Opt_D_dump_flatC) )
382 , ( "ddump-foreign", NoArg (setDynFlag Opt_D_dump_foreign) )
383 , ( "ddump-inlinings", NoArg (setDynFlag Opt_D_dump_inlinings) )
384 , ( "ddump-occur-anal", NoArg (setDynFlag Opt_D_dump_occur_anal) )
385 , ( "ddump-parsed", NoArg (setDynFlag Opt_D_dump_parsed) )
386 , ( "ddump-realC", NoArg (setDynFlag Opt_D_dump_realC) )
387 , ( "ddump-rn", NoArg (setDynFlag Opt_D_dump_rn) )
388 , ( "ddump-simpl", NoArg (setDynFlag Opt_D_dump_simpl) )
389 , ( "ddump-simpl-iterations", NoArg (setDynFlag Opt_D_dump_simpl_iterations) )
390 , ( "ddump-spec", NoArg (setDynFlag Opt_D_dump_spec) )
391 , ( "ddump-prep", NoArg (setDynFlag Opt_D_dump_prep) )
392 , ( "ddump-stg", NoArg (setDynFlag Opt_D_dump_stg) )
393 , ( "ddump-stranal", NoArg (setDynFlag Opt_D_dump_stranal) )
394 , ( "ddump-tc", NoArg (setDynFlag Opt_D_dump_tc) )
395 , ( "ddump-types", NoArg (setDynFlag Opt_D_dump_types) )
396 , ( "ddump-rules", NoArg (setDynFlag Opt_D_dump_rules) )
397 , ( "ddump-usagesp", NoArg (setDynFlag Opt_D_dump_usagesp) )
398 , ( "ddump-cse", NoArg (setDynFlag Opt_D_dump_cse) )
399 , ( "ddump-worker-wrapper", NoArg (setDynFlag Opt_D_dump_worker_wrapper) )
400 , ( "dshow-passes", NoArg (setVerbosity "2") )
401 , ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace) )
402 , ( "ddump-tc-trace", NoArg (setDynFlag Opt_D_dump_tc_trace) )
403 , ( "ddump-splices", NoArg (setDynFlag Opt_D_dump_splices) )
404 , ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats) )
405 , ( "ddump-stix", NoArg (setDynFlag Opt_D_dump_stix) )
406 , ( "ddump-simpl-stats", NoArg (setDynFlag Opt_D_dump_simpl_stats) )
407 , ( "ddump-bcos", NoArg (setDynFlag Opt_D_dump_BCOs) )
408 , ( "dsource-stats", NoArg (setDynFlag Opt_D_source_stats) )
409 , ( "dverbose-core2core", NoArg (setDynFlag Opt_D_verbose_core2core) )
410 , ( "dverbose-stg2stg", NoArg (setDynFlag Opt_D_verbose_stg2stg) )
411 , ( "ddump-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs) )
412 , ( "ddump-hi", NoArg (setDynFlag Opt_D_dump_hi) )
413 , ( "ddump-minimal-imports", NoArg (setDynFlag Opt_D_dump_minimal_imports) )
414 , ( "ddump-vect", NoArg (setDynFlag Opt_D_dump_vect) )
415 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting) )
416 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting) )
417 , ( "dusagesp-lint", NoArg (setDynFlag Opt_DoUSPLinting) )
419 ------ Machine dependant (-m<blah>) stuff ---------------------------
421 , ( "monly-2-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 2}) ))
422 , ( "monly-3-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 3}) ))
423 , ( "monly-4-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 4}) ))
425 ------ Warning opts -------------------------------------------------
426 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
427 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
428 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
429 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
430 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
432 ------ Compiler flags -----------------------------------------------
434 , ( "fasm", AnySuffix (\_ -> setLang HscAsm) )
435 , ( "fvia-c", NoArg (setLang HscC) )
436 , ( "fvia-C", NoArg (setLang HscC) )
437 , ( "filx", NoArg (setLang HscILX) )
439 -- "active negatives"
440 , ( "fno-implicit-prelude", NoArg (setDynFlag Opt_NoImplicitPrelude) )
441 , ( "fno-monomorphism-restriction",
442 NoArg (setDynFlag Opt_NoMonomorphismRestriction) )
444 -- the rest of the -f* and -fno-* flags
445 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
446 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
449 -- these -f<blah> flags can all be reversed with -fno-<blah>
452 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
453 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
454 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
455 ( "warn-missing-fields", Opt_WarnMissingFields ),
456 ( "warn-missing-methods", Opt_WarnMissingMethods ),
457 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
458 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
459 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
460 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
461 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
462 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
463 ( "warn-unused-imports", Opt_WarnUnusedImports ),
464 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
465 ( "warn-deprecations", Opt_WarnDeprecations ),
466 ( "glasgow-exts", Opt_GlasgowExts ),
467 ( "fi", Opt_FFI ), -- support `-ffi'...
468 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
469 ( "with", Opt_With ), -- with keyword
470 ( "parr", Opt_PArr ),
471 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
472 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
473 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
474 ( "generics", Opt_Generics )
477 isFFlag f = f `elem` (map fst fFlags)
478 getFFlag f = fromJust (lookup f fFlags)
480 -----------------------------------------------------------------------------
481 -- convert sizes like "3.5M" into integers
483 decodeSize :: String -> Integer
485 | c == "" = truncate n
486 | c == "K" || c == "k" = truncate (n * 1000)
487 | c == "M" || c == "m" = truncate (n * 1000 * 1000)
488 | c == "G" || c == "g" = truncate (n * 1000 * 1000 * 1000)
489 | otherwise = throwDyn (CmdLineError ("can't decode size: " ++ str))
490 where (m, c) = span pred str
492 pred c = isDigit c || c == '.'
495 -----------------------------------------------------------------------------
498 #if __GLASGOW_HASKELL__ >= 504
499 foreign import ccall unsafe "setHeapSize" setHeapSize :: Int -> IO ()
500 foreign import ccall unsafe "enableTimingStats" enableTimingStats :: IO ()
502 foreign import "setHeapSize" unsafe setHeapSize :: Int -> IO ()
503 foreign import "enableTimingStats" unsafe enableTimingStats :: IO ()
506 -----------------------------------------------------------------------------
507 -- Build the Hsc static command line opts
509 buildStaticHscOpts :: IO [String]
510 buildStaticHscOpts = do
512 opt_C_ <- getStaticOpts v_Opt_C -- misc hsc opts from the command line
515 minus_o <- readIORef v_OptLevel
516 let optimisation_opts =
518 0 -> hsc_minusNoO_flags
519 1 -> hsc_minusO_flags
520 2 -> hsc_minusO2_flags
521 n -> throwDyn (CmdLineError ("unknown optimisation level: "
525 -- take into account -fno-* flags by removing the equivalent -f*
526 -- flag from our list.
527 anti_flags <- getStaticOpts v_Anti_opt_C
528 let basic_opts = opt_C_ ++ optimisation_opts
529 filtered_opts = filter (`notElem` anti_flags) basic_opts
531 static <- (do s <- readIORef v_Static; if s then return "-static"
534 return ( static : filtered_opts )
536 -----------------------------------------------------------------------------
537 -- Via-C compilation stuff
539 -- flags returned are: ( all C compilations
540 -- , registerised HC compilations
544 | prefixMatch "alpha" cTARGETPLATFORM
545 = return ( ["-static", "-w", "-mieee"
546 #ifdef HAVE_THREADED_RTS_SUPPORT
550 -- For now, to suppress the gcc warning "call-clobbered
551 -- register used for global register variable", we simply
552 -- disable all warnings altogether using the -w flag. Oh well.
554 | prefixMatch "hppa" cTARGETPLATFORM
555 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
556 -- (very nice, but too bad the HP /usr/include files don't agree.)
557 = return ( ["-static", "-D_HPUX_SOURCE"], [] )
559 | prefixMatch "m68k" cTARGETPLATFORM
560 -- -fno-defer-pop : for the .hc files, we want all the pushing/
561 -- popping of args to routines to be explicit; if we let things
562 -- be deferred 'til after an STGJUMP, imminent death is certain!
564 -- -fomit-frame-pointer : *don't*
565 -- It's better to have a6 completely tied up being a frame pointer
566 -- rather than let GCC pick random things to do with it.
567 -- (If we want to steal a6, then we would try to do things
568 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
569 = return ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
571 | prefixMatch "i386" cTARGETPLATFORM
572 -- -fno-defer-pop : basically the same game as for m68k
574 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
575 -- the fp (%ebp) for our register maps.
576 = do n_regs <- dynFlag stolen_x86_regs
577 sta <- readIORef v_Static
578 return ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
579 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
581 [ "-fno-defer-pop", "-fomit-frame-pointer",
582 -- we want -fno-builtin, because when gcc inlines
583 -- built-in functions like memcpy() it tends to
584 -- run out of registers, requiring -monly-n-regs
586 "-DSTOLEN_X86_REGS="++show n_regs ]
589 | prefixMatch "ia64" cTARGETPLATFORM
590 = return ( [], ["-fomit-frame-pointer", "-G0"] )
592 | prefixMatch "mips" cTARGETPLATFORM
593 = return ( ["-static"], [] )
595 | prefixMatch "sparc" cTARGETPLATFORM
596 = return ( [], ["-w"] )
597 -- For now, to suppress the gcc warning "call-clobbered
598 -- register used for global register variable", we simply
599 -- disable all warnings altogether using the -w flag. Oh well.
601 | prefixMatch "powerpc-apple-darwin" cTARGETPLATFORM
603 -- Disable Apple's precompiling preprocessor. It's a great thing
604 -- for "normal" programs, but it doesn't support register variable
607 -- As we don't support haskell code in shared libraries anyway,
608 -- we might as well turn of PIC code generation and save space and time.
609 -- This is completely optional.
610 = return ( ["-no-cpp-precomp","-mdynamic-no-pic"], [] )
612 | prefixMatch "powerpc" cTARGETPLATFORM || prefixMatch "rs6000" cTARGETPLATFORM
613 = return ( ["-static"], ["-finhibit-size-directive"] )
618 -----------------------------------------------------------------------------
621 addOpt_L a = updDynFlags (\s -> s{opt_L = a : opt_L s})
622 addOpt_P a = updDynFlags (\s -> s{opt_P = a : opt_P s})
623 addOpt_F a = updDynFlags (\s -> s{opt_F = a : opt_F s})
624 addOpt_c a = updDynFlags (\s -> s{opt_c = a : opt_c s})
625 addOpt_a a = updDynFlags (\s -> s{opt_a = a : opt_a s})
626 addOpt_m a = updDynFlags (\s -> s{opt_m = a : opt_m s})
628 addOpt_I a = updDynFlags (\s -> s{opt_I = a : opt_I s})
629 addOpt_i a = updDynFlags (\s -> s{opt_i = a : opt_i s})
632 setVerbosity "" = updDynFlags (\dfs -> dfs{ verbosity = 3 })
634 | all isDigit n = updDynFlags (\dfs -> dfs{ verbosity = read n })
635 | otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
637 addCmdlineHCInclude a = updDynFlags (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})