diff --git a/compiler/HsVersions.h b/compiler/HsVersions.h
index a4ec3e4c40f38b06498f61c9172bbca176b0f644..992c4377cd3e756b971cb4c13db65212d84bfeee 100644
--- a/compiler/HsVersions.h
+++ b/compiler/HsVersions.h
@@ -12,7 +12,7 @@ you will screw up the layout where they are used in case expressions!
 /* Useful in the headers that we share with the RTS */
 #define COMPILING_GHC 1
 
-/* Pull in all the platform defines for this build (foo_TARGET_ARCH etc.) */
+/* Pull in all the platform defines for this build (foo_HOST_ARCH etc.) */
 #include "ghc_boot_platform.h"
 
 /* Pull in the autoconf defines (HAVE_FOO), but don't include
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 74bc64ede3706b77f75b34f61aa4cebe5936c0aa..17c8f480d92a298c8c617b4155fb210e4a481238 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -1962,11 +1962,13 @@ doCpp dflags raw input_fn output_fn = do
     let cpp_prog args | raw       = SysTools.runCpp dflags args
                       | otherwise = SysTools.runCc Nothing dflags (SysTools.Option "-E" : args)
 
+    let targetArch = stringEncodeArch $ platformArch $ targetPlatform dflags
+        targetOS = stringEncodeOS $ platformOS $ targetPlatform dflags
     let target_defs =
           [ "-D" ++ HOST_OS     ++ "_BUILD_OS",
             "-D" ++ HOST_ARCH   ++ "_BUILD_ARCH",
-            "-D" ++ TARGET_OS   ++ "_HOST_OS",
-            "-D" ++ TARGET_ARCH ++ "_HOST_ARCH" ]
+            "-D" ++ targetOS    ++ "_HOST_OS",
+            "-D" ++ targetArch  ++ "_HOST_ARCH" ]
         -- remember, in code we *compile*, the HOST is the same our TARGET,
         -- and BUILD is the same as our HOST.
 
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index fcc5cfb1a0648db118021de13e909184f872912d..2379f484e9d564dce826d0e3d8a980eaf7fc6501 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -1503,9 +1503,11 @@ versionedAppDir dflags = do
 -- constructing platform-version-dependent files that need to co-exist.
 --
 versionedFilePath :: DynFlags -> FilePath
-versionedFilePath dflags =     TARGET_ARCH
-                        ++ '-':TARGET_OS
-                        ++ '-':projectVersion dflags
+versionedFilePath dflags = intercalate "-"
+  [ stringEncodeArch $ platformArch $ targetPlatform dflags
+  , stringEncodeOS $ platformOS $ targetPlatform dflags
+  , projectVersion dflags
+  ]
   -- NB: This functionality is reimplemented in Cabal, so if you
   -- change it, be sure to update Cabal.
 
@@ -5503,7 +5505,7 @@ addIncludePath p =
 addFrameworkPath p =
   upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
 
-#if !defined(mingw32_TARGET_OS)
+#if !defined(mingw32_HOST_OS)
 split_marker :: Char
 split_marker = ':'   -- not configurable (ToDo)
 #endif
@@ -5515,7 +5517,7 @@ splitPathList s = filter notNull (splitUp s)
                 -- cause confusion when they are translated into -I options
                 -- for passing to gcc.
   where
-#if !defined(mingw32_TARGET_OS)
+#if !defined(mingw32_HOST_OS)
     splitUp xs = split split_marker xs
 #else
      -- Windows: 'hybrid' support for DOS-style paths in directory lists.
diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs
index e1e64d1a1a75875503f345038a791d9be89fadd5..edf6783055d8409fc1338660d9f08e3821101578 100644
--- a/hadrian/src/Rules/Generate.hs
+++ b/hadrian/src/Rules/Generate.hs
@@ -493,11 +493,8 @@ generateVersionHs :: Expr String
 generateVersionHs = do
     trackGenerateHs
     projectVersion <- getSetting ProjectVersion
-    targetOs       <- getSetting TargetOs
-    targetArch     <- getSetting TargetArch
     return $ unlines
         [ "module Version where"
-        , "version, targetOS, targetARCH :: String"
+        , "version :: String"
         , "version    = " ++ show projectVersion
-        , "targetOS   = " ++ show targetOs
-        , "targetARCH = " ++ show targetArch ]
+        ]
diff --git a/includes/rts/storage/InfoTables.h b/includes/rts/storage/InfoTables.h
index 5c8296a351a1909b09f40a7e3289a4a8ba1efc91..4de5207b4df2ecbcd2aee395fe184cbf621a1f1b 100644
--- a/includes/rts/storage/InfoTables.h
+++ b/includes/rts/storage/InfoTables.h
@@ -27,7 +27,7 @@
    hackery can go away sometime.
    ------------------------------------------------------------------------- */
 
-#if defined(x86_64_TARGET_ARCH)
+#if defined(x86_64_HOST_ARCH)
 #define OFFSET_FIELD(n) StgHalfInt n; StgHalfWord __pad_##n
 #else
 #define OFFSET_FIELD(n) StgInt n
@@ -153,7 +153,7 @@ typedef union {
 } StgClosureInfo;
 
 
-#if defined(x86_64_TARGET_ARCH) && defined(TABLES_NEXT_TO_CODE)
+#if defined(x86_64_HOST_ARCH) && defined(TABLES_NEXT_TO_CODE)
 // On x86_64 we can fit a pointer offset in half a word, so put the SRT offset
 // in the info->srt field directly.
 //
@@ -338,7 +338,7 @@ typedef struct StgConInfoTable_ {
  * info must be a Stg[Ret|Thunk]InfoTable* (an info table that has a SRT)
  */
 #if defined(TABLES_NEXT_TO_CODE)
-#if defined(x86_64_TARGET_ARCH)
+#if defined(x86_64_HOST_ARCH)
 #define GET_SRT(info) \
   ((StgClosure*) (((StgWord) ((info)+1)) + (info)->i.srt))
 #else
@@ -365,7 +365,7 @@ typedef struct StgConInfoTable_ {
  * info must be a StgFunInfoTable*
  */
 #if defined(TABLES_NEXT_TO_CODE)
-#if defined(x86_64_TARGET_ARCH)
+#if defined(x86_64_HOST_ARCH)
 #define GET_FUN_SRT(info) \
   ((StgClosure*) (((StgWord) ((info)+1)) + (info)->i.srt))
 #else
diff --git a/includes/stg/HaskellMachRegs.h b/includes/stg/HaskellMachRegs.h
index 7b12d128140a064d719f08f69854779483401f39..917365778beda0c7d85c1ffe7e34b22188e35d71 100644
--- a/includes/stg/HaskellMachRegs.h
+++ b/includes/stg/HaskellMachRegs.h
@@ -32,32 +32,32 @@
 
 #define MACHREGS_NO_REGS 0
 
-#if defined(i386_TARGET_ARCH)
+#if defined(i386_HOST_ARCH)
 #define MACHREGS_i386     1
 #endif
 
-#if defined(x86_64_TARGET_ARCH)
+#if defined(x86_64_HOST_ARCH)
 #define MACHREGS_x86_64   1
 #endif
 
-#if defined(powerpc_TARGET_ARCH) || defined(powerpc64_TARGET_ARCH) \
-            || defined(powerpc64le_TARGET_ARCH) || defined(rs6000_TARGET_ARCH)
+#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \
+            || defined(powerpc64le_HOST_ARCH) || defined(rs6000_HOST_ARCH)
 #define MACHREGS_powerpc  1
 #endif
 
-#if defined(sparc_TARGET_ARCH)
+#if defined(sparc_HOST_ARCH)
 #define MACHREGS_sparc    1
 #endif
 
-#if defined(arm_TARGET_ARCH)
+#if defined(arm_HOST_ARCH)
 #define MACHREGS_arm      1
 #endif
 
-#if defined(aarch64_TARGET_ARCH)
+#if defined(aarch64_HOST_ARCH)
 #define MACHREGS_aarch64  1
 #endif
 
-#if defined(darwin_TARGET_OS)
+#if defined(darwin_HOST_OS)
 #define MACHREGS_darwin   1
 #endif
 
diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
index afb990dda50a77dc29fb8e74b326bb5b1bc09da0..d9a28d7396a7d1aa3ae707c4640902512f372107 100644
--- a/rts/PrimOps.cmm
+++ b/rts/PrimOps.cmm
@@ -2440,7 +2440,7 @@ stg_traceEventzh ( W_ msg )
     // We should go through the macro HASKELLEVENT_USER_MSG_ENABLED from
     // RtsProbes.h, but that header file includes unistd.h, which doesn't
     // work in Cmm
-#if !defined(solaris2_TARGET_OS)
+#if !defined(solaris2_HOST_OS)
    (enabled) = ccall __dtrace_isenabled$HaskellEvent$user__msg$v1();
 #else
     // Solaris' DTrace can't handle the
@@ -2482,7 +2482,7 @@ stg_traceMarkerzh ( W_ msg )
 
     W_ enabled;
 
-#if !defined(solaris2_TARGET_OS)
+#if !defined(solaris2_HOST_OS)
     (enabled) = ccall __dtrace_isenabled$HaskellEvent$user__marker$v1();
 #else
     enabled = 1;
diff --git a/utils/genapply/Main.hs b/utils/genapply/Main.hs
index f35897ba9d4c6a2981fee457b898fde27ad92ba2..270bc616153fc5ebbb0234e0dfd3cb8e1b459147 100644
--- a/utils/genapply/Main.hs
+++ b/utils/genapply/Main.hs
@@ -12,8 +12,12 @@
 -- for details
 module Main(main) where
 
+-- We improperly include *HOST* macros for our target...
 #include "../../includes/ghcconfig.h"
+
+-- .. so that this header defines the right stuff.
 #include "../../includes/stg/HaskellMachRegs.h"
+
 #include "../../includes/rts/Constants.h"
 
 -- Needed for TAG_BITS
diff --git a/utils/ghc-pkg/ghc.mk b/utils/ghc-pkg/ghc.mk
index 37ce0a7c5bb583fa6b1f45b7b217dceca318bbc3..32e18f490dd14b783d7d0bbbe4006a189475b97b 100644
--- a/utils/ghc-pkg/ghc.mk
+++ b/utils/ghc-pkg/ghc.mk
@@ -17,10 +17,8 @@ utils/ghc-pkg/dist/build/Version.hs \
 utils/ghc-pkg/dist-install/build/Version.hs: mk/project.mk | $$(dir $$@)/.
 	$(call removeFiles,$@)
 	echo "module Version where"                    >> $@
-	echo "version, targetOS, targetARCH :: String" >> $@
+	echo "version :: String" >> $@
 	echo "version    = \"$(ProjectVersion)\""      >> $@
-	echo "targetOS   = \"$(TargetOS_CPP)\""        >> $@
-	echo "targetARCH = \"$(TargetArch_CPP)\""      >> $@
 
 utils/ghc-pkg_PACKAGE = ghc-pkg