summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-10-23 04:22:10 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-31 09:05:16 -0400
commitf5471c0baaa5c05488888f6d51485031e621a90b (patch)
tree0ef66802e4a14e46e0b8e57c04c4d3eb073eca00
parente4095c0c85b9c9f70f3c3d665370916e8fd4f616 (diff)
downloadhaskell-f5471c0baaa5c05488888f6d51485031e621a90b.tar.gz
Modularize autoconf platform detection
This will allow better reuse of it, such as in the upcoming RTS configure script. Progress towards #17191
-rw-r--r--configure.ac28
-rw-r--r--distrib/configure.ac.in25
-rw-r--r--m4/fp_cc_supports_target.m42
-rw-r--r--m4/fp_prog_sh.m42
-rw-r--r--m4/fptools_set_haskell_platform_vars.m4105
-rw-r--r--m4/fptools_set_platform_vars.m4184
-rw-r--r--m4/ghc_convert_platform_parts.m49
-rw-r--r--m4/ghc_llvm_target.m49
8 files changed, 200 insertions, 164 deletions
diff --git a/configure.ac b/configure.ac
index 17d87315f5..7c0f80cf68 100644
--- a/configure.ac
+++ b/configure.ac
@@ -265,7 +265,7 @@ AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
-FPTOOLS_SET_PLATFORM_VARS
+FPTOOLS_SET_PLATFORMS_VARS
FP_PROG_SH
@@ -374,7 +374,7 @@ case "$target" in
esac
AC_SUBST(TargetHasRTSLinker)
-# Requires FPTOOLS_SET_PLATFORM_VARS to be run first.
+# Requires FPTOOLS_SET_PLATFORMS_VARS to be run first.
FP_FIND_ROOT
@@ -806,6 +806,11 @@ FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAG
FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE2],[CONF_GCC_LINKER_OPTS_STAGE2],[CONF_LD_LINKER_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
# Stage 3 won't be supported by cross-compilation
+GHC_LLVM_TARGET_SET_VAR
+# we intend to pass trough --targets to llvm as is.
+LLVMTarget_CPP=` echo "$LlvmTarget"`
+AC_SUBST(LLVMTarget_CPP)
+
dnl ** See whether cc supports --target=<triple> and set
dnl CONF_CC_OPTS_STAGE[12] accordingly.
FP_CC_SUPPORTS_TARGET
@@ -835,7 +840,24 @@ AC_SUBST(CONF_HC_OPTS_STAGE2)
dnl ** Set up the variables for the platform in the settings file.
dnl May need to use gcc to find platform details.
dnl --------------------------------------------------------------
-FPTOOLS_SET_HASKELL_PLATFORM_VARS
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Build])
+
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host])
+AC_SUBST(HaskellHostArch)
+AC_SUBST(HaskellHostOs)
+
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Target])
+AC_SUBST(HaskellTargetArch)
+AC_SUBST(HaskellTargetOs)
+
+GHC_SUBSECTIONS_VIA_SYMBOLS
+AC_SUBST(TargetHasSubsectionsViaSymbols)
+
+GHC_IDENT_DIRECTIVE
+AC_SUBST(TargetHasIdentDirective)
+
+GHC_GNU_NONEXEC_STACK
+AC_SUBST(TargetHasGnuNonexecStack)
dnl ** figure out how to do context diffs
FP_PROG_CONTEXT_DIFF
diff --git a/distrib/configure.ac.in b/distrib/configure.ac.in
index d3aee52220..533be9dfac 100644
--- a/distrib/configure.ac.in
+++ b/distrib/configure.ac.in
@@ -37,15 +37,15 @@ AC_SUBST(LibdwIncludeDir)
UseLibffiForAdjustors=@UseLibffiForAdjustors@
AC_SUBST(UseLibffiForAdjustors)
-# We have to run these unconditionally as FPTOOLS_SET_PLATFORM_VARS wants the
+# We have to run these unconditionally as FPTOOLS_SET_PLATFORMS_VARS wants the
# values it computes.
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
-FPTOOLS_SET_PLATFORM_VARS
+FPTOOLS_SET_PLATFORMS_VARS
-# Requires FPTOOLS_SET_PLATFORM_VARS to be run first.
+# Requires FPTOOLS_SET_PLATFORMS_VARS to be run first.
FP_FIND_ROOT
# ToDo: if Stage1Only=YES, should be YES
@@ -168,7 +168,24 @@ AC_SUBST(CONF_CPP_OPTS_STAGE2)
dnl ** Set up the variables for the platform in the settings file.
dnl May need to use gcc to find platform details.
dnl --------------------------------------------------------------
-FPTOOLS_SET_HASKELL_PLATFORM_VARS
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Build])
+
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host])
+AC_SUBST(HaskellHostArch)
+AC_SUBST(HaskellHostOs)
+
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Target])
+AC_SUBST(HaskellTargetArch)
+AC_SUBST(HaskellTargetOs)
+
+GHC_SUBSECTIONS_VIA_SYMBOLS
+AC_SUBST(TargetHasSubsectionsViaSymbols)
+
+GHC_IDENT_DIRECTIVE
+AC_SUBST(TargetHasIdentDirective)
+
+GHC_GNU_NONEXEC_STACK
+AC_SUBST(TargetHasGnuNonexecStack)
dnl ** See whether cc supports --target=<triple> and set
dnl CONF_CC_OPTS_STAGE[12] accordingly.
diff --git a/m4/fp_cc_supports_target.m4 b/m4/fp_cc_supports_target.m4
index b99b5bf194..3ca01d85e1 100644
--- a/m4/fp_cc_supports_target.m4
+++ b/m4/fp_cc_supports_target.m4
@@ -9,7 +9,7 @@
AC_DEFUN([FP_CC_SUPPORTS_TARGET],
[
AC_REQUIRE([AC_PROG_CC])
- AC_REQUIRE([FPTOOLS_SET_PLATFORM_VARS])
+ AC_REQUIRE([GHC_LLVM_TARGET_SET_VAR])
AC_MSG_CHECKING([whether $1 CC supports --target])
echo 'int main() { return 0; }' > conftest.c
if $CC --target=$LlvmTarget -Werror conftest.c > /dev/null ; then
diff --git a/m4/fp_prog_sh.m4 b/m4/fp_prog_sh.m4
index f7c2c49fe8..18e909da51 100644
--- a/m4/fp_prog_sh.m4
+++ b/m4/fp_prog_sh.m4
@@ -3,7 +3,7 @@
# Find a functional Bourne shell
AC_DEFUN([FP_PROG_SH],
[
- AC_REQUIRE([FPTOOLS_SET_PLATFORM_VARS]) dnl for $windows
+ AC_REQUIRE([FPTOOLS_SET_PLATFORMS_VARS]) dnl for $windows
AC_ARG_VAR(SH,[Use as the full path to a Bourne shell. [default=autodetect]])
AC_PATH_PROGS([SH], [sh bash])
if test "$windows" = "YES"; then
diff --git a/m4/fptools_set_haskell_platform_vars.m4 b/m4/fptools_set_haskell_platform_vars.m4
index 7aec2e1d57..23b7ec8265 100644
--- a/m4/fptools_set_haskell_platform_vars.m4
+++ b/m4/fptools_set_haskell_platform_vars.m4
@@ -1,7 +1,7 @@
-# FPTOOLS_SET_HASKELL_PLATFORM_VARS
+# FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS
# ----------------------------------
-# Set the Haskell platform variables
-AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
+# Drop in shell functions used by FPTOOLS_SET_HASKELL_PLATFORM_VARS
+AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS],
[
checkArch() {
case [$]1 in
@@ -118,29 +118,32 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
;;
esac
}
+])
- dnl Note [autoconf assembler checks and -flto]
- dnl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- dnl
- dnl Autoconf's AC_COMPILE_IFELSE macro is fragile in the case of checks
- dnl which require that the assembler is run. Specifically, GCC does not run
- dnl the assembler if invoked with `-c -flto`; it merely dumps its internal
- dnl AST to the object file, to be compiled and assembled during the final
- dnl link.
- dnl
- dnl This can cause configure checks like that for the
- dnl .subsections_via_symbols directive to pass unexpected (see #16440),
- dnl leading the build system to incorrectly conclude that the directive is
- dnl supported.
- dnl
- dnl For this reason, it is important that configure checks that rely on the
- dnl assembler failing use AC_LINK_IFELSE rather than AC_COMPILE_IFELSE,
- dnl ensuring that the assembler sees the check.
- dnl
-
- dnl ** check for Apple-style dead-stripping support
- dnl (.subsections-via-symbols assembler directive)
+# Note [autoconf assembler checks and -flto]
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Autoconf's AC_COMPILE_IFELSE macro is fragile in the case of checks
+# which require that the assembler is run. Specifically, GCC does not run
+# the assembler if invoked with `-c -flto`; it merely dumps its internal
+# AST to the object file, to be compiled and assembled during the final
+# link.
+#
+# This can cause configure checks like that for the
+# .subsections_via_symbols directive to pass unexpected (see #16440),
+# leading the build system to incorrectly conclude that the directive is
+# supported.
+#
+# For this reason, it is important that configure checks that rely on the
+# assembler failing use AC_LINK_IFELSE rather than AC_COMPILE_IFELSE,
+# ensuring that the assembler sees the check.
+# GHC_SUBSECTIONS_VIA_SYMBOLS
+# ----------------------------------
+# check for Apple-style dead-stripping support
+# (.subsections-via-symbols assembler directive)
+AC_DEFUN([GHC_SUBSECTIONS_VIA_SYMBOLS],
+[
AC_MSG_CHECKING(for .subsections_via_symbols)
dnl See Note [autoconf assembler checks and -flto]
AC_LINK_IFELSE(
@@ -157,9 +160,13 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
],
[TargetHasSubsectionsViaSymbols=NO
AC_MSG_RESULT(no)])
+])
- dnl ** check for .ident assembler directive
-
+# GHC_IDENT_DIRECTIVE
+# ----------------------------------
+# check for .ident assembler directive
+AC_DEFUN([GHC_IDENT_DIRECTIVE],
+[
AC_MSG_CHECKING(whether your assembler supports .ident directive)
dnl See Note [autoconf assembler checks and -flto]
AC_LINK_IFELSE(
@@ -168,13 +175,18 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
TargetHasIdentDirective=YES],
[AC_MSG_RESULT(no)
TargetHasIdentDirective=NO])
+])
- dnl *** check for GNU non-executable stack note support (ELF only)
- dnl (.section .note.GNU-stack,"",@progbits)
-
- dnl This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889:
- dnl Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section}
- dnl so we empty CFLAGS while running this test
+# GHC_GNU_NONEXEC_STACK
+# ----------------------------------
+# *** check for GNU non-executable stack note support (ELF only)
+# (.section .note.GNU-stack,"",@progbits)
+#
+# This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889:
+# Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section}
+# so we empty CFLAGS while running this test
+AC_DEFUN([GHC_GNU_NONEXEC_STACK],
+[
CFLAGS2="$CFLAGS"
CFLAGS=
case $TargetArch in
@@ -201,24 +213,15 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
[AC_MSG_RESULT(no)
TargetHasGnuNonexecStack=NO])
CFLAGS="$CFLAGS2"
+])
- checkArch "$BuildArch" "HaskellBuildArch"
- checkVendor "$BuildVendor"
- checkOS "$BuildOS" ""
-
- checkArch "$HostArch" "HaskellHostArch"
- checkVendor "$HostVendor"
- checkOS "$HostOS" "HaskellHostOs"
-
- checkArch "$TargetArch" "HaskellTargetArch"
- checkVendor "$TargetVendor"
- checkOS "$TargetOS" "HaskellTargetOs"
-
- AC_SUBST(HaskellHostArch)
- AC_SUBST(HaskellHostOs)
- AC_SUBST(HaskellTargetArch)
- AC_SUBST(HaskellTargetOs)
- AC_SUBST(TargetHasSubsectionsViaSymbols)
- AC_SUBST(TargetHasIdentDirective)
- AC_SUBST(TargetHasGnuNonexecStack)
+# FPTOOLS_SET_HASKELL_PLATFORM_VARS
+# ----------------------------------
+# Set the Haskell platform variables
+AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
+[
+ AC_REQUIRE([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS])
+ checkArch "[$]$1Arch" "Haskell$1Arch"
+ checkVendor "[$]$1Vendor"
+ checkOS "[$]$1OS" "Haskell$1Os"
])
diff --git a/m4/fptools_set_platform_vars.m4 b/m4/fptools_set_platform_vars.m4
index 185661a3df..e091f1198c 100644
--- a/m4/fptools_set_platform_vars.m4
+++ b/m4/fptools_set_platform_vars.m4
@@ -1,7 +1,10 @@
-# FPTOOLS_SET_PLATFORM_VARS
+# FPTOOLS_SET_PLATFORMS_VARS
# ----------------------------------
-# Set the platform variables
-AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
+# Set all the platform variables. First massage the default autoconf
+# choices for build, host, and target, then parse it into
+# <platform>Arch, <platform>Vendor, and <platform>OS, and finally define
+# the other variables in terms of those.
+AC_DEFUN([FPTOOLS_SET_PLATFORMS_VARS],
[
# If no argument was given for a configuration variable, then discard
# the guessed canonical system and use the configuration of the
@@ -15,131 +18,104 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
if test "$build_alias" = ""
then
- if test "$bootstrap_target" != ""
- then
- build=$bootstrap_target
- echo "Build platform inferred as: $build"
- else
- echo "Can't work out build platform"
- exit 1
- fi
-
- BuildArch=`echo "$build" | sed 's/-.*//'`
- BuildVendor=`echo "$build" | sed -e 's/.*-\(.*\)-.*/\1/'`
- BuildOS=`echo "$build" | sed 's/.*-//'`
+ FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP([build], [Build])
else
- GHC_CONVERT_CPU([$build_cpu], [BuildArch])
- GHC_CONVERT_VENDOR([$build_vendor], [BuildVendor])
- GHC_CONVERT_OS([$build_os], [$BuildArch], [BuildOS])
+ GHC_CONVERT_PLATFORM_PARTS([build], [Build])
fi
if test "$host_alias" = ""
then
- if test "$bootstrap_target" != ""
- then
- host=$bootstrap_target
- echo "Host platform inferred as: $host"
- else
- echo "Can't work out host platform"
- exit 1
- fi
-
- HostArch=`echo "$host" | sed 's/-.*//'`
- HostVendor=`echo "$host" | sed -e 's/.*-\(.*\)-.*/\1/'`
- HostOS=`echo "$host" | sed 's/.*-//'`
+ FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP([host], [Host])
else
- GHC_CONVERT_CPU([$host_cpu], [HostArch])
- GHC_CONVERT_VENDOR([$host_vendor], [HostVendor])
- GHC_CONVERT_OS([$host_os], [$HostArch], [HostOS])
+ GHC_CONVERT_PLATFORM_PARTS([host], [Host])
fi
if test "$target_alias" = ""
then
if test "$host_alias" != ""
then
- GHC_CONVERT_CPU([$host_cpu], [TargetArch])
- GHC_CONVERT_VENDOR([$host_vendor], [TargetVendor])
- GHC_CONVERT_OS([$host_os], [$TargetArch],[TargetOS])
+ GHC_CONVERT_PLATFORM_PARTS([host], [Target])
else
- if test "$bootstrap_target" != ""
- then
- target=$bootstrap_target
- echo "Target platform inferred as: $target"
- else
- echo "Can't work out target platform"
- exit 1
- fi
-
- TargetArch=`echo "$target" | sed 's/-.*//'`
- TargetVendor=`echo "$target" | sed -e 's/.*-\(.*\)-.*/\1/'`
- TargetOS=`echo "$target" | sed 's/.*-//'`
+ FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP([target], [Target])
fi
else
- GHC_CONVERT_CPU([$target_cpu], [TargetArch])
- GHC_CONVERT_VENDOR([$target_vendor], [TargetVendor])
- GHC_CONVERT_OS([$target_os], [$TargetArch], [TargetOS])
+ GHC_CONVERT_PLATFORM_PARTS([target], [Target])
fi
- GHC_LLVM_TARGET([$target],[$target_cpu],[$target_vendor],[$target_os],[LlvmTarget])
+ FPTOOLS_SET_PLATFORM_VARS([build], [Build])
+ FPTOOLS_SET_PLATFORM_VARS([host], [Host])
+ FPTOOLS_SET_PLATFORM_VARS([target], [Target])
- GHC_SELECT_FILE_EXTENSIONS([$host], [exeext_host], [soext_host])
- GHC_SELECT_FILE_EXTENSIONS([$target], [exeext_target], [soext_target])
windows=NO
case $host in
*-unknown-mingw32)
windows=YES
;;
esac
+])
+
+dnl Attempt at arch agnostic distillation of the above, but it
+dnl doesn't quite work yet. Perhaps after the configure script is
+dnl more split up (#17191) this wil become more feasible.
+
+dnl if test "[$]$1_alias" = ""
+dnl then
+dnl if test "[$]$3_alias" != ""
+dnl then
+dnl GHC_CONVERT_PLATFORM_PARTS($3, $2)
+dnl else
+dnl FPTOOLS_SET_PLATFORMS_VARS($1, $2)
+dnl fi
+dnl else
+dnl GHC_CONVERT_PLATFORM_PARTS($1, $2)
+dnl fi
+
+# FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP(platform,Platform)
+# ----------------------------------
+# Per the comment in FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP's body, we
+# need to sometimes replace inferred platforms with the bootstrap
+# compiler's target platform.
+AC_DEFUN([FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP],
+[
+ if test "$bootstrap_target" != ""
+ then
+ $1=$bootstrap_target
+ echo "$1 platform inferred as: [$]$1"
+ else
+ echo "Can't work out $1 platform"
+ exit 1
+ fi
- BuildPlatform="$BuildArch-$BuildVendor-$BuildOS"
- BuildPlatform_CPP=`echo "$BuildPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
- BuildArch_CPP=` echo "$BuildArch" | sed -e 's/\./_/g' -e 's/-/_/g'`
- BuildVendor_CPP=` echo "$BuildVendor" | sed -e 's/\./_/g' -e 's/-/_/g'`
- BuildOS_CPP=` echo "$BuildOS" | sed -e 's/\./_/g' -e 's/-/_/g'`
-
- HostPlatform="$HostArch-$HostVendor-$HostOS"
- HostPlatform_CPP=`echo "$HostPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
- HostArch_CPP=` echo "$HostArch" | sed -e 's/\./_/g' -e 's/-/_/g'`
- HostVendor_CPP=` echo "$HostVendor" | sed -e 's/\./_/g' -e 's/-/_/g'`
- HostOS_CPP=` echo "$HostOS" | sed -e 's/\./_/g' -e 's/-/_/g'`
-
- TargetPlatform="$TargetArch-$TargetVendor-$TargetOS"
- TargetPlatform_CPP=`echo "$TargetPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
- TargetArch_CPP=` echo "$TargetArch" | sed -e 's/\./_/g' -e 's/-/_/g'`
- TargetVendor_CPP=` echo "$TargetVendor" | sed -e 's/\./_/g' -e 's/-/_/g'`
- TargetOS_CPP=` echo "$TargetOS" | sed -e 's/\./_/g' -e 's/-/_/g'`
-
- # we intend to pass trough --targets to llvm as is.
- LLVMTarget_CPP=` echo "$LlvmTarget"`
-
- echo "GHC build : $BuildPlatform"
- echo "GHC host : $HostPlatform"
- echo "GHC target : $TargetPlatform"
- echo "LLVM target: $LlvmTarget"
-
- AC_SUBST(BuildPlatform)
- AC_SUBST(HostPlatform)
- AC_SUBST(TargetPlatform)
- AC_SUBST(HostPlatform_CPP)
- AC_SUBST(BuildPlatform_CPP)
- AC_SUBST(TargetPlatform_CPP)
-
- AC_SUBST(HostArch_CPP)
- AC_SUBST(BuildArch_CPP)
- AC_SUBST(TargetArch_CPP)
-
- AC_SUBST(HostOS_CPP)
- AC_SUBST(BuildOS_CPP)
- AC_SUBST(TargetOS_CPP)
- AC_SUBST(LLVMTarget_CPP)
-
- AC_SUBST(HostVendor_CPP)
- AC_SUBST(BuildVendor_CPP)
- AC_SUBST(TargetVendor_CPP)
-
- AC_SUBST(exeext_host)
- AC_SUBST(exeext_target)
- AC_SUBST(soext_host)
- AC_SUBST(soext_target)
+ $2[Arch]=`echo "[$]$1" | sed 's/-.*//'`
+ $2[Vendor]=`echo "[$]$1" | sed -e 's/.*-\(.*\)-.*/\1/'`
+ $2[OS]=`echo "[$]$1" | sed 's/.*-//'`
])
+# FPTOOLS_SET_PLATFORM_VARS(platform,Platform)
+# ----------------------------------
+# Set the platform variables for a single plaform (one of build, host,
+# or target). Assumes <platform>Arch, <platform>Vendor, and <platform>OS
+# are defined, and does everything else in terms of them.
+AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
+[
+
+ $2Platform="[$]$2Arch-[$]$2Vendor-[$]$2OS"
+ $2Platform_CPP=`echo "[$]$2Platform" | sed -e 's/\./_/g' -e 's/-/_/g'`
+ $2Arch_CPP=` echo "[$]$2Arch" | sed -e 's/\./_/g' -e 's/-/_/g'`
+ $2Vendor_CPP=` echo "[$]$2Vendor" | sed -e 's/\./_/g' -e 's/-/_/g'`
+ $2OS_CPP=` echo "[$]$2OS" | sed -e 's/\./_/g' -e 's/-/_/g'`
+
+ echo "GHC $1 : [$]$2Platform"
+
+ AC_SUBST($2Platform)
+ AC_SUBST($2Platform_CPP)
+
+ AC_SUBST($2Arch_CPP)
+ AC_SUBST($2OS_CPP)
+ AC_SUBST($2Vendor_CPP)
+
+ GHC_SELECT_FILE_EXTENSIONS([$]$1, [exeext_]$1, [soext_]$1)
+
+ AC_SUBST(exeext_$1)
+ AC_SUBST(soext_$1)
+])
diff --git a/m4/ghc_convert_platform_parts.m4 b/m4/ghc_convert_platform_parts.m4
new file mode 100644
index 0000000000..940326fe3b
--- /dev/null
+++ b/m4/ghc_convert_platform_parts.m4
@@ -0,0 +1,9 @@
+# GHC_CONVERT_PLATFORM_PARTS(input_platform, OutputPlatform)
+# --------------------------------
+# Call all 3 of the underlying `GHC_CONVERT_*` functions to convert the
+# parsed platform from GNU to GHC naming.
+AC_DEFUN([GHC_CONVERT_PLATFORM_PARTS],[
+ GHC_CONVERT_CPU([$]$1[_cpu], $2[Arch])
+ GHC_CONVERT_VENDOR([$]$1[_vendor], $2[Vendor])
+ GHC_CONVERT_OS([$]$1[_os], [$]$2[Arch], $2[OS])
+])
diff --git a/m4/ghc_llvm_target.m4 b/m4/ghc_llvm_target.m4
index 33150e9a8c..abb10d963e 100644
--- a/m4/ghc_llvm_target.m4
+++ b/m4/ghc_llvm_target.m4
@@ -43,3 +43,12 @@ AC_DEFUN([GHC_LLVM_TARGET], [
esac
$5="$llvm_target_cpu-$llvm_target_vendor-$llvm_target_os"
])
+
+# GHC_LLVM_TARGET_SET_VAR
+# -----------------------
+# Sets the cannonical target variable. This stub exists so other macros can
+# require it.
+AC_DEFUN([GHC_LLVM_TARGET_SET_VAR], [
+ AC_REQUIRE([FPTOOLS_SET_PLATFORMS_VARS])
+ GHC_LLVM_TARGET([$target],[$target_cpu],[$target_vendor],[$target_os],[LlvmTarget])
+])