diff options
Diffstat (limited to 'compiler/main/SysTools/Tasks.hs')
-rw-r--r-- | compiler/main/SysTools/Tasks.hs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/compiler/main/SysTools/Tasks.hs b/compiler/main/SysTools/Tasks.hs index 9e3df26877..a3d312e30e 100644 --- a/compiler/main/SysTools/Tasks.hs +++ b/compiler/main/SysTools/Tasks.hs @@ -10,6 +10,7 @@ module SysTools.Tasks where import Exception import ErrUtils +import HscTypes import DynFlags import Outputable import Platform @@ -58,11 +59,12 @@ runPp dflags args = do opts = map Option (getOpts dflags opt_F) runSomething dflags "Haskell pre-processor" prog (args ++ opts) -runCc :: DynFlags -> [Option] -> IO () -runCc dflags args = do +-- | Run compiler of C-like languages and raw objects (such as gcc or clang). +runCc :: Maybe ForeignSrcLang -> DynFlags -> [Option] -> IO () +runCc mLanguage dflags args = do let (p,args0) = pgm_c dflags - args1 = map Option (getOpts dflags opt_c) - args2 = args0 ++ args ++ args1 + args1 = map Option userOpts + args2 = args0 ++ languageOptions ++ args ++ args1 -- We take care to pass -optc flags in args1 last to ensure that the -- user can override flags passed by GHC. See #14452. mb_env <- getGccEnv args2 @@ -118,6 +120,21 @@ runCc dflags args = do | "warning: call-clobbered register used" `isContainedIn` w = False | otherwise = True + -- force the C compiler to interpret this file as C when + -- compiling .hc files, by adding the -x c option. + -- Also useful for plain .c files, just in case GHC saw a + -- -x c option. + (languageOptions, userOpts) = case mLanguage of + Nothing -> ([], userOpts_c) + Just language -> ([Option "-x", Option languageName], opts) where + (languageName, opts) = case language of + LangCxx -> ("c++", userOpts_cxx) + LangObjc -> ("objective-c", userOpts_c) + LangObjcxx -> ("objective-c++", userOpts_cxx) + _ -> ("c", userOpts_c) + userOpts_c = getOpts dflags opt_c + userOpts_cxx = getOpts dflags opt_cxx + isContainedIn :: String -> String -> Bool xs `isContainedIn` ys = any (xs `isPrefixOf`) (tails ys) |