- = do { maybe_exec_dir <- getExecDir -- Get directory of executable
- ; case maybe_exec_dir of -- (only works on Windows)
- Nothing -> throwDyn (InstallationError ("missing -B<dir> option"))
- Just dir -> return dir }
-
- remove_suffix dir -- "/...stuff.../ghc/compiler" --> "/...stuff..."
- = ASSERT2( not (null p1) &&
- not (null p2) &&
- dosifyPath dir == dosifyPath (top_dir ++ "/ghc/compiler"),
- text dir )
- top_dir
- where
- p1 = dropWhile (not . isSlash) (reverse dir)
- p2 = dropWhile (not . isSlash) (tail p1) -- head is '/'
- top_dir = reverse (tail p2) -- head is '/'
-
-getExecDir = return Nothing
+ = do { maybe_exec_dir <- getExecDir -- Get directory of executable
+ ; case maybe_exec_dir of -- (only works on Windows;
+ -- returns Nothing on Unix)
+ Nothing -> throwDyn (InstallationError "missing -B<dir> option")
+ Just dir -> return dir
+ }
+\end{code}
+
+
+%************************************************************************
+%* *
+\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 -- an entry that _contains_ filename(s) / filepaths.
+ String -- a non-filepath prefix that shouldn't be transformed (e.g., "/out="
+ String -- the filepath/filename portion
+ | Option String
+
+showOptions :: [Option] -> String
+showOptions ls = unwords (map (quote.showOpt) ls)
+ where
+ showOpt (FileOption pre f) = pre ++ dosifyPath f
+ showOpt (Option s) = s
+
+#if defined(mingw32_TARGET_OS)
+ quote "" = ""
+ quote s = "\"" ++ s ++ "\""
+#else
+ quote = id
+#endif
+