-----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.56 2001/03/22 03:51:08 hwloidl Exp $
+-- $Id: DriverPipeline.hs,v 1.57 2001/03/23 16:36:20 simonmar Exp $
--
-- GHC Driver
--
run_phase Cpp basename suff input_fn output_fn
= do src_opts <- getOptionsFromSource input_fn
unhandled_flags <- processArgs dynamic_flags src_opts []
-
- when (not (null unhandled_flags))
- (throwDyn (OtherError (
- basename ++ "." ++ suff
- ++ ": static flags are not allowed in {-# OPTIONS #-} pragmas:\n\t"
- ++ unwords unhandled_flags)) (ExitFailure 1))
+ checkProcessArgsResult unhandled_flags basename suff
do_cpp <- dynFlag cppFlag
if do_cpp
Nothing -> basename ++ '.':hisuf
Just fn -> fn
+ -- figure out which header files to #include in a generated .hc file
+ c_includes <- getPackageCIncludes
+ cmdline_includes <- dynFlag cmdlineHcIncludes -- -#include options
+
+ let cc_injects = unlines (map mk_include
+ (c_includes ++ reverse cmdline_includes))
+ mk_include h_file =
+ case h_file of
+ '"':_{-"-} -> "#include "++h_file
+ '<':_ -> "#include "++h_file
+ _ -> "#include \""++h_file++"\""
+
+ writeIORef v_HCHeader cc_injects
+
-- figure out if the source has changed, for recompilation avoidance.
-- only do this if we're eventually going to generate a .o file.
-- (ToDo: do when generating .hc files too?)
-- we don't support preprocessing .c files (with -E) now. Doing so introduces
-- way too many hacks, and I can't say I've ever used it anyway.
-run_phase cc_phase _basename _suff input_fn output_fn
+run_phase cc_phase basename suff input_fn output_fn
| cc_phase == Cc || cc_phase == HCc
= do cc <- readIORef v_Pgm_c
cc_opts <- (getOpts opt_c)
let include_paths = map (\p -> "-I"++p) (cmdline_include_dirs
++ pkg_include_dirs)
- c_includes <- getPackageCIncludes
- cmdline_includes <- dynFlag cmdlineHcIncludes -- -#include options
-
- let cc_injects | hcc = unlines (map mk_include
- (c_includes ++ reverse cmdline_includes))
- | otherwise = ""
- mk_include h_file =
- case h_file of
- '"':_{-"-} -> "#include "++h_file
- '<':_ -> "#include "++h_file
- _ -> "#include \""++h_file++"\""
-
- cc_help <- newTempName "c"
- h <- openFile cc_help WriteMode
- hPutStr h cc_injects
- hPutStrLn h ("#include \"" ++ input_fn ++ "\"\n")
- hClose h
-
- ccout <- newTempName "ccout"
-
mangle <- readIORef v_Do_asm_mangling
(md_c_flags, md_regd_c_flags) <- machdepCCOpts
excessPrecision <- readIORef v_Excess_precision
runSomething "C Compiler"
- (unwords ([ cc, "-x", "c", cc_help, "-o", output_fn ]
+ (unwords ([ cc, "-x", "c", input_fn, "-o", output_fn ]
++ md_c_flags
++ (if cc_phase == HCc && mangle
then md_regd_c_flags
++ (if excessPrecision then [] else [ "-ffloat-store" ])
++ include_paths
++ pkg_extra_cc_opts
--- ++ [">", ccout]
))
return True
]
-----------------------------------------------------------------------------
+-- Complain about non-dynamic flags in OPTIONS pragmas
+
+checkProcessArgsResult flags basename suff
+ = do when (not (null flags)) (throwDyn (OtherError (
+ basename ++ "." ++ suff
+ ++ ": static flags are not allowed in {-# OPTIONS #-} pragmas:\n\t"
+ ++ unwords flags)) (ExitFailure 1))
+
+-----------------------------------------------------------------------------
-- Linking
doLink :: [String] -> IO ()