summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-11-10 19:24:51 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-12 21:25:40 -0500
commit490e8c750ea23ce8e2b7309e0d514b7d27f231bb (patch)
tree67a425e67c39f66165dcddbaa524c53e09068c95
parent4c6ace75435f23774de8ee3f317c9503bb1c5139 (diff)
downloadhaskell-490e8c750ea23ce8e2b7309e0d514b7d27f231bb.tar.gz
Generate ghcversion.h with the top-level configure
This is, rather unintuitively, part of the goal of making the packages that make of the GHC distribution more freestanding. `ghcversion.h` is very simple, so we easily can move it out of the main build systems (make and Hadrian). By doing so, the RTS becomes less of a special case to those build systems as the header, already existing in the source tree, appears like any other. We could do this with the upcomming RTS configure, but it hardly matters because there is nothing platform-specific here, it is just versioning information like the other files the top-level configure can be responsible for.
-rw-r--r--.gitignore8
-rw-r--r--configure.ac19
-rw-r--r--hadrian/src/Base.hs7
-rw-r--r--hadrian/src/Rules/Generate.hs48
-rw-r--r--hadrian/src/Rules/Register.hs2
-rw-r--r--hadrian/src/Settings/Builders/Cabal.hs3
-rw-r--r--hadrian/src/Settings/Builders/Ghc.hs4
-rw-r--r--rts/.gitignore18
-rw-r--r--rts/ghcversion.h.bottom10
-rw-r--r--rts/ghcversion.h.top3
-rw-r--r--rts/include/ghc.mk46
11 files changed, 69 insertions, 99 deletions
diff --git a/.gitignore b/.gitignore
index cbf1429c23..f0121e6936 100644
--- a/.gitignore
+++ b/.gitignore
@@ -80,8 +80,6 @@ _darcs/
/libraries/*/dist-install/
/libraries/*/dist-newstyle/
/libraries/dist-haddock/
-/rts/dist/
-/rts/dist-*/
/utils/*/dist*/
/compiler/stage1/
/compiler/stage2/
@@ -187,11 +185,6 @@ _darcs/
/mk/project.mk
/mk/project.mk.old
/mk/validate.mk
-/rts/rts.cabal
-/rts/package.conf.inplace
-/rts/package.conf.inplace.raw
-/rts/package.conf.install
-/rts/package.conf.install.raw
/stage3.package.conf
/testsuite_summary*.txt
/testsuite*.xml
@@ -205,7 +198,6 @@ _darcs/
/utils/ghc-pkg/ghc-pkg.cabal
utils/lndir/fs.*
utils/unlit/fs.*
-rts/fs.*
libraries/base/include/fs.h
libraries/base/cbits/fs.c
missing-win32-tarballs
diff --git a/configure.ac b/configure.ac
index 8bab372e81..560e8d6cb6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,6 +53,23 @@ FP_PROG_SORT
dnl ----------------------------------------------------------
FP_SETUP_PROJECT_VERSION
+dnl Don't use AC_DEFINE because it will make C-style comments invalid for
+dnl Haskell.
+
+> rts/include/ghcversion.h
+
+cat rts/ghcversion.h.top >> rts/include/ghcversion.h
+
+echo "#define __GLASGOW_HASKELL__ ${ProjectVersionInt}" >> rts/include/ghcversion.h
+echo "#define __GLASGOW_HASKELL_FULL_VERSION__ \"${ProjectVersion}\"" >> rts/include/ghcversion.h
+echo >> rts/include/ghcversion.h
+AS_IF([test x"${ProjectPatchLevel1}" != x],
+ [echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ ${ProjectPatchLevel1}" >> rts/include/ghcversion.h])
+AS_IF([test x"${ProjectPatchLevel2}" != x],
+ [echo "#define __GLASGOW_HASKELL_PATCHLEVEL2__ ${ProjectPatchLevel2}" >> rts/include/ghcversion.h])
+
+cat rts/ghcversion.h.bottom >> rts/include/ghcversion.h
+
# Hmmm, we fix the RPM release number to 1 here... Is this convenient?
AC_SUBST([release], [1])
@@ -76,6 +93,8 @@ AC_PREREQ([2.69])
AC_CONFIG_HEADER(mk/config.h)
# This one is manually maintained.
AC_CONFIG_HEADER(compiler/ghc-llvm-version.h)
+dnl manually outputted above, for reasons described there.
+dnl AC_CONFIG_HEADER(rts/include/ghcversion.h)
# No, semi-sadly, we don't do `--srcdir'...
if test x"$srcdir" != 'x.' ; then
diff --git a/hadrian/src/Base.hs b/hadrian/src/Base.hs
index 205bd7518f..253a436ea9 100644
--- a/hadrian/src/Base.hs
+++ b/hadrian/src/Base.hs
@@ -21,7 +21,7 @@ module Base (
module Way,
-- * Files
- configH, ghcVersionH,
+ configH,
-- * Paths
hadrianPath, configPath, configFile, sourcePath, shakeFilesDir,
@@ -74,9 +74,6 @@ sourcePath = hadrianPath -/- "src"
configH :: FilePath
configH = "mk/config.h"
-ghcVersionH :: Stage -> Action FilePath
-ghcVersionH stage = stageLibPath stage <&> (-/- "ghcversion.h")
-
-- | The directory in 'buildRoot' containing the Shake database and other
-- auxiliary files generated by Hadrian.
shakeFilesDir :: FilePath
@@ -123,7 +120,7 @@ includesDependencies :: Stage -> Action [FilePath]
includesDependencies stage = do
p <- stageLibPath stage
pure $ (p -/-) <$>
- [ "ghcautoconf.h", "ghcplatform.h", "ghcversion.h" ]
+ [ "ghcautoconf.h", "ghcplatform.h" ]
-- | Files the `haddock` binary depends on
haddockDeps :: Stage -> Action [FilePath]
diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs
index 13147aeec9..eb7a780d97 100644
--- a/hadrian/src/Rules/Generate.hs
+++ b/hadrian/src/Rules/Generate.hs
@@ -133,7 +133,6 @@ generatePackageCode context@(Context stage pkg _) = do
(root -/- "**" -/- dir -/- "DerivedConstants.h") <~ stageLibPath stage
(root -/- "**" -/- dir -/- "ghcautoconf.h") <~ stageLibPath stage
(root -/- "**" -/- dir -/- "ghcplatform.h") <~ stageLibPath stage
- (root -/- "**" -/- dir -/- "ghcversion.h") <~ stageLibPath stage
where
pattern <~ mdir = pattern %> \file -> do
dir <- mdir
@@ -184,7 +183,6 @@ generateRules = do
(prefix -/- "ghcplatform.h") %> go generateGhcPlatformH
(prefix -/- "settings") %> go generateSettings
(prefix -/- "ghcautoconf.h") %> go generateGhcAutoconfH
- (prefix -/- "ghcversion.h") %> go generateGhcVersionH
-- TODO: simplify, get rid of fake rts context
for_ (fst <$> deriveConstantsPairs) $ \constantsFile ->
prefix -/- constantsFile %> \file -> do
@@ -193,7 +191,6 @@ generateRules = do
need
[ prefix -/- "ghcplatform.h"
, prefix -/- "ghcautoconf.h"
- , prefix -/- "ghcversion.h"
]
withTempDir $ \dir -> build $
target (rtsContext stage) DeriveConstants [] [file, dir]
@@ -395,7 +392,7 @@ generateConfigHs = do
generateGhcAutoconfH :: Expr String
generateGhcAutoconfH = do
trackGenerateHs
- configHContents <- expr $ map undefinePackage <$> readFileLines configH
+ configHContents <- expr $ mapMaybe undefinePackage <$> readFileLines configH
return . unlines $
[ "#if !defined(__GHCAUTOCONF_H__)"
, "#define __GHCAUTOCONF_H__" ]
@@ -404,43 +401,12 @@ generateGhcAutoconfH = do
where
undefinePackage s
| "#define PACKAGE_" `isPrefixOf` s
- = "/* #undef " ++ takeWhile (/=' ') (drop 8 s) ++ " */"
- | otherwise = s
-
--- | Generate @ghcversion.h@ header.
-generateGhcVersionH :: Expr String
-generateGhcVersionH = do
- trackGenerateHs
- fullVersion <- getSetting ProjectVersion
- version <- getSetting ProjectVersionInt
- patchLevel1 <- getSetting ProjectPatchLevel1
- patchLevel2 <- getSetting ProjectPatchLevel2
- return . unlines $
- [ "#if !defined(__GHCVERSION_H__)"
- , "#define __GHCVERSION_H__"
- , ""
- , "#if !defined(__GLASGOW_HASKELL__)"
- , "#define __GLASGOW_HASKELL__ " ++ version
- , "#endif"
- , "#if !defined(__GLASGOW_HASKELL_FULL_VERSION__)"
- , "#define __GLASGOW_HASKELL_FULL_VERSION__ \"" ++ fullVersion ++ "\""
- , "#endif"
- , ""]
- ++
- [ "#define __GLASGOW_HASKELL_PATCHLEVEL1__ " ++ patchLevel1 | patchLevel1 /= "" ]
- ++
- [ "#define __GLASGOW_HASKELL_PATCHLEVEL2__ " ++ patchLevel2 | patchLevel2 /= "" ]
- ++
- [ ""
- , "#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\\"
- , " ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \\"
- , " ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\"
- , " && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \\"
- , " ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\"
- , " && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \\"
- , " && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )"
- , ""
- , "#endif /* __GHCVERSION_H__ */" ]
+ = Just $ "/* #undef " ++ takeWhile (/=' ') (drop 8 s) ++ " */"
+ | "#define __GLASGOW_HASKELL" `isPrefixOf` s
+ = Nothing
+ | "/* REMOVE ME */" == s
+ = Nothing
+ | otherwise = Just s
-- | Generate @Version.hs@ files.
generateVersionHs :: Expr String
diff --git a/hadrian/src/Rules/Register.hs b/hadrian/src/Rules/Register.hs
index 6bbae7e0bd..6b603c6858 100644
--- a/hadrian/src/Rules/Register.hs
+++ b/hadrian/src/Rules/Register.hs
@@ -128,7 +128,7 @@ buildConf _ context@Context {..} _conf = do
need [ path -/- "DerivedConstants.h"
, path -/- "ghcautoconf.h"
, path -/- "ghcplatform.h"
- , path -/- "ghcversion.h" ]
+ ]
-- we need to generate this file for GMP
when (package == ghcBignum) $ do
diff --git a/hadrian/src/Settings/Builders/Cabal.hs b/hadrian/src/Settings/Builders/Cabal.hs
index e3361d3fe9..e38eba1cf0 100644
--- a/hadrian/src/Settings/Builders/Cabal.hs
+++ b/hadrian/src/Settings/Builders/Cabal.hs
@@ -129,7 +129,8 @@ configureArgs = do
, conf "--with-curses-libraries" $ arg =<< getSetting CursesLibDir
, conf "--host" $ arg =<< getSetting TargetPlatformFull
, conf "--with-cc" $ arg =<< getBuilderPath . (Cc CompileC) =<< getStage
- , notStage0 ? (arg =<< ("--ghc-option=-ghcversion-file=" ++) <$> expr ((-/-) <$> topDirectory <*> ghcVersionH stage))]
+ , notStage0 ? arg "--ghc-option=-ghcversion-file=rts/include/ghcversion.h"
+ ]
bootPackageConstraints :: Args
bootPackageConstraints = stage0 ? do
diff --git a/hadrian/src/Settings/Builders/Ghc.hs b/hadrian/src/Settings/Builders/Ghc.hs
index 3d5a96efe4..b4c129562e 100644
--- a/hadrian/src/Settings/Builders/Ghc.hs
+++ b/hadrian/src/Settings/Builders/Ghc.hs
@@ -195,9 +195,7 @@ commonGhcArgs :: Args
commonGhcArgs = do
way <- getWay
path <- getBuildPath
- stage <- getStage
useColor <- shakeColor <$> expr getShakeOptions
- ghcVersion <- expr $ ghcVersionH stage
mconcat [ arg "-hisuf", arg $ hisuf way
, arg "-osuf" , arg $ osuf way
, arg "-hcsuf", arg $ hcsuf way
@@ -208,7 +206,7 @@ commonGhcArgs = do
-- in the package database. We therefore explicitly supply the path
-- to the @ghc-version@ file, to prevent GHC from trying to open the
-- RTS package in the package database and failing.
- , package rts ? notStage0 ? arg ("-ghcversion-file=" ++ ghcVersion)
+ , package rts ? notStage0 ? arg "-ghcversion-file=rts/include/ghcversion.h"
, map ("-optc" ++) <$> getStagedSettingList ConfCcArgs
, map ("-optP" ++) <$> getStagedSettingList ConfCppArgs
, map ("-optP" ++) <$> getContextData cppOpts
diff --git a/rts/.gitignore b/rts/.gitignore
new file mode 100644
index 0000000000..a0fafa79ab
--- /dev/null
+++ b/rts/.gitignore
@@ -0,0 +1,18 @@
+# Specific generated files
+/dist/
+/dist-*/
+
+/rts.cabal
+
+/include/ghcversion.h
+
+/package.conf.inplace
+/package.conf.inplace.raw
+/package.conf.install
+/package.conf.install.raw
+/fs.*
+
+/autom4te.cache/
+/config.log
+/config.status
+/configure
diff --git a/rts/ghcversion.h.bottom b/rts/ghcversion.h.bottom
new file mode 100644
index 0000000000..b9a8fc29c6
--- /dev/null
+++ b/rts/ghcversion.h.bottom
@@ -0,0 +1,10 @@
+
+#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) ( \
+ ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \
+ ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \
+ && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \
+ ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \
+ && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \
+ && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )
+
+#endif /* __GHCVERSION_H__ */
diff --git a/rts/ghcversion.h.top b/rts/ghcversion.h.top
new file mode 100644
index 0000000000..788dba3f40
--- /dev/null
+++ b/rts/ghcversion.h.top
@@ -0,0 +1,3 @@
+#if !defined(__GHCVERSION_H__)
+#define __GHCVERSION_H__
+
diff --git a/rts/include/ghc.mk b/rts/include/ghc.mk
index 11e72c3daa..7bc4fc2d8b 100644
--- a/rts/include/ghc.mk
+++ b/rts/include/ghc.mk
@@ -19,9 +19,6 @@ includes_2_H_CONFIG = $(includes_1_H_CONFIG)
includes_1_H_PLATFORM = rts/dist-install/build/include/ghcplatform.h
includes_2_H_PLATFORM = $(includes_1_H_PLATFORM)
-includes_1_H_VERSION = rts/dist-install/build/include/ghcversion.h
-includes_2_H_VERSION = $(includes_1_H_VERSION)
-
BUILD_0_INCLUDE_DIR = rts/dist/build/include
BUILD_1_INCLUDE_DIR = rts/dist-install/build/include
BUILD_2_INCLUDE_DIR = $(BUILD_1_INCLUDE_DIR)
@@ -41,8 +38,7 @@ includes_H_FILES := $(subst /./,/,$(includes_H_FILES))
includes_H_FILES_GENERATED = \
ghcautoconf.h \
- ghcplatform.h \
- ghcversion.h
+ ghcplatform.h
# Unlike above, include generated files. We still need the previous list
# without the generated files separtely and not just as part of this due to
@@ -76,40 +72,6 @@ ifneq "$(GhcWithSMP)" "YES"
includes_CC_OPTS += -DNOSMP
endif
-define includesHeaderVersion
-# $1 = stage
-$$(includes_$1_H_VERSION) : mk/project.mk | $$$$(dir $$$$@)/.
- $$(call removeFiles,$$@)
- @echo "Creating $$@..."
- @echo "#if !defined(__GHCVERSION_H__)" > $$@
- @echo "#define __GHCVERSION_H__" >> $$@
- @echo >> $$@
- @echo "#define __GLASGOW_HASKELL__ $$(ProjectVersionInt)" >> $$@
- @echo "#define __GLASGOW_HASKELL_FULL_VERSION__ \"$$(ProjectVersion)\"" >> $$@
- @echo >> $$@
- @if [ -n "$$(ProjectPatchLevel1)" ]; then \
- echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $$(ProjectPatchLevel1)" >> $$@; \
- fi
- @if [ -n "$$(ProjectPatchLevel2)" ]; then \
- echo "#define __GLASGOW_HASKELL_PATCHLEVEL2__ $$(ProjectPatchLevel2)" >> $$@; \
- fi
- @echo >> $$@
- @echo '#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\' >> $$@
- @echo ' ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \' >> $$@
- @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $$@
- @echo ' && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \' >> $$@
- @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $$@
- @echo ' && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \' >> $$@
- @echo ' && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )' >> $$@
- @echo >> $$@
- @echo "#endif /* __GHCVERSION_H__ */" >> $$@
- @echo "Done."
-
-endef
-
-$(eval $(call includesHeaderVersion,0))
-$(eval $(call includesHeaderVersion,1))
-
ifneq "$(BINDIST)" "YES"
define includesHeaderConfig
@@ -123,7 +85,11 @@ $$(includes_$1_H_CONFIG) : mk/config.h mk/config.mk rts/include/ghc.mk | $$$$(di
# Copy the contents of mk/config.h, turning '#define PACKAGE_FOO
# "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
#
- @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$$$,\1/* #undef \2 */,' mk/config.h >> $$@
+ @sed mk/config.h \
+ -e 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$$$,\1/* #undef \2 */,' \
+ -e '/__GLASGOW_HASKELL/d' \
+ -e '/REMOVE ME/d' \
+ >> $$@
#
@echo "#endif /* __GHCAUTOCONF_H__ */" >> $$@
@echo "Done."