-# -optC-funfolding-interface-threshold7
-# To stop the definition of 'strLength', which calls strlen, getting
-# into the interface file and spreading the -monly-3-regs virus.
-# We need -optC here because the driver before 3.02 didn't understand
-# the -funfolding flags.
-
-utils/PrimPacked_HC_OPTS = -fvia-C -monly-3-regs -funfolding-interface-threshold7
-
-# Strictness analyser misbehaving in 2.10, fails to terminate on
-# UpdAnal.lhs due to weird recursive datatype. Bug was exposed by a
-# separate bugfix to the fixpoint finder.
-simplStg/UpdAnal_HC_OPTS = -fno-strictness
-
-ghci/StgInterp_HC_OPTS = -fvia-C
-
-# ----------------------------------------------------------------------------
-# C compilations
-
-SRC_C_OPTS += -O -I. -IcodeGen
-
+utils/PrimPacked_HC_OPTS = -fvia-C -monly-3-regs
+
+# ByteCodeItbls uses primops that the NCG doesn't support yet.
+ghci/ByteCodeItbls_HC_OPTS = -fvia-C
+ghci/ByteCodeLink_HC_OPTS = -fvia-C -monly-3-regs
+
+# CSE interacts badly with top-level IORefs (reportedly in DriverState and
+# DriverMkDepend), causing some of them to be commoned up. We have a fix for
+# this in 5.00+, but earlier versions of the compiler will need CSE turned off.
+# To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
+compMan/CompManager_HC_OPTS = -fno-cse
+ghci/InteractiveUI_HC_OPTS = -fno-cse
+main/CmdLineOpts_HC_OPTS = -fno-cse
+main/DriverFlags_HC_OPTS = -fno-cse
+main/DriverMkDepend_HC_OPTS = -fno-cse
+main/DriverPipeline_HC_OPTS = -fno-cse
+main/DriverState_HC_OPTS = -fno-cse
+main/DriverUtil_HC_OPTS = -fno-cse
+main/Finder_HC_OPTS = -fno-cse
+main/SysTools_HC_OPTS = -fno-cse
+
+# The #include is vital for the via-C route, else the C
+# compiler doesn't realise that the stcall foreign imports are indeed
+# stdcall, and doesn't generate the Foo@8 name for them
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+main/SysTools_HC_OPTS += '-\#include <windows.h>' '-\#include <process.h>'
+endif