diff --git a/autogen/Config.hs b/autogen/Config.hs
--- a/autogen/Config.hs
+++ b/autogen/Config.hs
@@ -19,15 +19,15 @@
 cProjectName          :: String
 cProjectName          = "The Glorious Glasgow Haskell Compilation System"
 cProjectGitCommitId   :: String
-cProjectGitCommitId   = "aac18e9a08e6de9648e1a62d849dcd409f407df8"
+cProjectGitCommitId   = "92b6a0237e0195cee4773de4b237951addd659d9"
 cProjectVersion       :: String
-cProjectVersion       = "8.6.4"
+cProjectVersion       = "8.6.5"
 cProjectVersionInt    :: String
 cProjectVersionInt    = "806"
 cProjectPatchLevel    :: String
-cProjectPatchLevel    = "4"
+cProjectPatchLevel    = "5"
 cProjectPatchLevel1   :: String
-cProjectPatchLevel1   = "4"
+cProjectPatchLevel1   = "5"
 cProjectPatchLevel2   :: String
 cProjectPatchLevel2   = ""
 cBooterVersion        :: String
diff --git a/cmm/CmmParse.hs b/cmm/CmmParse.hs
--- a/cmm/CmmParse.hs
+++ b/cmm/CmmParse.hs
@@ -3205,9 +3205,9 @@
 {-# LINE 1 "<built-in>" #-}
 {-# LINE 1 "<command-line>" #-}
 {-# LINE 11 "<command-line>" #-}
-# 1 "/nix/store/f3l058q0zvnzr7nvl0jj789pyvljqadw-glibc-2.27-dev/include/stdc-predef.h" 1 3 4
+# 1 "/nix/store/sr4253np2gz2bpha4gn8gqlmiw604155-glibc-2.27-dev/include/stdc-predef.h" 1 3 4
 
-# 17 "/nix/store/f3l058q0zvnzr7nvl0jj789pyvljqadw-glibc-2.27-dev/include/stdc-predef.h" 3 4
+# 17 "/nix/store/sr4253np2gz2bpha4gn8gqlmiw604155-glibc-2.27-dev/include/stdc-predef.h" 3 4
 
 
 
@@ -3255,7 +3255,7 @@
 
 
 {-# LINE 11 "<command-line>" #-}
-{-# LINE 1 "/nix/store/s2h1ssv92djzj2b16w7xm4w7rjic7bqz-ghc-8.4.3/lib/ghc-8.4.3/include/ghcversion.h" #-}
+{-# LINE 1 "/nix/store/d9syi687jirk386a9hgr96yqhw6mx243-ghc-8.4.4/lib/ghc-8.4.4/include/ghcversion.h" #-}
 
 
 
@@ -3272,7 +3272,7 @@
 
 
 {-# LINE 11 "<command-line>" #-}
-{-# LINE 1 "/tmp/nix-build-happy-1.19.9.drv-0/ghc93072_0/ghc_2.h" #-}
+{-# LINE 1 "/build/ghc1606_0/ghc_2.h" #-}
 
 
 
diff --git a/ghc.cabal b/ghc.cabal
--- a/ghc.cabal
+++ b/ghc.cabal
@@ -1,6 +1,6 @@
 Cabal-Version: 2.0
 Name: ghc
-Version: 8.6.4
+Version: 8.6.5
 
 License: BSD3
 License-File: LICENSE
@@ -55,7 +55,7 @@
 Library
     -- The generated code in autogen/ has been generated for a linux/x86_64 target
     -- So everything else is definitely not working...
-    if !(os(linux) && arch(x86_64) && impl(ghc == 8.6.4))
+    if !(os(linux) && arch(x86_64) && impl(ghc == 8.6.5))
       build-depends: base<0
 
     -- ...while this package may in theory allow to reinstall lib:ghc
@@ -83,10 +83,10 @@
                    template-haskell == 2.14.*,
                    hpc        == 0.6.*,
                    transformers == 0.5.*,
-                   ghc-boot   == 8.6.4,
-                   ghc-boot-th == 8.6.4,
-                   ghc-heap   == 8.6.4,
-                   ghci == 8.6.4
+                   ghc-boot   == 8.6.5,
+                   ghc-boot-th == 8.6.5,
+                   ghc-heap   == 8.6.5,
+                   ghci == 8.6.5
 
     if os(windows)
         Build-Depends: Win32  >= 2.3 && < 2.7
diff --git a/main/GhcMake.hs b/main/GhcMake.hs
--- a/main/GhcMake.hs
+++ b/main/GhcMake.hs
@@ -2049,6 +2049,9 @@
         , ms_hspp_opts = dflags@DynFlags
           {hscTarget = HscNothing}
         } <- ms
+      -- Don't enable codegen for TH on indefinite packages; we
+      -- can't compile anything anyway! See #16219.
+      , not (isIndefinite dflags)
       , ms_mod `Set.member` needs_codegen_set
       = do
         let new_temp_file suf dynsuf = do
diff --git a/main/Packages.hs b/main/Packages.hs
--- a/main/Packages.hs
+++ b/main/Packages.hs
@@ -58,6 +58,7 @@
         pprPackages,
         pprPackagesSimple,
         pprModuleMap,
+        isIndefinite,
         isDllName
     )
 where
diff --git a/parser/Parser.hs b/parser/Parser.hs
--- a/parser/Parser.hs
+++ b/parser/Parser.hs
@@ -12057,9 +12057,9 @@
 {-# LINE 1 "<built-in>" #-}
 {-# LINE 1 "<command-line>" #-}
 {-# LINE 11 "<command-line>" #-}
-# 1 "/nix/store/f3l058q0zvnzr7nvl0jj789pyvljqadw-glibc-2.27-dev/include/stdc-predef.h" 1 3 4
+# 1 "/nix/store/sr4253np2gz2bpha4gn8gqlmiw604155-glibc-2.27-dev/include/stdc-predef.h" 1 3 4
 
-# 17 "/nix/store/f3l058q0zvnzr7nvl0jj789pyvljqadw-glibc-2.27-dev/include/stdc-predef.h" 3 4
+# 17 "/nix/store/sr4253np2gz2bpha4gn8gqlmiw604155-glibc-2.27-dev/include/stdc-predef.h" 3 4
 
 
 
@@ -12107,7 +12107,7 @@
 
 
 {-# LINE 11 "<command-line>" #-}
-{-# LINE 1 "/nix/store/s2h1ssv92djzj2b16w7xm4w7rjic7bqz-ghc-8.4.3/lib/ghc-8.4.3/include/ghcversion.h" #-}
+{-# LINE 1 "/nix/store/d9syi687jirk386a9hgr96yqhw6mx243-ghc-8.4.4/lib/ghc-8.4.4/include/ghcversion.h" #-}
 
 
 
@@ -12124,7 +12124,7 @@
 
 
 {-# LINE 11 "<command-line>" #-}
-{-# LINE 1 "/tmp/nix-build-happy-1.19.9.drv-0/ghc93072_0/ghc_2.h" #-}
+{-# LINE 1 "/build/ghc1606_0/ghc_2.h" #-}
 
 
 
