Commit 05419e55 authored by John Ericson's avatar John Ericson Committed by Marge Bot

Per stage headers, ghc_boot_platform.h -> stage 0 ghcplatform.h

The generated headers are now generated per stage, which means we can
skip hacks like `ghc_boot_platform.h` and just have that be the stage 0
header as proper. In general, stages are to be embraced: freely generate
everything in each stage but then just build what you depend on, and
everything is symmetrical and efficient. Trying to avoid stages because
bootstrapping is a mind bender just creates tons of bespoke
mini-mind-benders that add up to something far crazier.

Hadrian was pretty close to this "stage-major" approach already, and so
was fairly easy to fix. Make needed more work, however: it did know
about stages so at least there was a scaffold, but few packages except
for the compiler cared, and the compiler used its own counting system.
That said, make and Hadrian now work more similarly, which is good for
the transition to Hadrian. The merits of embracing stage aside, the
change may be worthy for easing that transition alone.
parent ec93d2a9
......@@ -73,6 +73,7 @@ _darcs/
/driver/ghc/dist/
/driver/haddock/dist/
/driver/ghci/dist/
/includes/dist/
/includes/dist-*/
/libffi/dist-install/
/libraries/*/dist-boot/
......@@ -128,9 +129,6 @@ _darcs/
/ghc.spec
/ghc/ghc-bin.cabal
/includes/dist/
/includes/ghcautoconf.h
/includes/ghcplatform.h
/includes/ghcversion.h
/index.html
/inplace/
/libffi/build/
......
......@@ -9,14 +9,10 @@ you will screw up the layout where they are used in case expressions!
#endif
/* 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
* ghcconfig.h, because that will include ghcplatform.h which has the
* wrong platform settings for the compiler (it has the platform
* settings for the target plat instead). */
#include "ghcautoconf.h"
/* Pull in the autoconf defines (HAVE_FOO), and all the platform defines
* for this build (foo_HOST_ARCH etc.)
*/
#include "ghcconfig.h"
#define GLOBAL_VAR(name,value,ty) \
{-# NOINLINE name #-}; \
......
......@@ -162,7 +162,7 @@ Library
if flag(stage3)
Include-Dirs: stage2
Install-Includes: HsVersions.h, ghc_boot_platform.h
Install-Includes: HsVersions.h
c-sources:
parser/cutils.c
......
......@@ -29,20 +29,23 @@ compiler_stage1_C_FILES_NODEPS = compiler/parser/cutils.c
# we just skip the check.
compiler_NO_CHECK = YES
dec1 = 0
dec2 = 1
dec3 = 2
ifneq "$(BINDIST)" "YES"
compiler/stage1/package-data.mk : compiler/stage1/build/Config.hs
compiler/stage2/package-data.mk : compiler/stage2/build/Config.hs
compiler/stage3/package-data.mk : compiler/stage3/build/Config.hs
compiler/stage1/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
compiler/stage2/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
compiler/stage3/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
compiler/stage1/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
compiler/stage2/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
compiler/stage3/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
compiler/stage1/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
compiler/stage2/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
compiler/stage3/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
$(foreach n,1 2 3, \
$(eval compiler/stage$n/package-data.mk : $(includes_$(dec$n)_H_PLATFORM)) \
$(eval compiler/stage$n/package-data.mk : $(includes_$(dec$n)_H_CONFIG)) \
)
$(foreach n,1 2 3, \
$(eval compiler/stage$n/package-data.mk : compiler/stage$n/build/Config.hs) \
$(eval compiler/stage$n/build/PlatformConstants.o : $(includes_GHCCONSTANTS_HASKELL_TYPE)) \
$(eval compiler/stage$n/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)) \
$(eval compiler/stage$n/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)) \
)
endif
compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
......@@ -62,7 +65,7 @@ compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
@echo >> $@
@echo 'import GHC.Version' >> $@
@echo >> $@
@echo '#include "ghc_boot_platform.h"' >> $@
@echo '#include "ghcplatform.h"' >> $@
@echo >> $@
@echo 'cBuildPlatformString :: String' >> $@
@echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
......@@ -80,82 +83,6 @@ compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
@echo 'cStage = show (STAGE :: Int)' >> $@
@echo done.
# -----------------------------------------------------------------------------
# Create platform includes
# Here we generate a little header file containing CPP symbols that GHC
# uses to determine which platform it is building on/for. The platforms
# can differ between stage1 and stage2 if we're cross-compiling, so we
# need one of these header files per stage.
PLATFORM_H = ghc_boot_platform.h
compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
$(call removeFiles,$@)
@echo "Creating $@..."
@echo "#if !defined(__PLATFORM_H__)" >> $@
@echo "#define __PLATFORM_H__" >> $@
@echo >> $@
@echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
@echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
@echo >> $@
@echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
@echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
@echo >> $@
@echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
@echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
@echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
@echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
@echo >> $@
@echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
@echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
@echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
@echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
@echo >> $@
@echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
@echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
@echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
@echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
@echo >> $@
@echo "#endif /* __PLATFORM_H__ */" >> $@
@echo "Done."
# For stage2 and above, the BUILD platform is the HOST of stage1, and
# the HOST platform is the TARGET of stage1. The TARGET remains the same
# (stage1 is the cross-compiler, not stage2).
compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
$(call removeFiles,$@)
@echo "Creating $@..."
@echo "#if !defined(__PLATFORM_H__)" >> $@
@echo "#define __PLATFORM_H__" >> $@
@echo >> $@
@echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
@echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
@echo >> $@
@echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
@echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
@echo >> $@
@echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
@echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
@echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
@echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
@echo >> $@
@echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
@echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
@echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
@echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
@echo >> $@
@echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
@echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
@echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
@echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
@echo >> $@
@echo "#endif /* __PLATFORM_H__ */" >> $@
@echo "Done."
compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
"$(CP)" $< $@
# ----------------------------------------------------------------------------
# Generate supporting stuff for prelude/PrimOp.hs
# from prelude/primops.txt
......@@ -180,18 +107,16 @@ PRIMOP_BITS_STAGE1 = $(addprefix compiler/stage1/build/,$(PRIMOP_BITS_NAMES))
PRIMOP_BITS_STAGE2 = $(addprefix compiler/stage2/build/,$(PRIMOP_BITS_NAMES))
PRIMOP_BITS_STAGE3 = $(addprefix compiler/stage3/build/,$(PRIMOP_BITS_NAMES))
compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
compiler_CPP_OPTS += ${GhcCppOpts}
# We add these paths to the Haskell compiler's #include search path list since
# we must avoid #including files by paths relative to the source file as Hadrian
# moves the build artifacts out of the source tree. See #8040.
compiler_HC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
define preprocessCompilerFiles
# $0 = stage
compiler/stage$1/build/primops.txt: compiler/prelude/primops.txt.pp
$$(HS_CPP) -P $$(compiler_CPP_OPTS) -Icompiler/stage$1 -x c $$< | grep -v '^#pragma GCC' > $$@
# $1 = compiler stage (build system stage + 1)
compiler/stage$1/build/primops.txt: \
compiler/prelude/primops.txt.pp \
$(includes_$(dec$1)_H_CONFIG) \
$(includes_$(dec$1)_H_PLATFORM)
$$(HS_CPP) -P $$(compiler_CPP_OPTS) \
-Icompiler/stage$1 \
-I$(BUILD_$(dec$1)_INCLUDE_DIR) \
-x c $$< | grep -v '^#pragma GCC' > $$@
compiler/stage$1/build/primop-data-decl.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
"$$(genprimopcode_INPLACE)" --data-decl < $$< > $$@
......@@ -389,6 +314,17 @@ compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
# after build-package, because that sets compiler_stage1_HC_OPTS:
compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
$(foreach n,1 2 3,$(eval compiler_stage$n_CPP_OPTS += -I$(BUILD_$(dec$n)_INCLUDE_DIR)))
compiler_CPP_OPTS += ${GhcCppOpts}
# We add these paths to the Haskell compiler's #include search path list since
# we must avoid #including files by paths relative to the source file as Hadrian
# moves the build artifacts out of the source tree. See #8040.
compiler_HC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
$(foreach n,1 2 3,$(eval compiler_stage$n_HC_OPTS += -I$(BUILD_$(dec$n)_INCLUDE_DIR)))
ifeq "$(V)" "0"
compiler_stage1_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage1HcOpts)
compiler_stage2_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage2HcOpts)
......@@ -401,12 +337,10 @@ endif
ifneq "$(BINDIST)" "YES"
$(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
$(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
$(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
$(compiler_stage1_depfile_haskell) : $(includes_0_H_CONFIG) $(includes_0_H_PLATFORM)
$(compiler_stage2_depfile_haskell) : $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM)
$(compiler_stage3_depfile_haskell) : $(includes_2_H_CONFIG) $(includes_2_H_PLATFORM)
COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_TYPE)
COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
......
......@@ -1023,6 +1023,9 @@ $(eval $(call bindist-list,.,\
$(BINDIST_EXTRAS) \
includes/Makefile \
$(includes_H_FILES) \
$(includes_1_H_CONFIG) \
$(includes_1_H_PLATFORM) \
$(includes_1_H_VERSION) \
$(includes_DERIVEDCONSTANTS) \
$(includes_GHCCONSTANTS) \
$(libffi_HEADERS) \
......@@ -1064,7 +1067,7 @@ BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
#
# See Note [No stage2 packages when CrossCompiling or Stage1Only].
unix-binary-dist-prep:
unix-binary-dist-prep: $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) $(includes_1_H_VERSION)
$(call removeTrees,bindistprep/)
"$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
set -e; for i in packages LICENSE compiler ghc rts libraries utils docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess install-sh llvm-targets llvm-passes ghc.mk inplace distrib/configure.ac distrib/README distrib/INSTALL; do ln -s ../../$$i $(BIN_DIST_PREP_DIR)/; done
......@@ -1303,9 +1306,9 @@ CLEAN_FILES += compiler/ghc.cabal.old
# as they may still be in old GHC trees:
CLEAN_FILES += includes/GHCConstants.h
CLEAN_FILES += includes/DerivedConstants.h
CLEAN_FILES += includes/ghcautoconf.h
CLEAN_FILES += includes/ghcplatform.h
CLEAN_FILES += includes/ghcversion.h
$(foreach n,0 1 2, \
$(foreach h,$(includes_$n_H_CONFIG) $(includes_$n_H_PLATFORM) $(includes_$n_H_VERSION), \
$(eval CLEAN_FILES += $h)))
CLEAN_FILES += $(includes_SETTINGS)
CLEAN_FILES += utils/ghc-pkg/Version.hs
CLEAN_FILES += compiler/prelude/primops.txt
......@@ -1441,7 +1444,6 @@ maintainer-clean : distclean
.PHONY: bootstrapping-files
# See https://gitlab.haskell.org/ghc/ghc/wikis/building/porting
bootstrapping-files: $(includes_H_CONFIG)
bootstrapping-files: $(includes_DERIVEDCONSTANTS)
bootstrapping-files: $(includes_GHCCONSTANTS)
bootstrapping-files: $(libffi_HEADERS)
......
......@@ -120,11 +120,6 @@ ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(compiler_stage2_p_LIB)
ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_p_LIB))
endif
# Modules here import HsVersions.h, so we need ghc_boot_platform.h
$(ghc_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
$(ghc_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
$(ghc_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
all_ghc_stage1 : $(GHC_STAGE1)
all_ghc_stage2 : $(GHC_STAGE2)
all_ghc_stage3 : $(GHC_STAGE3)
......
......@@ -23,7 +23,7 @@ module Base (
-- * Paths
hadrianPath, configPath, configFile, sourcePath, shakeFilesDir,
generatedDir, generatedPath, stageBinPath, stageLibPath, templateHscPath,
stageBinPath, stageLibPath, templateHscPath,
ghcBinDeps, ghcLibDeps, includesDependencies, haddockDeps,
relativePackageDbPath, packageDbPath, packageDbStamp, mingwStamp,
) where
......@@ -68,22 +68,14 @@ sourcePath = hadrianPath -/- "src"
configH :: FilePath
configH = "mk/config.h"
ghcVersionH :: Action FilePath
ghcVersionH = generatedPath <&> (-/- "ghcversion.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
shakeFilesDir = "hadrian"
-- | The directory in 'buildRoot' containing generated source files that are not
-- package-specific, e.g. @ghcplatform.h@.
generatedDir :: FilePath
generatedDir = "generated"
generatedPath :: Action FilePath
generatedPath = buildRoot <&> (-/- generatedDir)
-- | Path to the package database for a given build stage, relative to the build
-- root.
relativePackageDbPath :: Stage -> FilePath
......@@ -122,10 +114,11 @@ ghcBinDeps stage = mapM (\f -> stageLibPath stage <&> (-/- f))
, "ghci-usage.txt"
]
includesDependencies :: Action [FilePath]
includesDependencies = do
path <- generatedPath
return $ (path -/-) <$> [ "ghcautoconf.h", "ghcplatform.h", "ghcversion.h" ]
includesDependencies :: Stage -> Action [FilePath]
includesDependencies stage = do
p <- stageLibPath stage
pure $ (p -/-) <$>
[ "ghcautoconf.h", "ghcplatform.h", "ghcversion.h" ]
-- | Files the `haddock` binary depends on
haddockDeps :: Stage -> Action [FilePath]
......
......@@ -176,12 +176,12 @@ instance H.Builder Builder where
Autoreconf dir -> return [dir -/- "configure.ac"]
Configure dir -> return [dir -/- "configure"]
Ghc _ Stage0 -> generatedGhcDependencies Stage0
Ghc _ Stage0 -> includesDependencies Stage0
Ghc _ stage -> do
root <- buildRoot
touchyPath <- programPath (vanillaContext Stage0 touchy)
unlitPath <- builderPath Unlit
ghcgens <- generatedGhcDependencies stage
ghcgens <- includesDependencies stage
-- GHC from the previous stage is used to build artifacts in the
-- current stage. Need the previous stage's GHC deps.
......
......@@ -13,7 +13,7 @@ module Packages (
-- * Package information
programName, nonHsMainPackage, autogenPath, programPath, timeoutPath,
rtsContext, rtsBuildPath, libffiBuildPath, libffiLibraryName,
generatedGhcDependencies, ensureConfigured
ensureConfigured
) where
import Hadrian.Package
......@@ -216,12 +216,3 @@ libffiLibraryName = do
(True , False) -> "ffi"
(False, False) -> "Cffi"
(_ , True ) -> "Cffi-6"
-- | Generated header files required by GHC in runtime.
generatedGhcDependencies :: Stage -> Action [FilePath]
generatedGhcDependencies stage = do
let context = vanillaContext stage compiler
bh <- buildPath context <&> (-/- "ghc_boot_platform.h")
ch <- contextPath context <&> (-/- "ghc_boot_platform.h")
is <- includesDependencies
return $ is ++ [bh, ch]
......@@ -46,7 +46,7 @@ toolArgsTarget = do
(Ghc ToolArgs Stage0) [] ["ignored"]
-- need the autogenerated files so that they are precompiled
generatedGhcDependencies Stage0 >>= need
includesDependencies Stage0 >>= need
interpret fake_target Rules.Generate.compilerDependencies >>= need
root <- buildRoot
......
This diff is collapsed.
......@@ -99,15 +99,16 @@ libraryArgs = do
configureArgs :: Args
configureArgs = do
top <- expr topDirectory
root <- getBuildRoot
pkg <- getPackage
stage <- getStage
libPath <- expr $ stageLibPath stage
let conf key expr = do
values <- unwords <$> expr
not (null values) ?
arg ("--configure-option=" ++ key ++ "=" ++ values)
cFlags = mconcat [ remove ["-Werror"] cArgs
, getStagedSettingList ConfCcArgs
, arg $ "-I" ++ top -/- root -/- generatedDir
, arg $ "-I" ++ libPath
-- See https://github.com/snowleopard/hadrian/issues/523
, arg $ "-iquote"
, arg $ top -/- pkgPath pkg
......@@ -127,7 +128,7 @@ configureArgs = do
, conf "--with-curses-libraries" $ arg =<< getSetting CursesLibDir
, flag CrossCompiling ? (conf "--host" $ arg =<< getSetting TargetPlatformFull)
, conf "--with-cc" $ arg =<< getBuilderPath . (Cc CompileC) =<< getStage
, notStage0 ? (arg =<< ("--ghc-option=-ghcversion-file=" ++) <$> expr ((-/-) <$> topDirectory <*> ghcVersionH))]
, notStage0 ? (arg =<< ("--ghc-option=-ghcversion-file=" ++) <$> expr ((-/-) <$> topDirectory <*> ghcVersionH stage))]
bootPackageConstraints :: Args
bootPackageConstraints = stage0 ? do
......@@ -140,8 +141,9 @@ bootPackageConstraints = stage0 ? do
cppArgs :: Args
cppArgs = do
root <- getBuildRoot
arg $ "-I" ++ root -/- generatedDir
stage <- getStage
libPath <- expr $ stageLibPath stage
arg $ "-I" ++ libPath
withBuilderKey :: Builder -> String
withBuilderKey b = case b of
......
......@@ -22,15 +22,16 @@ import UserSettings
cIncludeArgs :: Args
cIncludeArgs = do
pkg <- getPackage
root <- getBuildRoot
path <- getBuildPath
incDirs <- getContextData includeDirs
depDirs <- getContextData depIncludeDirs
stage <- getStage
iconvIncludeDir <- getSetting IconvIncludeDir
gmpIncludeDir <- getSetting GmpIncludeDir
ffiIncludeDir <- getSetting FfiIncludeDir
libPath <- expr $ stageLibPath stage
mconcat [ notStage0 ||^ package compiler ? arg "-Iincludes"
, arg $ "-I" ++ root -/- generatedDir
, arg $ "-I" ++ libPath
, arg $ "-I" ++ path
, pure . map ("-I"++) . filter (/= "") $ [iconvIncludeDir, gmpIncludeDir]
, flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir)
......
module Settings.Builders.DeriveConstants (deriveConstantsBuilderArgs) where
module Settings.Builders.DeriveConstants (
deriveConstantsBuilderArgs, deriveConstantsPairs
) where
import Builder
import Settings.Builders.Common
deriveConstantsPairs :: [(String, String)]
deriveConstantsPairs =
[ ("DerivedConstants.h", "--gen-header")
, ("GHCConstantsHaskellType.hs", "--gen-haskell-type")
, ("platformConstants", "--gen-haskell-value")
, ("GHCConstantsHaskellWrappers.hs", "--gen-haskell-wrappers")
, ("GHCConstantsHaskellExports.hs", "--gen-haskell-exports")
]
-- TODO: do we need to support `includes_CC_OPTS += -DDYNAMIC_BY_DEFAULT`?
deriveConstantsBuilderArgs :: Args
deriveConstantsBuilderArgs = builder DeriveConstants ? do
......@@ -12,11 +23,8 @@ deriveConstantsBuilderArgs = builder DeriveConstants ? do
[a, b] -> (a, b)
_ -> error $ "DeriveConstants: expected two outputs, got " ++ show outs
mconcat
[ output "**/DerivedConstants.h" ? arg "--gen-header"
, output "**/GHCConstantsHaskellType.hs" ? arg "--gen-haskell-type"
, output "**/platformConstants" ? arg "--gen-haskell-value"
, output "**/GHCConstantsHaskellWrappers.hs" ? arg "--gen-haskell-wrappers"
, output "**/GHCConstantsHaskellExports.hs" ? arg "--gen-haskell-exports"
[ mconcat $ flip fmap deriveConstantsPairs $ \(fileName, flag) ->
output ("**/" ++ fileName) ? arg flag
, arg "-o", arg outputFile
, arg "--tmpdir", arg tempDir
, arg "--gcc-program", arg =<< getBuilderPath (Cc CompileC Stage1)
......@@ -28,13 +36,14 @@ deriveConstantsBuilderArgs = builder DeriveConstants ? do
includeCcArgs :: Args
includeCcArgs = do
root <- getBuildRoot
stage <- getStage
libPath <- expr $ stageLibPath stage
mconcat [ cArgs
, cWarnings
, getSettingList $ ConfCcArgs Stage1
, flag GhcUnregisterised ? arg "-DUSE_MINIINTERPRETER"
, arg "-Irts"
, arg "-Iincludes"
, arg $ "-I" ++ root -/- generatedDir
, arg $ "-I" ++ libPath
, notM ghcWithSMP ? arg "-DNOSMP"
, arg "-fcommon" ]
......@@ -161,7 +161,8 @@ commonGhcArgs :: Args
commonGhcArgs = do
way <- getWay
path <- getBuildPath
ghcVersion <- expr ghcVersionH
stage <- getStage
ghcVersion <- expr $ ghcVersionH stage
mconcat [ arg "-hisuf", arg $ hisuf way
, arg "-osuf" , arg $ osuf way
, arg "-hcsuf", arg $ hcsuf way
......@@ -208,10 +209,11 @@ includeGhcArgs :: Args
includeGhcArgs = do
pkg <- getPackage
path <- getBuildPath
root <- getBuildRoot
context <- getContext
srcDirs <- getContextData srcDirs
autogen <- expr $ autogenPath context
stage <- getStage
libPath <- expr $ stageLibPath stage
let cabalMacros = autogen -/- "cabal_macros.h"
expr $ need [cabalMacros]
mconcat [ arg "-i"
......@@ -219,6 +221,6 @@ includeGhcArgs = do
, arg $ "-i" ++ autogen
, pure [ "-i" ++ pkgPath pkg -/- dir | dir <- srcDirs ]
, cIncludeArgs
, arg $ "-I" ++ root -/- generatedDir
, arg $ "-optc-I" ++ root -/- generatedDir
, arg $ "-I" ++ libPath
, arg $ "-optc-I" ++ libPath
, pure ["-optP-include", "-optP" ++ cabalMacros] ]
......@@ -6,12 +6,12 @@ import Settings.Builders.Common
hsCppBuilderArgs :: Args
hsCppBuilderArgs = builder HsCpp ? do
stage <- getStage
root <- getBuildRoot
ghcPath <- expr $ buildPath (vanillaContext stage compiler)
libPath <- expr $ stageLibPath stage
mconcat [ getSettingList HsCppArgs
, arg "-P"
, arg "-Iincludes"
, arg $ "-I" ++ root -/- generatedDir
, arg $ "-I" ++ libPath
, arg $ "-I" ++ ghcPath
, arg "-x", arg "c"
, arg =<< getInput ]
This diff is collapsed.
......@@ -190,8 +190,12 @@ ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
rts_$1_DTRACE_OBJS = rts/dist/build/RtsProbes.$$($1_osuf)
$$(rts_$1_DTRACE_OBJS) : $$(rts_$1_OBJS)
$(DTRACE) -G -C $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) -DDTRACE -s rts/RtsProbes.d -o \
$$@ $$(rts_$1_OBJS)
$(DTRACE) -G -C \
$$(addprefix -I,$$(GHC_INCLUDE_DIRS)) \
-I$$(BUILD_1_INCLUDE_DIR) \
-DDTRACE -s rts/RtsProbes.d \
-o $$@ \
$$(rts_$1_OBJS)
endif
endif
......@@ -352,7 +356,12 @@ endif
# support for registerised builds on this arch. -- BL 2010/02/03
# WARNING_OPTS += -Wcast-align
STANDARD_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS)) -Irts -Irts/dist/build
STANDARD_OPTS += \
$(addprefix -I,$(GHC_INCLUDE_DIRS)) \
-I$(BUILD_1_INCLUDE_DIR) \
-Irts \
-Irts/dist/build
# COMPILING_RTS is only used when building Win32 DLL support.
STANDARD_OPTS += -DCOMPILING_RTS -DFS_NAMESPACE=rts
......@@ -568,6 +577,10 @@ endif
$(eval $(call dependencies,rts,dist,1))
$(rts_dist_depfile_c_asm) : $(includes_dist_H_CONFIG)
$(rts_dist_depfile_c_asm) : $(includes_dist_H_PLATFORM)
$(rts_dist_depfile_c_asm) : $(includes_dist_H_VERSION)
$(rts_dist_depfile_c_asm) : $(DTRACEPROBES_H)
ifneq "$(UseSystemLibFFI)" "YES"
$(rts_dist_depfile_c_asm) : $(libffi_HEADERS)
......@@ -594,7 +607,7 @@ DTRACE_FLAGS = -x cpppath=$(CC)
endif
DTRACEPROBES_SRC = rts/RtsProbes.d
$(DTRACEPROBES_H): $(DTRACEPROBES_SRC) includes/ghcplatform.h | $$(dir $$@)/.
$(DTRACEPROBES_H): $(DTRACEPROBES_SRC) $(includes_1_H_PLATFORM) | $$(dir $$@)/.
"$(DTRACE)" $(filter -I%,$(rts_CC_OPTS)) -C $(DTRACE_FLAGS) -h -o $@ -s $<
endif
......@@ -610,9 +623,9 @@ ifeq "$(HaveLibMingwEx)" "YES"
rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
endif
$(eval $(call manual-package-config,rts))
$(eval $(call manual-package-config,rts,1))
rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
rts/dist/package.conf.inplace : $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) $(includes_1_H_VERSION)
# -----------------------------------------------------------------------------
# installing
......
......@@ -67,7 +67,7 @@ extra-libraries:
#if defined(INSTALLING)
include-dirs: INCLUDE_DIR FFI_INCLUDE_DIR
#else /* !INSTALLING */
include-dirs: TOP"/rts/dist/build" TOP"/includes" TOP"/includes/dist-derivedconstants/header" FFI_INCLUDE_DIR
include-dirs: TOP"/rts/dist/build" TOP"/includes" TOP"/includes/dist-derivedconstants/header" FFI_INCLUDE_DIR TOP"/includes/dist-install/build"
#endif
includes: Stg.h
......
......@@ -30,7 +30,7 @@ ifneq "$$(NO_GENERATED_MAKEFILE_RULES)" "YES"
# Some of the Haskell files (e.g. utils/hsc2hs/Main.hs) (directly or
# indirectly) include the generated includes files.
$$($1_$2_depfile_haskell) : $$(includes_H_CONFIG) $$(includes_H_PLATFORM)
$$($1_$2_depfile_haskell) : $$(includes_$3_H_CONFIG) $$(includes_$3_H_PLATFORM)
$$($1_$2_depfile_haskell) : $$($1_$2_HS_SRCS) $$($1_$2_HS_BOOT_SRCS) $$$$($1_$2_HC_MK_DEPEND_DEP) | $$$$(dir $$$$@)/.
$$(call removeFiles,$$@.tmp)
......@@ -65,7 +65,7 @@ endif
$$@.tmp2 > $$@
# Some of the C files (directly or indirectly) include the generated
# includes files.
$$($1_$2_depfile_c_asm) : $$(includes_H_CONFIG) $$(includes_H_PLATFORM)
$$($1_$2_depfile_c_asm) : $$(includes_$3_H_CONFIG) $$(includes_$3_H_PLATFORM)
$$($1_$2_depfile_c_asm) : $$($1_$2_C_FILES_DEPS) $$($1_$2_S_FILES) $$($1_$2_CMM_FILES) | $$$$(dir $$$$@)/.
$$(call removeFiles,$$@.tmp)
......
......@@ -16,7 +16,7 @@ $(call trace, build-package-way($1,$2,$3))
$(call profStart, build-package-way($1,$2,$3))
$(call distdir-way-opts,$1,$2,$3,$4)
$(call hs-suffix-way-rules,$1,$2,$3)
$(call hs-suffix-way-rules,$1,$2,$3,$4)
$(call hs-objs,$1,$2,$3)
......
......@@ -178,7 +178,7 @@ endif
$$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
$$(eval $$(call hs-suffix-rules-srcdir,$1,$2,$$(dir))))
$(call hs-suffix-way-rules,$1,$2,$$($1_$2_PROGRAM_WAY))
$(call hs-suffix-way-rules,$1,$2,$$($1_$2_PROGRAM_WAY),$3)
$(call c-objs,$1,$2,$$($1_$2_PROGRAM_WAY))
$(call hs-objs,$1,$2,$$($1_$2_PROGRAM_WAY))
......
......@@ -12,7 +12,7 @@
define hs-suffix-way-rules-srcdir
# args: $1 = dir, $2 = distdir, $3 = way, $4 = srcdir
# args: $1 = dir, $2 = distdir, $3 = way, $4 = srcdir, $5 = stage
ifneq "$$(BINDIST)" "YES"
......@@ -35,11 +35,21 @@ $1/$2/build/%.$$($3_hcsuf) : $1/$4/%.lhs $$(LAX_DEPS_FOLLOW) $$$$($1_$2_HC_DEP)
# XXX: for some reason these get used in preference to the direct
# .hs->.o rule, I don't know why --SDM
$1/$2/build/%.$$($3_osuf) : $1/$4/%.hc includes/ghcautoconf.h includes/ghcplatform.h | $$$$(dir $$$$@)/.
$$(call cmd,$1_$2_CC) $$($1_$2_$3_ALL_CC_OPTS) $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) -x c -c $$< -o $$@ $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),-dyno $$(addsuffix .$$(dyn_osuf),$$(basename $$@)))
$1/$2/build/%.$$($3_osuf) : $1/$2/build/%.hc includes/ghcautoconf.h includes/ghcplatform.h
$$(call cmd,$1_$2_CC) $$($1_$2_$3_ALL_CC_OPTS) $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) -x c -c $$< -o $$@ $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),-dyno $$(addsuffix .$$(dyn_osuf),$$(basename $$@)))
$1/$2/build/%.$$($3_osuf) : $1/$4/%.hc $$(includes_$5_H_CONFIG) $$(includes_$5_H_PLATFORM) | $$$$(dir $$$$@)/.
$$(call cmd,$1_$2_CC) \
$$($1_$2_$3_ALL_CC_OPTS) \
$$(addprefix -I,$$(GHC_INCLUDE_DIRS)) \
-I$$(BUILD_$5_INCLUDE_DIR) \
-x c -c $$< -o $$@ \
$$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),-dyno $$(addsuffix .$$(dyn_osuf),$$(basename $$@)))
$1/$2/build/%.$$($3_osuf) : $1/$2/build/%.hc $$(includes_$5_H_CONFIG) $$(includes_$5_H_PLATFORM)
$$(call cmd,$1_$2_CC) \
$$($1_$2_$3_ALL_CC_OPTS) \
$$(addprefix -I,$$(GHC_INCLUDE_DIRS)) \
-I$$(BUILD_$5_INCLUDE_DIR) \
-x c -c $$< -o $$@ \
$$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),-dyno $$(addsuffix .$$(dyn_osuf),$$(basename $$@)))
# $1/$2/build/%.$$($3_osuf) : $1/$2/build/%.$$($3_hcsuf)
# $$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
......
......@@ -11,7 +11,7 @@
# -----------------------------------------------------------------------------
define hs-suffix-way-rules # args: $1 = dir, $2 = distdir, $3 = way
define hs-suffix-way-rules # args: $1 = dir, $2 = distdir, $3 = way, $4 = stage
ifeq "$3 $$($1_$2_DYNAMIC_TOO)" "dyn YES"
# We only want this rule to be used for Haskell sources, not for
......@@ -106,7 +106,7 @@ else
# [1] https://www.gnu.org/software/make/manual/make.html#Implicit-Rule-Search
$$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
$$(eval $$(call hs-suffix-way-rules-srcdir,$1,$2,$3,$$(dir))))
$$(eval $$(call hs-suffix-way-rules-srcdir,$1,$2,$3,$$(dir),$4)))
ifneq "$$(BINDIST)" "YES"
......
......@@ -11,15 +11,20 @@
# -----------------------------------------------------------------------------
define manual-package-config # args: $1 = dir
$(call trace, manual-package-config($1))
$(call profStart, manual-package-config($1))
define manual-package-config
# args:
# $1 = dir
# $2 = stage
$(call trace, manual-package-config($1, $2))
$(call profStart, manual-package-config($1, $2))
$1/dist/package.conf.inplace : $1/package.conf.in $$$$(ghc-pkg_INPLACE) | $$$$(dir $$$$@)/.
$$(HS_CPP) -P \
-DTOP='"$$(TOP)"' \
$$($1_PACKAGE_CPP_OPTS) \
-x c $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) $$< -o $$@.raw
$$(addprefix -I,$$(GHC_INCLUDE_DIRS)) \
-I$$(BUILD_$2_INCLUDE_DIR) \
-x c $$< -o $$@.raw