link' Batch dflags batch_attempt_linking linkables
| batch_attempt_linking
- = do when (verb >= 1) $
- hPutStrLn stderr "ghc: linking ..."
+ = do
+ -- check for the -no-link flag
+ omit_linking <- readIORef v_NoLink
+ if omit_linking
+ then do when (verb >= 3) $
+ hPutStrLn stderr "link(batch): linking omitted (-no-link flag given)."
+ return Succeeded
+ else do
+
+ when (verb >= 1) $
+ hPutStrLn stderr "Linking ..."
-- Don't showPass in Batch mode; doLink will do that for us.
staticLink (concatMap getOfiles linkables)
++ filename ++ "'" ++ show pipeline ++ show stop_phase)))
let
-- .o and .hc suffixes can be overriden by command-line options:
- myPhaseInputExt Ln | Just s <- osuf = s
myPhaseInputExt HCc | Just s <- hcsuf = s
- myPhaseInputExt other = phaseInputExt other
+ myPhaseInputExt Ln = osuf
+ myPhaseInputExt other = phaseInputExt other
annotatePipeline
:: [Phase] -- raw pipeline
deps_normals <- mapM (findDependency False orig_fn) import_normals
let deps = deps_sources ++ deps_normals
- osuf_opt <- readIORef v_Object_suf
- let osuf = case osuf_opt of
- Nothing -> phaseInputExt Ln
- Just s -> s
+ osuf <- readIORef v_Object_suf
extra_suffixes <- readIORef v_Dep_suffixes
let suffixes = osuf : map (++ ('_':osuf)) extra_suffixes
-- we add the current directory (i.e. the directory in which
-- the .hs files resides) to the import path, since this is
-- what gcc does, and it's probably what you want.
- let current_dir = getdir basename
+ let current_dir = directoryOf basename
paths <- readIORef v_Include_paths
writeIORef v_Include_paths (current_dir : paths)
getImportsFromFile input_fn
-- build a ModLocation to pass to hscMain.
- (mod, location')
- <- mkHomeModuleLocn mod_name basename (basename ++ '.':suff)
+ let (path,file) = splitFilenameDir basename
+ (mod, location') <- mkHomeModLocation mod_name True path file suff
-- take -ohi into account if present
ohi <- readIORef v_Output_hi
let assemble_file n
= do let input_s = split_s_prefix ++ "__" ++ show n ++ ".s"
- let output_o = newdir real_odir
+ let output_o = replaceFilenameDirectory
(basename ++ "__" ++ show n ++ ".o")
+ real_odir
real_o <- osuf_ify output_o
SysTools.runAs (map SysTools.Option as_opts ++
[ SysTools.Option "-c"
lib_paths <- readIORef v_Library_paths
let lib_path_opts = map ("-L"++) lib_paths
- pkg_libs <- getPackageLibraries
- let imp = if static then "" else "_imp"
- pkg_lib_opts = map (\lib -> "-l" ++ lib ++ imp) pkg_libs
-
- libs <- readIORef v_Cmdline_libraries
- let lib_opts = map ("-l"++) (reverse libs)
- -- reverse because they're added in reverse order from the cmd line
+ pkg_link_opts <- getPackageLinkOpts
#ifdef darwin_TARGET_OS
pkg_framework_paths <- getPackageFrameworkPath
-- reverse because they're added in reverse order from the cmd line
#endif
- pkg_extra_ld_opts <- getPackageExtraLdOpts
-
-- probably _stub.o files
extra_ld_inputs <- readIORef v_Ld_inputs
- -- opts from -optl-<blah>
+ -- opts from -optl-<blah> (including -l<blah> options)
extra_ld_opts <- getStaticOpts v_Opt_l
- [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, preludePackage]
+ [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, basePackage]
let extra_os = if static || no_hs_main
then []
++ extra_os
++ extra_ld_inputs
++ lib_path_opts
- ++ lib_opts
+ ++ extra_ld_opts
#ifdef darwin_TARGET_OS
++ framework_path_opts
++ framework_opts
#endif
++ pkg_lib_path_opts
- ++ pkg_lib_opts
+ ++ pkg_link_opts
#ifdef darwin_TARGET_OS
++ pkg_framework_path_opts
++ pkg_framework_opts
#endif
- ++ pkg_extra_ld_opts
- ++ extra_ld_opts
++ if static && not no_hs_main then
[ "-u", prefixUnderscore "Main_zdmain_closure"]
else []))
lib_paths <- readIORef v_Library_paths
let lib_path_opts = map ("-L"++) lib_paths
- pkg_libs <- getPackageLibraries
- let imp = if static then "" else "_imp"
- pkg_lib_opts = map (\lib -> "-l" ++ lib ++ imp) pkg_libs
-
- libs <- readIORef v_Cmdline_libraries
- let lib_opts = map ("-l"++) (reverse libs)
- -- reverse because they're added in reverse order from the cmd line
-
- pkg_extra_ld_opts <- getPackageExtraLdOpts
+ pkg_link_opts <- getPackageLinkOpts
-- probably _stub.o files
extra_ld_inputs <- readIORef v_Ld_inputs
-- opts from -optdll-<blah>
extra_ld_opts <- getStaticOpts v_Opt_dll
- [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, preludePackage]
+ [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, basePackage]
let extra_os = if static || no_hs_main
then []
++ [ "--target=i386-mingw32" ]
++ extra_ld_inputs
++ lib_path_opts
- ++ lib_opts
+ ++ extra_ld_opts
++ pkg_lib_path_opts
- ++ pkg_lib_opts
- ++ pkg_extra_ld_opts
+ ++ pkg_link_opts
++ (if "--def" `elem` (concatMap words extra_ld_opts)
then [ "" ]
else [ "--export-all" ])
- ++ extra_ld_opts
))