Skip to content

Commit

Permalink
feat: generate ghcversion.h on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabedini committed Feb 20, 2025
1 parent 6a0ce30 commit 2a17303
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
31 changes: 29 additions & 2 deletions compiler/GHC/SysTools/Cpp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Control.Monad

import System.Directory
import System.FilePath
import GHC.Settings.Config (cProjectVersionInt, cProjectVersion, cProjectPatchLevel1, cProjectPatchLevel2)

data CppOpts = CppOpts
{ sourceCodePreprocessor :: !SourceCodePreprocessor
Expand Down Expand Up @@ -176,7 +177,11 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do
let asserts_def = [ "-D__GLASGOW_HASKELL_ASSERTS_IGNORED__" | gopt Opt_IgnoreAsserts dflags]

-- Default CPP defines in Haskell source
hsSourceCppOpts <- getGhcVersionIncludeFlags dflags unit_env
-- hsSourceCppOpts <- getGhcVersionIncludeFlags dflags unit_env
ghc_version_include <-
do stub_filename <- newTempName logger tmpfs (tmpDir dflags) TFL_CurrentModule "h"
writeFile stub_filename ghc_version_stub
return [GHC.SysTools.FileOption "-include" stub_filename]

-- MIN_VERSION macros
let uids = explicitUnits unit_state
Expand All @@ -199,7 +204,7 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do

cpp_prog ( map GHC.SysTools.Option verbFlags
++ map GHC.SysTools.Option include_paths
++ map GHC.SysTools.Option hsSourceCppOpts
++ ghc_version_include
++ map GHC.SysTools.Option target_defs
++ map GHC.SysTools.Option backend_defs
++ map GHC.SysTools.Option th_defs
Expand Down Expand Up @@ -230,6 +235,28 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do
, GHC.SysTools.FileOption "" output_fn
])

-- ---------------------------------------------------------------------------
-- ghcversion.h

ghc_version_stub :: String
ghc_version_stub =
concat
["#define __GLASGOW_HASKELL__ ", show cProjectVersionInt, "\n"
,"#define __GLASGOW_HASKELL_FULL_VERSION__ ", show cProjectVersion, "\n"
,"\n"
,"#define __GLASGOW_HASKELL_PATCHLEVEL1__", show cProjectPatchLevel1, "\n"
,"#define __GLASGOW_HASKELL_PATCHLEVEL2__", show cProjectPatchLevel2, "\n"
,"\n"
,"#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) ( \\\n"
," ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \\\n"
," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n"
," && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \\\n"
," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n"
," && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \\\n"
," && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )\n"
,"\n\n"
]

-- ---------------------------------------------------------------------------
-- Macros (cribbed from Cabal)

Expand Down
1 change: 0 additions & 1 deletion rts/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ AC_DEFUN([GHC_INFO_FIELD],[
])

AC_CONFIG_FILES([include/ghcplatform.h])
AC_CONFIG_FILES([include/ghcversion.h])
AC_CONFIG_HEADERS([include/ghcautoconf.h])

AC_ARG_WITH([compiler],
Expand Down
3 changes: 0 additions & 3 deletions rts/rts.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extra-source-files:
config.guess
config.sub
include/ghcplatform.h.in
include/ghcversion.h.in
configure.ac
external-symbols.list.in
rts.buildinfo.in
Expand Down Expand Up @@ -346,13 +345,11 @@ library
autogen-includes:
ghcautoconf.h
ghcplatform.h
ghcversion.h

install-includes:
ghcautoconf.h
ghcconfig.h
ghcplatform.h
ghcversion.h

HsFFI.h
Rts.h
Expand Down

0 comments on commit 2a17303

Please sign in to comment.