summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-07-25 16:46:48 -0400
committerBen Gamari <ben@smart-cactus.org>2021-09-20 10:25:14 -0400
commitd5daac91d724f305f216c93cad964d5bc27d22cd (patch)
treec69e5fb6215636a29dae771589a105ad8db95e4c
parent3d48bce34b830a551345db760f5281db0f7db593 (diff)
downloadhaskell-d5daac91d724f305f216c93cad964d5bc27d22cd.tar.gz
configure: Add check for whether CC supports --target
-rw-r--r--configure.ac6
-rw-r--r--distrib/configure.ac.in4
-rw-r--r--m4/fp_cc_supports_target.m433
3 files changed, 42 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 7783065664..f86ffaaf97 100644
--- a/configure.ac
+++ b/configure.ac
@@ -785,7 +785,7 @@ dnl If gcc, make sure it's at least 4.7
dnl
FP_GCC_VERSION
-dnl ** See whether gcc supports -no-pie
+dnl ** See whether cc supports -no-pie
FP_GCC_SUPPORTS_NO_PIE
dnl ** Used to determine how to compile ghc-prim's atomics.c, used by
@@ -809,6 +809,10 @@ 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
+dnl ** See whether cc supports --target=<triple> and set
+dnl CONF_CC_OPTS_STAGE[12] accordingly.
+FP_CC_SUPPORTS_TARGET
+
# See rules/distdir-way-opts.mk for details.
# Flags passed to the C compiler
AC_SUBST(CONF_CC_OPTS_STAGE0)
diff --git a/distrib/configure.ac.in b/distrib/configure.ac.in
index 2a3425b1a6..b0fbd4bb77 100644
--- a/distrib/configure.ac.in
+++ b/distrib/configure.ac.in
@@ -165,6 +165,10 @@ dnl May need to use gcc to find platform details.
dnl --------------------------------------------------------------
FPTOOLS_SET_HASKELL_PLATFORM_VARS
+dnl ** See whether cc supports --target=<triple> and set
+dnl CONF_CC_OPTS_STAGE[12] accordingly.
+FP_CC_SUPPORTS_TARGET
+
dnl TargetWordSize for settings file
AC_CHECK_SIZEOF(void *, 4)
if test "x$ac_cv_sizeof_void_p" = "x0"; then
diff --git a/m4/fp_cc_supports_target.m4 b/m4/fp_cc_supports_target.m4
new file mode 100644
index 0000000000..b99b5bf194
--- /dev/null
+++ b/m4/fp_cc_supports_target.m4
@@ -0,0 +1,33 @@
+# FP_CC_SUPPORTS_TARGET
+# ---------------------
+# Does CC support the --target=<triple> option? If so, we should pass it
+# whenever possible to avoid ambiguity and potential compile-time errors (e.g.
+# see #20162).
+#
+# The primary effect of this is updating CONF_CC_OPTS_STAGE[12] to
+# explicitly ask the compiler to generate code for the $TargetPlatform.
+AC_DEFUN([FP_CC_SUPPORTS_TARGET],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([FPTOOLS_SET_PLATFORM_VARS])
+ 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
+ CONF_CC_SUPPORTS_TARGET=YES
+ AC_MSG_RESULT([yes])
+ else
+ CONF_CC_SUPPORTS_TARGET=NO
+ AC_MSG_RESULT([no])
+ fi
+ rm -f conftest.c conftest
+
+ if test $CONF_CC_SUPPORTS_TARGET = YES ; then
+ CONF_CC_OPTS_STAGE1="--target=$LlvmTarget $CONF_CC_OPTS_STAGE1"
+ CONF_CC_OPTS_STAGE2="--target=$LlvmTarget $CONF_CC_OPTS_STAGE2"
+ CONF_CXX_OPTS_STAGE1="--target=$LlvmTarget $CONF_CXX_OPTS_STAGE1"
+ CONF_CXX_OPTS_STAGE2="--target=$LlvmTarget $CONF_CXX_OPTS_STAGE2"
+ CONF_GCC_LINKER_OPTS_STAGE1="--target=$LlvmTarget $CONF_GCC_LINKER_OPTS_STAGE1"
+ CONF_GCC_LINKER_OPTS_STAGE2="--target=$LlvmTarget $CONF_GCC_LINKER_OPTS_STAGE2"
+ fi
+])
+