Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
# - [ ] Where do we get the version number from? The configure script _does_ contain
# one and sets it, but should it come from the last release tag this branch is
# contains?
# - [ ] HADRIAN_SETTINGS needs to be removed.
# - [x] HADRIAN_SETTINGS has been removed. Version/platform info now generated by configure.
# - [ ] The hadrian folder needs to be removed.
# - [ ] All sublibs should be SRPs in the relevant cabal.project files. No more
# submodules.
Expand Down Expand Up @@ -169,17 +169,11 @@ TARGET_OS = $(call GHC_INFO,target os)
TARGET_TRIPLE = $(call GHC_INFO,Target platform)
GIT_COMMIT_ID := $(shell git rev-parse HEAD)

define HADRIAN_SETTINGS
[ ("hostPlatformArch", "$(TARGET_ARCH)") \
, ("hostPlatformOS", "$(TARGET_OS)") \
, ("cProjectGitCommitId", "$(GIT_COMMIT_ID)") \
, ("cProjectVersion", "9.14") \
, ("cProjectVersionInt", "914") \
, ("cProjectPatchLevel", "0") \
, ("cProjectPatchLevel1", "0") \
, ("cProjectPatchLevel2", "0") \
]
endef
# HADRIAN_SETTINGS has been removed.
# Version and platform info is now generated by ./configure into:
# - libraries/ghc-boot/GHC/Version.hs (from Version.hs.in)
# - libraries/ghc-boot/GHC/Platform/Host.hs (from Host.hs.in)
# See configure.ac for details.

# Handle CPUS and THREADS
CPUS_DETECT_SCRIPT := ./mk/detect-cpu-count.sh
Expand All @@ -206,6 +200,8 @@ CONFIGURED_FILES := \
compiler/GHC/CmmToLlvm/Version/Bounds.hs \
compiler/ghc.cabal \
libraries/ghc-boot/ghc-boot.cabal \
libraries/ghc-boot/GHC/Version.hs \
libraries/ghc-boot/GHC/Platform/Host.hs \
libraries/ghc-boot-th/ghc-boot-th.cabal \
libraries/ghc-heap/ghc-heap.cabal \
libraries/template-haskell/template-haskell.cabal \
Expand Down Expand Up @@ -587,7 +583,7 @@ $(addprefix _build/stage1/bin/,$(STAGE1_EXECUTABLES)) &: $(CABAL) $(CONFIGURE_SC
@echo "::group::Building stage1 executables ($(STAGE1_EXECUTABLES))..."
# Force cabal to replan
rm -rf _build/stage1/cache
HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' $(CABAL_BUILD) $(STAGE1_TARGETS)
$(CABAL_BUILD) $(STAGE1_TARGETS)
@echo "::endgroup::"

_build/stage1/lib/settings: _build/stage1/bin/ghc-toolchain-bin
Expand Down Expand Up @@ -631,8 +627,7 @@ $(addprefix _build/stage2/bin/,$(STAGE2_EXECUTABLES)) &: $(CABAL) stage1
@echo "::group::Building stage2 executables ($(STAGE2_EXECUTABLES))..."
# Force cabal to replan
rm -rf _build/stage2/cache
HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage1/bin:$(PATH) \
PATH=$(PWD)/_build/stage1/bin:$(PATH) \
$(CABAL_BUILD) --ghc-options="-ghcversion-file=$(abspath ./rts/include/ghcversion.h)" -W $(GHC0) $(STAGE2_TARGETS)
@echo "::endgroup::"

Expand All @@ -645,8 +640,7 @@ $(addprefix _build/stage2/bin/,$(STAGE2_UTIL_EXECUTABLES)) &: $(CABAL) stage1 ca
@echo "::group::Building stage2 utilities ($(STAGE2_UTIL_EXECUTABLES))..."
# Force cabal to replan
rm -rf _build/stage2/cache
HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage1/bin:$(PATH) \
PATH=$(PWD)/_build/stage1/bin:$(PATH) \
$(CABAL_BUILD) --ghc-options="-ghcversion-file=$(abspath ./rts/include/ghcversion.h)" -W $(GHC0) $(STAGE2_UTIL_TARGETS)
@echo "::endgroup::"

Expand Down Expand Up @@ -718,8 +712,7 @@ _build/stage3/lib/targets/%/lib/ghc-interp.js:

# $1 = TIPLET
define build_cross
HADRIAN_SETTINGS='$(call HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage2/bin:$(PWD)/_build/stage3/bin:$(PATH) \
PATH=$(PWD)/_build/stage2/bin:$(PWD)/_build/stage3/bin:$(PATH) \
$(CABAL_BUILD) -W $(GHC2) --happy-options="--template=$(abspath _build/stage2/src/happy-lib-2.1.5/data/)" --with-hsc2hs=$1-hsc2hs --hsc2hs-options='-x' --configure-option='--host=$1' \
$(foreach lib,$(CROSS_EXTRA_LIB_DIRS),--extra-lib-dirs=$(lib)) \
$(foreach include,$(CROSS_EXTRA_INCLUDE_DIRS),--extra-include-dirs=$(include)) \
Expand Down
134 changes: 133 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,138 @@ AC_CONFIG_MACRO_DIR([m4]) # For any custom m4 macros
# --- Define GHC Build Options ---
# Usage: ./configure ProjectVersion=X.Y ...
AC_ARG_WITH([project-version], [AS_HELP_STRING([--with-project-version=VER], [GHC version (default: 9.14)])], [ProjectVersion="$withval"], [ProjectVersion="9.14"])
AC_ARG_WITH([project-version-int], [AS_HELP_STRING([--with-project-version-int=VER], [GHC version as int (default: 913)])], [ProjectVersionInt="$withval"], [ProjectVersionInt="913"])
AC_ARG_WITH([project-version-int], [AS_HELP_STRING([--with-project-version-int=VER], [GHC version as int (default: 914)])], [ProjectVersionInt="$withval"], [ProjectVersionInt="914"])
AC_ARG_WITH([project-version-munged], [AS_HELP_STRING([--with-project-version-munged=VER], [GHC version "munged" (default: 9.14)])], [ProjectVersionMunged="$withval"], [ProjectVersionMunged="9.14"])
AC_ARG_WITH([project-version-for-lib], [AS_HELP_STRING([--with-project-version-for-lib=VER], [GHC version for libraries (default: 9.1400)])], [ProjectVersionForLib="$withval"], [ProjectVersionForLib="9.1400"])
AC_ARG_WITH([project-patch-level], [AS_HELP_STRING([--with-project-patch-level=VER], [GHC patchlevel version (default: 0)])], [ProjectPatchLevel="$withval"], [ProjectPatchLevel="0"])
AC_ARG_WITH([project-patch-level1], [AS_HELP_STRING([--with-project-patch-level1=VER], [GHC patchlevel1 version (default: 0)])], [ProjectPatchLevel1="$withval"], [ProjectPatchLevel1="0"])
AC_ARG_WITH([project-patch-level2], [AS_HELP_STRING([--with-project-patch-level2=VER], [GHC patchlevel2 version (default: 0)])], [ProjectPatchLevel2="$withval"], [ProjectPatchLevel2="0"])

# Git commit ID (captured at configure time)
AC_ARG_WITH([project-git-commit-id], [AS_HELP_STRING([--with-project-git-commit-id=ID], [Git commit hash (default: auto-detect)])],
[ProjectGitCommitId="$withval"], [ProjectGitCommitId="$(git rev-parse HEAD 2>/dev/null || echo unknown)"])

# --- Platform Detection ---
# Auto-detect build machine's architecture and OS using uname, with override options
# These are used to generate GHC.Platform.Host module

# Detect default architecture from uname -m
default_arch=$(uname -m 2>/dev/null || echo unknown)
# Normalize common variants
case "$default_arch" in
arm64) default_arch="aarch64" ;;
amd64) default_arch="x86_64" ;;
esac

# Detect default OS from uname -s
default_os=$(uname -s 2>/dev/null | tr '[[A-Z]]' '[[a-z]]' || echo unknown)
# Normalize common variants
case "$default_os" in
darwin*) default_os="darwin" ;;
linux*) default_os="linux" ;;
mingw*|msys*|cygwin*) default_os="mingw32" ;;
freebsd*) default_os="freebsd" ;;
esac

AC_ARG_WITH([target-arch], [AS_HELP_STRING([--with-target-arch=ARCH], [Target architecture (default: auto-detect from uname)])],
[TargetArch="$withval"], [TargetArch="$default_arch"])
AC_ARG_WITH([target-os], [AS_HELP_STRING([--with-target-os=OS], [Target OS (default: auto-detect from uname)])],
[TargetOS="$withval"], [TargetOS="$default_os"])

# Shell functions to convert platform strings to Haskell types
# (Inline the relevant parts from m4/fptools_set_haskell_platform_vars.m4)
checkArch() {
case $[]1 in
i386)
test -z "$[]2" || eval "$[]2=ArchX86"
;;
x86_64|amd64)
test -z "$[]2" || eval "$[]2=ArchX86_64"
;;
powerpc)
test -z "$[]2" || eval "$[]2=ArchPPC"
;;
powerpc64*)
test -z "$[]2" || eval "$[]2=\"ArchPPC_64 ELF_V2\""
;;
s390x)
test -z "$[]2" || eval "$[]2=ArchS390X"
;;
arm)
test -z "$[]2" || eval "$[]2=\"ArchARM ARMv7 VFPv3D16 HARD\""
;;
aarch64)
test -z "$[]2" || eval "$[]2=ArchAArch64"
;;
riscv64)
test -z "$[]2" || eval "$[]2=ArchRISCV64"
;;
wasm32)
test -z "$[]2" || eval "$[]2=ArchWasm32"
;;
loongarch64)
test -z "$[]2" || eval "$[]2=ArchLoongArch64"
;;
javascript)
test -z "$[]2" || eval "$[]2=ArchJavaScript"
;;
*)
test -z "$[]2" || eval "$[]2=ArchUnknown"
;;
esac
}

checkOS() {
case $[]1 in
linux|linux-android)
test -z "$[]2" || eval "$[]2=OSLinux"
;;
darwin|ios|watchos|tvos)
test -z "$[]2" || eval "$[]2=OSDarwin"
;;
solaris2)
test -z "$[]2" || eval "$[]2=OSSolaris2"
;;
mingw32|mingw64|windows)
test -z "$[]2" || eval "$[]2=OSMinGW32"
;;
freebsd)
test -z "$[]2" || eval "$[]2=OSFreeBSD"
;;
dragonfly)
test -z "$[]2" || eval "$[]2=OSDragonFly"
;;
openbsd)
test -z "$[]2" || eval "$[]2=OSOpenBSD"
;;
netbsd)
test -z "$[]2" || eval "$[]2=OSNetBSD"
;;
wasi)
test -z "$[]2" || eval "$[]2=OSWasi"
;;
aix)
test -z "$[]2" || eval "$[]2=OSAIX"
;;
gnu)
test -z "$[]2" || eval "$[]2=OSHurd"
;;
ghcjs|js)
test -z "$[]2" || eval "$[]2=OSGhcjs"
;;
*)
test -z "$[]2" || eval "$[]2=OSUnknown"
;;
esac
}

# Convert target platform strings to Haskell types
checkArch "$TargetArch" "HaskellTargetArch"
checkOS "$TargetOS" "HaskellTargetOs"

AC_MSG_NOTICE([Target architecture: $TargetArch -> $HaskellTargetArch])
AC_MSG_NOTICE([Target OS: $TargetOS -> $HaskellTargetOs])

# Export these variables for substitution by AC_SUBST
AC_SUBST([ProjectVersion])
AC_SUBST([ProjectVersionInt])
Expand All @@ -22,6 +147,11 @@ AC_SUBST([ProjectVersionForLib])
AC_SUBST([ProjectPatchLevel])
AC_SUBST([ProjectPatchLevel1])
AC_SUBST([ProjectPatchLevel2])
AC_SUBST([ProjectGitCommitId])
AC_SUBST([TargetArch])
AC_SUBST([TargetOS])
AC_SUBST([HaskellTargetArch])
AC_SUBST([HaskellTargetOs])

# For ghc-boot-th.cabal.in
AC_SUBST([Suffix],[""])
Expand Down Expand Up @@ -81,6 +211,8 @@ AC_CONFIG_FILES([
compiler/ghc.cabal
compiler/GHC/CmmToLlvm/Version/Bounds.hs
libraries/ghc-boot/ghc-boot.cabal
libraries/ghc-boot/GHC/Version.hs
libraries/ghc-boot/GHC/Platform/Host.hs
libraries/ghc-boot-th/ghc-boot-th.cabal
libraries/ghc-boot-th-next/ghc-boot-th-next.cabal
libraries/ghc-heap/ghc-heap.cabal
Expand Down
12 changes: 12 additions & 0 deletions libraries/ghc-boot/GHC/Platform/Host.hs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module GHC.Platform.Host where

import GHC.Platform.ArchOS

hostPlatformArch :: Arch
hostPlatformArch = @HaskellTargetArch@

hostPlatformOS :: OS
hostPlatformOS = @HaskellTargetOs@

hostPlatformArchOS :: ArchOS
hostPlatformArchOS = ArchOS hostPlatformArch hostPlatformOS
21 changes: 21 additions & 0 deletions libraries/ghc-boot/GHC/Version.hs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module GHC.Version where

import Prelude -- See Note [Why do we import Prelude here?]

cProjectGitCommitId :: String
cProjectGitCommitId = "@ProjectGitCommitId@"

cProjectVersion :: String
cProjectVersion = "@ProjectVersion@"

cProjectVersionInt :: String
cProjectVersionInt = "@ProjectVersionInt@"

cProjectPatchLevel :: String
cProjectPatchLevel = "@ProjectPatchLevel@"

cProjectPatchLevel1 :: String
cProjectPatchLevel1 = "@ProjectPatchLevel1@"

cProjectPatchLevel2 :: String
cProjectPatchLevel2 = "@ProjectPatchLevel2@"
Loading