-- at which stage to stop.
--
-- The DynFlags can be modified by phases in the pipeline (eg. by
--- GHC_OPTIONS pragmas), and the changes affect later phases in the
+-- OPTIONS_GHC pragmas), and the changes affect later phases in the
-- pipeline.
runPipeline
:: GhcMonad m =>
-- might be a hierarchical module.
createDirectoryHierarchy (takeDirectory output_fn)
+ let (md_c_flags, _) = machdepCCOpts dflags
SysTools.runAs dflags
(map SysTools.Option as_opts
++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
, SysTools.FileOption "" input_fn
, SysTools.Option "-o"
, SysTools.FileOption "" output_fn
- ])
+ ]
+ ++ map SysTools.Option md_c_flags)
return (StopLn, dflags, maybe_loc, output_fn)
split_obj n = split_odir </>
takeFileName base_o ++ "__" ++ show n <.> osuf
+ let (md_c_flags, _) = machdepCCOpts dflags
let assemble_file n
= SysTools.runAs dflags
(map SysTools.Option as_opts ++
, SysTools.Option "-o"
, SysTools.FileOption "" (split_obj n)
, SysTools.FileOption "" (split_s n)
- ])
+ ]
+ ++ map SysTools.Option md_c_flags)
mapM_ assemble_file [1..n]
SysTools.Option "-Wl,-r",
SysTools.Option ld_x_flag,
SysTools.Option "-o",
- SysTools.FileOption "" output_fn ] ++ args)
+ SysTools.FileOption "" output_fn ]
+ ++ map SysTools.Option md_c_flags
+ ++ args)
ld_x_flag | null cLD_X = ""
| otherwise = "-Wl,-x"
let lib_paths = libraryPaths dflags
let lib_path_opts = map ("-L"++) lib_paths
+ -- The C "main" function is not in the rts but in a separate static
+ -- library libHSrtsmain.a that sits next to the rts lib files. Assuming
+ -- we're using a Haskell main function then we need to link it in.
+ let no_hs_main = dopt Opt_NoHsMain dflags
+ let main_lib | no_hs_main = []
+ | otherwise = [ "-lHSrtsmain" ]
+
pkg_link_opts <- getPackageLinkOpts dflags dep_packages
#ifdef darwin_TARGET_OS
framework_opts = concat [ ["-framework", fw] | fw <- reverse frameworks ]
-- reverse because they're added in reverse order from the cmd line
#endif
-#ifdef mingw32_TARGET_OS
- let dynMain = if not opt_Static then
- (head (libraryDirs (getPackageDetails (pkgState dflags) rtsPackageId))) ++ "/Main.dyn_o"
- else
- ""
-#endif
-- probably _stub.o files
extra_ld_inputs <- readIORef v_Ld_inputs
++ map SysTools.Option (
md_c_flags
++ o_files
-#ifdef mingw32_TARGET_OS
- ++ [dynMain]
-#endif
++ extra_ld_inputs
++ lib_path_opts
++ extra_ld_opts
++ framework_opts
#endif
++ pkg_lib_path_opts
+ ++ main_lib
++ pkg_link_opts
#ifdef darwin_TARGET_OS
++ pkg_framework_path_opts
let pkgs_no_rts = pkgs
#endif
let pkg_lib_paths = collectLibraryPaths pkgs_no_rts
- let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
+ let pkg_lib_path_opts = concatMap get_pkg_lib_path_opts pkg_lib_paths
+#ifdef linux_TARGET_OS
+ get_pkg_lib_path_opts l | (dynLibLoader dflags)==SystemDependent && not opt_Static = ["-L" ++ l, "-Wl,-rpath", "-Wl," ++ l]
+ | otherwise = ["-L" ++ l]
+#else
+ get_pkg_lib_path_opts l = ["-L" ++ l]
+#endif
let lib_paths = libraryPaths dflags
let lib_path_opts = map ("-L"++) lib_paths
md_c_flags
++ o_files
++ [ "-shared", "-Wl,-Bsymbolic" ] -- we need symbolic linking to resolve non-PIC intra-package-relocations
+ ++ [ "-Wl,-soname," ++ takeFileName output_fn ] -- set the library soname
++ extra_ld_inputs
++ lib_path_opts
++ extra_ld_opts