diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,91 +1,4 @@
-{-# LANGUAGE CPP #-}
-
--- if MIN_VERSION_Cabal is not defined, then most likely we have old
--- GHC or/and old cabal-install in use.
-#ifndef MIN_VERSION_Cabal
-#define MIN_VERSION_Cabal(x,y,z) 0
-#endif
-
 import Distribution.Simple
-import Distribution.Simple.Setup
-import Distribution.PackageDescription
-import Distribution.Simple.LocalBuildInfo
-import Distribution.InstalledPackageInfo
-import Distribution.Simple.Program
-import qualified Distribution.Simple.PackageIndex as Pkg
 
-import System.Exit
-import System.IO
-import Data.IORef
-import Data.Char
-import Data.Maybe
-import System.Directory
-
-main = defaultMainWithHooks simpleUserHooks {
-                      postConf    = defaultPostConf,
-                      preBuild    = readHook,
-                      preCopy     = readHook,
-                      preInst     = readHook,
-                      preHscolour = readHook,
-                      preHaddock  = readHook,
-                      preReg      = readHook,
-                      preUnreg    = readHook
-                     }
-  where
-    defaultPostConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-    defaultPostConf args flags pkgdescr lbi = do
-#if MIN_VERSION_Cabal(2,3,0)
-      libdir_ <- getDbProgramOutput (fromFlag (configVerbosity flags))
-#else
-      libdir_ <- rawSystemProgramStdoutConf (fromFlag (configVerbosity flags))
-#endif
-                     ghcProgram (withPrograms lbi) ["--print-libdir"]
-      let libdir = reverse $ dropWhile isSpace $ reverse libdir_
-
-          ghc_pkg = case lookupProgram ghcPkgProgram (withPrograms lbi) of
-                          Just p  -> programPath p
-                          Nothing -> error "ghc-pkg was not found"
-          ghc     = case lookupProgram ghcProgram (withPrograms lbi) of
-                          Just p  -> programPath p
-                          Nothing -> error "ghc was not found"
-
-          -- figure out docdir from base's haddock-html field
-          base_pkg = case Pkg.searchByName (installedPkgs lbi) "base" of
-                        Pkg.None -> error "no base package"
-                        Pkg.Unambiguous (x:_) -> x
-                        _ -> error "base ambiguous"
-          base_html = case haddockHTMLs base_pkg of
-                        [] -> ""
-                        (x:_) -> x
-          docdir = fromMaybe base_html $
-                        fmap reverse (stripPrefix (reverse "/libraries/base")
-                                                  (reverse base_html))
-      c_ghc_pkg <- canonicalizePath ghc_pkg
-      c_ghc     <- canonicalizePath ghc
-
-      let buildinfo = emptyBuildInfo{
-               cppOptions = ["-DGHC_PATHS_GHC_PKG=" ++ show c_ghc_pkg,
-                             "-DGHC_PATHS_GHC=" ++ show c_ghc,
-                             "-DGHC_PATHS_LIBDIR=" ++ show libdir,
-                             "-DGHC_PATHS_DOCDIR=" ++ show docdir ]
-             }
-      writeFile file (show buildinfo)
-
-    readHook :: Args -> a -> IO HookedBuildInfo
-    readHook _ _ = do
-      str <- readFile file
-      return (Just (read str), [])
-
-file = "ghc-paths.buildinfo"
-
-die :: String -> IO a
-die msg = do
-  hFlush stdout
-  hPutStr stderr msg
-  exitWith (ExitFailure 1)
-
-stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]
-stripPrefix [] ys = Just ys
-stripPrefix (x:xs) (y:ys)
- | x == y = stripPrefix xs ys
-stripPrefix _ _ = Nothing
+main :: IO ()
+main = defaultMain
diff --git a/SetupHooks.hs b/SetupHooks.hs
new file mode 100644
--- /dev/null
+++ b/SetupHooks.hs
@@ -0,0 +1,51 @@
+-- | The locations of GHC that "GHC.Paths" is made from are given to the
+-- library as @cpp-options@, when its component is configured.
+module SetupHooks (setupHooks) where
+
+import Data.Char (isSpace)
+import Data.List (dropWhileEnd, stripPrefix)
+import Data.Maybe (fromMaybe)
+import System.Directory (canonicalizePath)
+import System.Process (readProcess)
+
+import Distribution.Simple.Program (programPath)
+import Distribution.Simple.Program.Db (lookupProgramByName)
+import Distribution.Simple.SetupHooks
+import qualified Distribution.Types.LocalBuildConfig as LBC
+
+setupHooks :: SetupHooks
+setupHooks =
+  noSetupHooks
+    { configureHooks = noConfigureHooks{preConfComponentHook = Just preConfComponent}
+    }
+
+preConfComponent :: PreConfComponentHook
+preConfComponent inputs@(PreConfComponentInputs lbc _ comp) = case comp of
+  CLib _ -> do
+    cppOpts <- ghcPathsOptions (LBC.withPrograms lbc)
+    return $
+      PreConfComponentOutputs $
+        ComponentDiff $
+          CLib emptyLibrary{libBuildInfo = emptyBuildInfo{cppOptions = cppOpts}}
+  _ -> return (noPreConfComponentOutputs inputs)
+
+ghcPathsOptions :: ProgramDb -> IO [String]
+ghcPathsOptions progDb = do
+  ghc <- required "ghc"
+  ghcPkg <- required "ghc-pkg"
+  libdir <- trim <$> readProcess ghc ["--print-libdir"] ""
+  -- The documentation is where base's is, without its last component.
+  baseHtml <- trim . takeWhile (/= '\n') <$> readProcess ghcPkg ["field", "base", "haddock-html", "--simple-output"] ""
+  let docdir = fromMaybe baseHtml (reverseStripPrefix "/libraries/base" baseHtml)
+  return
+    [ "-DGHC_PATHS_GHC_PKG=" ++ show ghcPkg
+    , "-DGHC_PATHS_GHC=" ++ show ghc
+    , "-DGHC_PATHS_LIBDIR=" ++ show libdir
+    , "-DGHC_PATHS_DOCDIR=" ++ show docdir
+    ]
+  where
+    required name = case lookupProgramByName name progDb of
+      Just prog -> canonicalizePath (programPath prog)
+      Nothing -> ioError (userError (name ++ " was not found"))
+    trim = dropWhileEnd isSpace . dropWhile isSpace
+    reverseStripPrefix suffix s = reverse <$> stripPrefix (reverse suffix) (reverse s)
diff --git a/ghc-paths.cabal b/ghc-paths.cabal
--- a/ghc-paths.cabal
+++ b/ghc-paths.cabal
@@ -1,6 +1,7 @@
+cabal-version: 3.14
 name: ghc-paths
-version: 0.1.0.12
-license: BSD3
+version: 0.1.0.13
+license: BSD-3-Clause
 license-file: LICENSE
 copyright: (c) Simon Marlow
 author: Simon Marlow
@@ -9,15 +10,27 @@
 synopsis: Knowledge of GHC's installation directories
 description: Knowledge of GHC's installation directories
 category: Development
-cabal-version: >= 1.6
-build-type: Custom
+build-type: Hooks
 
+tested-with:
+  GHC == 9.14.1
+  GHC == 9.12.2
+  GHC == 9.10.2
+  GHC == 9.8.4
+  GHC == 9.6.7
+
 custom-setup
-        setup-depends: base >= 3 && < 5, Cabal >= 1.6 && <3.1, directory
+        setup-depends:
+            base        >= 4.18 && < 5
+          , Cabal       >= 3.16 && < 3.19
+          , Cabal-hooks >= 3.16 && < 3.19
+          , directory
+          , process
 
 library
         build-depends: base >= 3 && < 5
         exposed-modules: GHC.Paths
+        default-language: Haskell2010
 
 source-repository head
   type:     git
