-----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.95 2001/08/03 07:44:47 sof Exp $
+-- $Id: DriverPipeline.hs,v 1.96 2001/08/10 23:08:25 sof Exp $
--
-- GHC Driver
--
-- The -h option passes the file name for unlit to put in a #line directive;
-- we undosify it so that it doesn't contain backslashes in Windows, which
-- would disappear in error messages
- SysTools.runUnlit (unlit_flags ++ ["-h", unDosifyPath input_fn, input_fn, output_fn])
+ SysTools.runUnlit (map SysTools.Option unlit_flags ++
+ [ SysTools.Option "-h"
+ , SysTools.Option input_fn
+ , SysTools.FileOption input_fn
+ , SysTools.FileOption output_fn
+ ])
return (Just output_fn)
-------------------------------------------------------------------------------
verb <- getVerbFlag
(md_c_flags, _) <- machdepCCOpts
- SysTools.runCpp ([verb]
- ++ include_paths
- ++ hs_src_cpp_opts
- ++ hscpp_opts
- ++ md_c_flags
- ++ [ "-x", "c", input_fn, "-o", output_fn ])
+ SysTools.runCpp ([SysTools.Option verb]
+ ++ map SysTools.Option include_paths
+ ++ map SysTools.Option hs_src_cpp_opts
+ ++ map SysTools.Option hscpp_opts
+ ++ map SysTools.Option md_c_flags
+ ++ [ SysTools.Option "-x c"
+ , SysTools.FileOption input_fn
+ , SysTools.Option "-o"
+ , SysTools.FileOption output_fn
+ ])
return (Just output_fn)
-----------------------------------------------------------------------------
| otherwise = [ ]
excessPrecision <- readIORef v_Excess_precision
- SysTools.runCc ([ "-x", "c", input_fn, "-o", output_fn ]
- ++ md_c_flags
+ SysTools.runCc ([ SysTools.Option "-x c"
+ , SysTools.FileOption input_fn
+ , SysTools.Option "-o"
+ , SysTools.FileOption output_fn
+ ]
+ ++ map SysTools.Option (
+ md_c_flags
++ (if cc_phase == HCc && mangle
then md_regd_c_flags
else [])
++ (if excessPrecision then [] else [ "-ffloat-store" ])
++ include_paths
++ pkg_extra_cc_opts
- )
+ ))
return (Just output_fn)
-- ToDo: postprocess the output from gcc
return [ show n_regs ]
else return []
- SysTools.runMangle (mangler_opts
- ++ [ input_fn, output_fn ]
- ++ machdep_opts)
+ SysTools.runMangle (map SysTools.Option mangler_opts
+ ++ [ SysTools.FileOption input_fn
+ , SysTools.FileOption output_fn
+ ]
+ ++ map SysTools.Option machdep_opts)
return (Just output_fn)
-----------------------------------------------------------------------------
split_s_prefix <- SysTools.newTempName "split"
let n_files_fn = split_s_prefix
- SysTools.runSplit [input_fn, split_s_prefix, n_files_fn]
+ SysTools.runSplit [ SysTools.FileOption input_fn
+ , SysTools.FileOption split_s_prefix
+ , SysTools.FileOption n_files_fn
+ ]
-- Save the number of split files for future references
s <- readFile n_files_fn
= do as_opts <- getOpts opt_a
cmdline_include_paths <- readIORef v_Include_paths
- SysTools.runAs (as_opts
- ++ [ "-I" ++ p | p <- cmdline_include_paths ]
- ++ [ "-c", input_fn, "-o", output_fn ])
+ SysTools.runAs (map SysTools.Option as_opts
+ ++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
+ ++ [ SysTools.Option "-c"
+ , SysTools.FileOption input_fn
+ , SysTools.Option "-o"
+ , SysTools.FileOption output_fn
+ ])
return (Just output_fn)
run_phase SplitAs basename _suff _input_fn output_fn
let output_o = newdir real_odir
(basename ++ "__" ++ show n ++ ".o")
real_o <- osuf_ify output_o
- SysTools.runAs (as_opts ++ ["-c", "-o", real_o, input_s])
+ SysTools.runAs (map SysTools.Option as_opts ++
+ [ SysTools.Option "-c"
+ , SysTools.Option "-o"
+ , SysTools.FileOption real_o
+ , SysTools.FileOption input_s
+ ])
mapM_ assemble_file [1..n]
return (Just output_fn)
head (library_dirs (head std_pkg)) ++ "/PrelMain.dll_o" ]
(md_c_flags, _) <- machdepCCOpts
- SysTools.runLink ( [verb, "-o", output_fn]
- ++ md_c_flags
+ SysTools.runLink ( [ SysTools.Option verb
+ , SysTools.Option "-o"
+ , SysTools.FileOption output_fn
+ ]
+ ++ map SysTools.Option (
+ md_c_flags
++ o_files
++ extra_os
++ extra_ld_inputs
[ "-u", prefixUnderscore "PrelMain_mainIO_closure" ,
"-u", prefixUnderscore "__init_PrelMain"]
#endif
- else [])
+ else []))
-- parallel only: move binary to another dir -- HWL
ways_ <- readIORef v_Ways
(md_c_flags, _) <- machdepCCOpts
SysTools.runMkDLL
- ([ verb, "-o", output_fn ]
- ++ md_c_flags
+ ([ SysTools.Option verb
+ , SysTools.Option "-o"
+ , SysTools.FileOption output_fn
+ ]
+ ++ map SysTools.Option (
+ md_c_flags
++ o_files
++ extra_os
++ [ "--target=i386-mingw32" ]
Nothing -> [ "--export-all" ]
Just _ -> [ "" ])
++ extra_ld_opts
- )
+ ))
-----------------------------------------------------------------------------
-- Just preprocess a file, put the result in a temp. file (used by the
-- Where package.conf is
-- Interface to system tools
- runUnlit, runCpp, runCc,-- [String] -> IO ()
- runMangle, runSplit, -- [String] -> IO ()
- runAs, runLink, -- [String] -> IO ()
+ runUnlit, runCpp, runCc, -- [Option] -> IO ()
+ runMangle, runSplit, -- [Option] -> IO ()
+ runAs, runLink, -- [Option] -> IO ()
runMkDLL,
touch, -- String -> String -> IO ()
-- Misc
showGhcUsage, -- IO () Shows usage message and exits
- getSysMan -- IO String Parallel system only
+ getSysMan, -- IO String Parallel system only
+
+ Option(..)
) where
%************************************************************************
%* *
+\subsection{Command-line options}
+n%* *
+%************************************************************************
+
+When invoking external tools as part of the compilation pipeline, we
+pass these a sequence of options on the command-line. Rather than
+just using a list of Strings, we use a type that allows us to distinguish
+between filepaths and 'other stuff'. [The reason being, of course, that
+this type gives us a handle on transforming filenames, and filenames only,
+to whatever format they're expected to be on a particular platform.]
+
+
+\begin{code}
+data Option
+ = FileOption String
+ | Option String
+
+showOptions :: [Option] -> String
+showOptions ls = unwords (map (quote.showOpt) ls)
+ where
+ showOpt (FileOption f) = dosifyPath f
+ showOpt (Option s) = s
+
+#if defined(mingw32_TARGET_OS)
+ quote "" = ""
+ quote s = "\"" ++ s ++ "\""
+#else
+ quote = id
+#endif
+
+\end{code}
+
+
+%************************************************************************
+%* *
\subsection{Running an external program}
n%* *
%************************************************************************
\begin{code}
-runUnlit :: [String] -> IO ()
+runUnlit :: [Option] -> IO ()
runUnlit args = do p <- readIORef v_Pgm_L
runSomething "Literate pre-processor" p args
-runCpp :: [String] -> IO ()
+runCpp :: [Option] -> IO ()
runCpp args = do p <- readIORef v_Pgm_P
runSomething "C pre-processor" p args
-runCc :: [String] -> IO ()
+runCc :: [Option] -> IO ()
runCc args = do p <- readIORef v_Pgm_c
runSomething "C Compiler" p args
-runMangle :: [String] -> IO ()
+runMangle :: [Option] -> IO ()
runMangle args = do p <- readIORef v_Pgm_m
runSomething "Mangler" p args
-runSplit :: [String] -> IO ()
+runSplit :: [Option] -> IO ()
runSplit args = do p <- readIORef v_Pgm_s
runSomething "Splitter" p args
-runAs :: [String] -> IO ()
+runAs :: [Option] -> IO ()
runAs args = do p <- readIORef v_Pgm_a
runSomething "Assembler" p args
-runLink :: [String] -> IO ()
+runLink :: [Option] -> IO ()
runLink args = do p <- readIORef v_Pgm_l
runSomething "Linker" p args
-runMkDLL :: [String] -> IO ()
+runMkDLL :: [Option] -> IO ()
runMkDLL args = do p <- readIORef v_Pgm_MkDLL
runSomething "Make DLL" p args
touch :: String -> String -> IO ()
touch purpose arg = do p <- readIORef v_Pgm_T
- runSomething purpose p [arg]
+ runSomething purpose p [FileOption arg]
copy :: String -> String -> String -> IO ()
copy purpose from to = do
runSomething :: String -- For -v message
-> String -- Command name (possibly a full path)
-- assumed already dos-ified
- -> [String] -- Arguments
+ -> [Option] -- Arguments
-- runSomething will dos-ify them
-> IO ()
else return ()
}
where
- cmd_line = unwords (pgm : dosifyPaths (map quote args))
+ cmd_line = pgm ++ ' ':showOptions args -- unwords (pgm : dosifyPaths (map quote args))
-- The pgm is already in native format (appropriate dir separators)
#if defined(mingw32_TARGET_OS)
quote "" = ""
#else
--------------------- Unix version ---------------------
-dosifyPaths ps = ps
-unDosifyPath xs = xs
-pgmPath dir pgm = dir ++ '/' : pgm
+dosifyPaths ps = ps
+unDosifyPath xs = xs
+pgmPath dir pgm = dir ++ '/' : pgm
+dosifyPath stuff = stuff
--------------------------------------------------------
#endif