1 -----------------------------------------------------------------------------
2 -- $Id: DriverFlags.hs,v 1.119 2003/08/11 08:53:39 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) )
228 , ( "main-is" , SepArg setMainIs )
230 ------- Output Redirection ------------------------------------------
231 , ( "odir" , HasArg (writeIORef v_Output_dir . Just) )
232 , ( "o" , SepArg (writeIORef v_Output_file . Just) )
233 , ( "osuf" , HasArg (writeIORef v_Object_suf) )
234 , ( "hcsuf" , HasArg (writeIORef v_HC_suf . Just) )
235 , ( "hisuf" , HasArg (writeIORef v_Hi_suf) )
236 , ( "hidir" , HasArg (writeIORef v_Hi_dir . Just) )
237 , ( "buildtag" , HasArg (writeIORef v_Build_tag) )
238 , ( "tmpdir" , HasArg setTmpDir)
239 , ( "ohi" , HasArg (writeIORef v_Output_hi . Just) )
242 , ( "keep-hc-file" , AnySuffix (\_ -> writeIORef v_Keep_hc_files True) )
243 , ( "keep-s-file" , AnySuffix (\_ -> writeIORef v_Keep_s_files True) )
244 , ( "keep-raw-s-file", AnySuffix (\_ -> writeIORef v_Keep_raw_s_files True) )
246 , ( "keep-il-file" , AnySuffix (\_ -> writeIORef v_Keep_il_files True) )
247 , ( "keep-ilx-file" , AnySuffix (\_ -> writeIORef v_Keep_ilx_files True) )
249 , ( "keep-tmp-files" , AnySuffix (\_ -> writeIORef v_Keep_tmp_files True) )
251 , ( "split-objs" , NoArg (if can_split
252 then do writeIORef v_Split_object_files True
253 add v_Opt_C "-fglobalise-toplev-names"
254 else hPutStrLn stderr
255 "warning: don't know how to split \
256 \object files on this architecture"
259 ------- Include/Import Paths ----------------------------------------
260 , ( "i" , OptPrefix (addToDirList v_Import_paths) )
261 , ( "I" , Prefix (addToDirList v_Include_paths) )
263 ------- Libraries ---------------------------------------------------
264 , ( "L" , Prefix (addToDirList v_Library_paths) )
265 , ( "l" , AnySuffix (\s -> add v_Opt_l s >> add v_Opt_dll s) )
267 #ifdef darwin_TARGET_OS
268 ------- Frameworks --------------------------------------------------
269 -- -framework-path should really be -F ...
270 , ( "framework-path" , HasArg (addToDirList v_Framework_paths) )
271 , ( "framework" , HasArg (add v_Cmdline_frameworks) )
273 ------- Packages ----------------------------------------------------
274 , ( "package-name" , HasArg (\s -> add v_Opt_C ("-inpackage="++s)) )
276 , ( "package-conf" , HasArg (readPackageConf) )
277 , ( "package" , HasArg (addPackage) )
278 , ( "syslib" , HasArg (addPackage) ) -- for compatibility w/ old vsns
280 ------- Specific phases --------------------------------------------
281 , ( "pgmL" , HasArg setPgmL )
282 , ( "pgmP" , HasArg setPgmP )
283 , ( "pgmP" , HasArg setPgmP )
284 , ( "pgmF" , HasArg setPgmF )
285 , ( "pgmc" , HasArg setPgmc )
286 , ( "pgmm" , HasArg setPgmm )
287 , ( "pgms" , HasArg setPgms )
288 , ( "pgma" , HasArg setPgma )
289 , ( "pgml" , HasArg setPgml )
291 , ( "pgmI" , HasArg setPgmI )
292 , ( "pgmi" , HasArg setPgmi )
295 , ( "optdep" , HasArg (add v_Opt_dep) )
296 , ( "optl" , HasArg (add v_Opt_l) )
297 , ( "optdll" , HasArg (add v_Opt_dll) )
299 ----- Linker --------------------------------------------------------
300 , ( "no-link" , NoArg (writeIORef v_NoLink True) )
301 , ( "static" , NoArg (writeIORef v_Static True) )
302 , ( "dynamic" , NoArg (writeIORef v_Static False) )
303 , ( "rdynamic" , NoArg (return ()) ) -- ignored for compat w/ gcc
305 ----- RTS opts ------------------------------------------------------
306 , ( "H" , HasArg (setHeapSize . fromIntegral . decodeSize) )
307 , ( "Rghc-timing" , NoArg (enableTimingStats) )
309 ------ Compiler flags -----------------------------------------------
310 , ( "O2-for-C" , NoArg (writeIORef v_minus_o2_for_C True) )
311 , ( "O" , NoArg (setOptLevel 1))
312 , ( "Onot" , NoArg (setOptLevel 0))
313 , ( "O" , PrefixPred (all isDigit) (setOptLevel . read))
315 , ( "fno-asm-mangling" , NoArg (writeIORef v_Do_asm_mangling False) )
317 , ( "fmax-simplifier-iterations",
318 PrefixPred (all isDigit) (writeIORef v_MaxSimplifierIterations . read) )
321 SepArg (\s -> writeIORef v_RuleCheck (Just s)) )
323 , ( "fexcess-precision" , NoArg (do writeIORef v_Excess_precision True
324 add v_Opt_C "-fexcess-precision"))
326 -- Optimisation flags are treated specially, so the normal
327 -- -fno-* pattern below doesn't work. We therefore allow
328 -- certain optimisation passes to be turned off explicitly:
329 , ( "fno-strictness" , NoArg (writeIORef v_Strictness False) )
330 , ( "fno-cse" , NoArg (writeIORef v_CSE False) )
332 -- All other "-fno-<blah>" options cancel out "-f<blah>" on the hsc cmdline
333 , ( "fno-", PrefixPred (\s -> isStaticHscFlag ("f"++s))
334 (\s -> add v_Anti_opt_C ("-f"++s)) )
336 -- Pass all remaining "-f<blah>" options to hsc
337 , ( "f", AnySuffixPred (isStaticHscFlag) (add v_Opt_C) )
342 ( "cpp", NoArg (updDynFlags (\s -> s{ cppFlag = True })) )
343 , ( "F", NoArg (updDynFlags (\s -> s{ ppFlag = True })) )
344 , ( "#include", HasArg (addCmdlineHCInclude) )
346 , ( "v", OptPrefix (setVerbosity) )
348 , ( "optL", HasArg (addOpt_L) )
349 , ( "optP", HasArg (addOpt_P) )
350 , ( "optF", HasArg (addOpt_F) )
351 , ( "optc", HasArg (addOpt_c) )
352 , ( "optm", HasArg (addOpt_m) )
353 , ( "opta", HasArg (addOpt_a) )
355 , ( "optI", HasArg (addOpt_I) )
356 , ( "opti", HasArg (addOpt_i) )
359 ------ HsCpp opts ---------------------------------------------------
360 , ( "D", AnySuffix addOpt_P )
361 , ( "U", AnySuffix addOpt_P )
363 ------ Debugging ----------------------------------------------------
364 , ( "dstg-stats", NoArg (writeIORef v_StgStats True) )
366 , ( "ddump-absC", NoArg (setDynFlag Opt_D_dump_absC) )
367 , ( "ddump-asm", NoArg (setDynFlag Opt_D_dump_asm) )
368 , ( "ddump-cpranal", NoArg (setDynFlag Opt_D_dump_cpranal) )
369 , ( "ddump-deriv", NoArg (setDynFlag Opt_D_dump_deriv) )
370 , ( "ddump-ds", NoArg (setDynFlag Opt_D_dump_ds) )
371 , ( "ddump-flatC", NoArg (setDynFlag Opt_D_dump_flatC) )
372 , ( "ddump-foreign", NoArg (setDynFlag Opt_D_dump_foreign) )
373 , ( "ddump-inlinings", NoArg (setDynFlag Opt_D_dump_inlinings) )
374 , ( "ddump-occur-anal", NoArg (setDynFlag Opt_D_dump_occur_anal) )
375 , ( "ddump-parsed", NoArg (setDynFlag Opt_D_dump_parsed) )
376 , ( "ddump-realC", NoArg (setDynFlag Opt_D_dump_realC) )
377 , ( "ddump-rn", NoArg (setDynFlag Opt_D_dump_rn) )
378 , ( "ddump-simpl", NoArg (setDynFlag Opt_D_dump_simpl) )
379 , ( "ddump-simpl-iterations", NoArg (setDynFlag Opt_D_dump_simpl_iterations) )
380 , ( "ddump-spec", NoArg (setDynFlag Opt_D_dump_spec) )
381 , ( "ddump-prep", NoArg (setDynFlag Opt_D_dump_prep) )
382 , ( "ddump-stg", NoArg (setDynFlag Opt_D_dump_stg) )
383 , ( "ddump-stranal", NoArg (setDynFlag Opt_D_dump_stranal) )
384 , ( "ddump-tc", NoArg (setDynFlag Opt_D_dump_tc) )
385 , ( "ddump-types", NoArg (setDynFlag Opt_D_dump_types) )
386 , ( "ddump-rules", NoArg (setDynFlag Opt_D_dump_rules) )
387 , ( "ddump-cse", NoArg (setDynFlag Opt_D_dump_cse) )
388 , ( "ddump-worker-wrapper", NoArg (setDynFlag Opt_D_dump_worker_wrapper) )
389 , ( "dshow-passes", NoArg (setVerbosity "2") )
390 , ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace) )
391 , ( "ddump-tc-trace", NoArg (setDynFlag Opt_D_dump_tc_trace) )
392 , ( "ddump-splices", NoArg (setDynFlag Opt_D_dump_splices) )
393 , ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats) )
394 , ( "ddump-stix", NoArg (setDynFlag Opt_D_dump_stix) )
395 , ( "ddump-simpl-stats", NoArg (setDynFlag Opt_D_dump_simpl_stats) )
396 , ( "ddump-bcos", NoArg (setDynFlag Opt_D_dump_BCOs) )
397 , ( "dsource-stats", NoArg (setDynFlag Opt_D_source_stats) )
398 , ( "dverbose-core2core", NoArg (setDynFlag Opt_D_verbose_core2core) )
399 , ( "dverbose-stg2stg", NoArg (setDynFlag Opt_D_verbose_stg2stg) )
400 , ( "ddump-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs) )
401 , ( "ddump-hi", NoArg (setDynFlag Opt_D_dump_hi) )
402 , ( "ddump-minimal-imports", NoArg (setDynFlag Opt_D_dump_minimal_imports) )
403 , ( "ddump-vect", NoArg (setDynFlag Opt_D_dump_vect) )
404 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting) )
405 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting) )
407 ------ Machine dependant (-m<blah>) stuff ---------------------------
409 , ( "monly-2-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 2}) ))
410 , ( "monly-3-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 3}) ))
411 , ( "monly-4-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 4}) ))
413 ------ Warning opts -------------------------------------------------
414 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
415 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
416 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
417 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
418 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
420 ------ Compiler flags -----------------------------------------------
422 , ( "fasm", AnySuffix (\_ -> setLang HscAsm) )
423 , ( "fvia-c", NoArg (setLang HscC) )
424 , ( "fvia-C", NoArg (setLang HscC) )
425 , ( "filx", NoArg (setLang HscILX) )
427 -- "active negatives"
428 , ( "fno-implicit-prelude", NoArg (setDynFlag Opt_NoImplicitPrelude) )
429 , ( "fno-monomorphism-restriction",
430 NoArg (setDynFlag Opt_NoMonomorphismRestriction) )
432 -- the rest of the -f* and -fno-* flags
433 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
434 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
437 -- these -f<blah> flags can all be reversed with -fno-<blah>
440 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
441 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
442 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
443 ( "warn-missing-fields", Opt_WarnMissingFields ),
444 ( "warn-missing-methods", Opt_WarnMissingMethods ),
445 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
446 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
447 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
448 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
449 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
450 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
451 ( "warn-unused-imports", Opt_WarnUnusedImports ),
452 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
453 ( "warn-deprecations", Opt_WarnDeprecations ),
454 ( "glasgow-exts", Opt_GlasgowExts ),
455 ( "fi", Opt_FFI ), -- support `-ffi'...
456 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
457 ( "with", Opt_With ), -- with keyword
458 ( "arrows", Opt_Arrows ), -- arrow syntax
459 ( "parr", Opt_PArr ),
460 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
461 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
462 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
463 ( "generics", Opt_Generics )
466 isFFlag f = f `elem` (map fst fFlags)
467 getFFlag f = fromJust (lookup f fFlags)
469 -----------------------------------------------------------------------------
470 -- convert sizes like "3.5M" into integers
472 decodeSize :: String -> Integer
474 | c == "" = truncate n
475 | c == "K" || c == "k" = truncate (n * 1000)
476 | c == "M" || c == "m" = truncate (n * 1000 * 1000)
477 | c == "G" || c == "g" = truncate (n * 1000 * 1000 * 1000)
478 | otherwise = throwDyn (CmdLineError ("can't decode size: " ++ str))
479 where (m, c) = span pred str
481 pred c = isDigit c || c == '.'
484 -----------------------------------------------------------------------------
487 #if __GLASGOW_HASKELL__ >= 504
488 foreign import ccall unsafe "setHeapSize" setHeapSize :: Int -> IO ()
489 foreign import ccall unsafe "enableTimingStats" enableTimingStats :: IO ()
491 foreign import "setHeapSize" unsafe setHeapSize :: Int -> IO ()
492 foreign import "enableTimingStats" unsafe enableTimingStats :: IO ()
495 -----------------------------------------------------------------------------
496 -- Build the Hsc static command line opts
498 buildStaticHscOpts :: IO [String]
499 buildStaticHscOpts = do
501 opt_C_ <- getStaticOpts v_Opt_C -- misc hsc opts from the command line
504 minus_o <- readIORef v_OptLevel
505 let optimisation_opts =
507 0 -> hsc_minusNoO_flags
508 1 -> hsc_minusO_flags
509 2 -> hsc_minusO2_flags
510 n -> throwDyn (CmdLineError ("unknown optimisation level: "
514 -- take into account -fno-* flags by removing the equivalent -f*
515 -- flag from our list.
516 anti_flags <- getStaticOpts v_Anti_opt_C
517 let basic_opts = opt_C_ ++ optimisation_opts
518 filtered_opts = filter (`notElem` anti_flags) basic_opts
520 static <- (do s <- readIORef v_Static; if s then return "-static"
523 return ( static : filtered_opts )
525 setMainIs :: String -> IO ()
527 | not (null main_mod) -- The arg looked like "Foo.baz"
528 = do { writeIORef v_MainFunIs (Just main_fn) ;
529 writeIORef v_MainModIs (Just main_mod) }
531 | isUpper (head main_fn) -- The arg looked like "Foo"
532 = writeIORef v_MainModIs (Just main_fn)
534 | otherwise -- The arg looked like "baz"
535 = writeIORef v_MainFunIs (Just main_fn)
537 (main_mod, main_fn) = split_longest_prefix arg (== '.')
540 -----------------------------------------------------------------------------
541 -- Via-C compilation stuff
543 -- flags returned are: ( all C compilations
544 -- , registerised HC compilations
548 | prefixMatch "alpha" cTARGETPLATFORM
549 = return ( ["-static", "-w", "-mieee"
550 #ifdef HAVE_THREADED_RTS_SUPPORT
554 -- For now, to suppress the gcc warning "call-clobbered
555 -- register used for global register variable", we simply
556 -- disable all warnings altogether using the -w flag. Oh well.
558 | prefixMatch "hppa" cTARGETPLATFORM
559 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
560 -- (very nice, but too bad the HP /usr/include files don't agree.)
561 = return ( ["-static", "-D_HPUX_SOURCE"], [] )
563 | prefixMatch "m68k" cTARGETPLATFORM
564 -- -fno-defer-pop : for the .hc files, we want all the pushing/
565 -- popping of args to routines to be explicit; if we let things
566 -- be deferred 'til after an STGJUMP, imminent death is certain!
568 -- -fomit-frame-pointer : *don't*
569 -- It's better to have a6 completely tied up being a frame pointer
570 -- rather than let GCC pick random things to do with it.
571 -- (If we want to steal a6, then we would try to do things
572 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
573 = return ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
575 | prefixMatch "i386" cTARGETPLATFORM
576 -- -fno-defer-pop : basically the same game as for m68k
578 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
579 -- the fp (%ebp) for our register maps.
580 = do n_regs <- dynFlag stolen_x86_regs
581 sta <- readIORef v_Static
582 return ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
583 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
586 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
587 -- Some gccs are configured with
588 -- -momit-leaf-frame-pointer on by default, and it
589 -- apparently takes precedence over
590 -- -fomit-frame-pointer, so we disable it first here.
591 "-mno-omit-leaf-frame-pointer",
593 "-fomit-frame-pointer",
594 -- we want -fno-builtin, because when gcc inlines
595 -- built-in functions like memcpy() it tends to
596 -- run out of registers, requiring -monly-n-regs
598 "-DSTOLEN_X86_REGS="++show n_regs ]
601 | prefixMatch "ia64" cTARGETPLATFORM
602 = return ( [], ["-fomit-frame-pointer", "-G0"] )
604 | prefixMatch "mips" cTARGETPLATFORM
605 = return ( ["-static"], [] )
607 | prefixMatch "sparc" cTARGETPLATFORM
608 = return ( [], ["-w"] )
609 -- For now, to suppress the gcc warning "call-clobbered
610 -- register used for global register variable", we simply
611 -- disable all warnings altogether using the -w flag. Oh well.
613 | prefixMatch "powerpc-apple-darwin" cTARGETPLATFORM
615 -- Disable Apple's precompiling preprocessor. It's a great thing
616 -- for "normal" programs, but it doesn't support register variable
619 -- As we don't support haskell code in shared libraries anyway,
620 -- we might as well turn of PIC code generation and save space and time.
621 -- This is completely optional.
622 = return ( ["-no-cpp-precomp","-mdynamic-no-pic"], [] )
624 | prefixMatch "powerpc" cTARGETPLATFORM || prefixMatch "rs6000" cTARGETPLATFORM
625 = return ( ["-static"], ["-finhibit-size-directive"] )
630 -----------------------------------------------------------------------------
633 addOpt_L a = updDynFlags (\s -> s{opt_L = a : opt_L s})
634 addOpt_P a = updDynFlags (\s -> s{opt_P = a : opt_P s})
635 addOpt_F a = updDynFlags (\s -> s{opt_F = a : opt_F s})
636 addOpt_c a = updDynFlags (\s -> s{opt_c = a : opt_c s})
637 addOpt_a a = updDynFlags (\s -> s{opt_a = a : opt_a s})
638 addOpt_m a = updDynFlags (\s -> s{opt_m = a : opt_m s})
640 addOpt_I a = updDynFlags (\s -> s{opt_I = a : opt_I s})
641 addOpt_i a = updDynFlags (\s -> s{opt_i = a : opt_i s})
644 setVerbosity "" = updDynFlags (\dfs -> dfs{ verbosity = 3 })
646 | all isDigit n = updDynFlags (\dfs -> dfs{ verbosity = read n })
647 | otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
649 addCmdlineHCInclude a = updDynFlags (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})