-outputC dflags filenm flat_absC (stub_h_exists, _)
- = do dumpIfSet_dyn dflags Opt_D_dump_realC "Real C" (dumpRealC flat_absC)
- header <- readIORef v_HCHeader
+outputC dflags filenm flat_absC
+ (stub_h_exists, _) dependencies foreign_stubs
+ = do
+ -- figure out which header files to #include in the generated .hc file:
+ --
+ -- * extra_includes from packages
+ -- * -#include options from the cmdline and OPTIONS pragmas
+ -- * the _stub.h file, if there is one.
+ --
+ let packages = dep_pkgs dependencies
+ pkg_configs <- getExplicitPackagesAnd packages
+ let pkg_names = map name pkg_configs
+
+ c_includes <- getPackageCIncludes pkg_configs
+ let cmdline_includes = cmdlineHcIncludes dflags -- -#include options
+
+ ffi_decl_headers
+ = case foreign_stubs of
+ NoStubs -> []
+ ForeignStubs _ _ fdhs _ -> map unpackFS (fst (removeDupsEq fdhs))
+ -- Remove duplicates, because distinct foreign import decls
+ -- may cite the same #include. Order doesn't matter.
+
+ all_headers = c_includes
+ ++ reverse cmdline_includes
+ ++ ffi_decl_headers
+
+ let cc_injects = unlines (map mk_include all_headers)
+ mk_include h_file =
+ case h_file of
+ '"':_{-"-} -> "#include "++h_file
+ '<':_ -> "#include "++h_file
+ _ -> "#include \""++h_file++"\""
+