Commit 865602e0 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by Ben Gamari

Rework CC/CC_STAGE0 handling in `configure.ac`

Rather than using the non-standard/idiomatic `--with-{gcc,clang}=...`
scheme use the `CC=...` style scheme.

The basic idea is to have Autoconf's CC/CFLAG/CPPFLAG apply to
stage{1,2,3}, while having a separate _STAGE0 set of env-vars
denote the bootstrap-toolchain flags/programs.

This should be simpler, less confusing, and somewhat more in line with
Autoconf's idioms (allowing us to reuse more of Autoconf rather than
(re)inventing our own confusing non-standard m4 macros to do stuff that
Autoconf could almost do already for us)

Morever, expose CC_STAGE0 as a so-called "precious" variable.

So now we can better control which bootstrapping gcc is used
(by default the one used by the stage0 ghc, unless CC_STAGE0 is
overriden)

```
Some influential environment variables:
  CC_STAGE0   C compiler command (bootstrap)
  CC          C compiler command
  CFLAGS      C compiler flags
  ...

Use these variables to override the choices made by `configure' or to
help it to find libraries and programs with nonstandard names/locations.
```

Test Plan: I've tested that cross-compiling with
`--target=powerpc-linux-gnu` still works, and tried a few variants of
settting `CC=` and `CC_STAGE0=`; `./validate` passed as well

Reviewers: erikd, austin, bgamari, simonmar

Reviewed By: simonmar

Subscribers: Phyx, thomie

Differential Revision: https://phabricator.haskell.org/D2078
parent f4e65912
......@@ -471,7 +471,7 @@ AC_DEFUN([FP_SETTINGS],
SettingsWindresCommand="\$topdir/../${mingw_bin_prefix}windres.exe"
SettingsTouchCommand='$topdir/bin/touchy.exe'
else
SettingsCCompilerCommand="$WhatGccIsCalled"
SettingsCCompilerCommand="$CC"
SettingsHaskellCPPCommand="$HaskellCPPCmd"
SettingsHaskellCPPFlags="$HaskellCPPArgs"
SettingsLdCommand="$LdCmd"
......@@ -2067,38 +2067,6 @@ AC_DEFUN([FIND_GHC_BOOTSTRAP_PROG],[
])
# FIND_GCC()
# --------------------------------
# Finds where gcc is
#
# $1 = the variable to set
# $2 = the with option name
# $3 = the command to look for
AC_DEFUN([FIND_GCC],[
if test "$windows" = YES
then
$1="$CC"
else
FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL([$1], [$2], [$3])
# fallback to CC if set and no --with-$2=... was used
if test -z "$With_$2" -a -n "$CC"
then
With_$2="$CC"
$1="$CC"
# From Xcode 5 on/, OS X command line tools do not include gcc
# anymore. Use clang.
elif test -z "$$1"
then
FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL([$1], [clang], [clang])
fi
if test -z "$$1"
then
AC_MSG_ERROR([cannot find $3 nor clang in your PATH])
fi
fi
AC_SUBST($1)
])
AC_DEFUN([MAYBE_OVERRIDE_STAGE0],[
if test ! -z "$With_$1" -a "$CrossCompiling" != "YES"; then
AC_MSG_NOTICE([Not cross-compiling, so --with-$1 also sets $2])
......@@ -2132,13 +2100,13 @@ AC_ARG_WITH(hs-cpp,
# We can't use $CPP here, since HS_CPP_CMD is expected to be a single
# command (no flags), and AC_PROG_CPP defines CPP as "/usr/bin/gcc -E".
HS_CPP_CMD=$WhatGccIsCalled
HS_CPP_CMD=$CC
SOLARIS_GCC_CPP_BROKEN=NO
SOLARIS_FOUND_GOOD_CPP=NO
case $host in
i386-*-solaris2)
GCC_MAJOR_MINOR=`$WhatGccIsCalled --version|grep "gcc (GCC)"|cut -d ' ' -f 3-3|cut -d '.' -f 1-2`
GCC_MAJOR_MINOR=`$CC --version|grep "gcc (GCC)"|cut -d ' ' -f 3-3|cut -d '.' -f 1-2`
if test "$GCC_MAJOR_MINOR" != "3.4"; then
# this is not 3.4.x release so with broken CPP
SOLARIS_GCC_CPP_BROKEN=YES
......
......@@ -38,7 +38,7 @@ test_bindist:
ifeq "$(Windows_Host)" "YES"
mv bindisttest/a/b/c/$(BIN_DIST_NAME) $(BIN_DIST_INST_DIR)
else
cd bindisttest/a/b/c/$(BIN_DIST_NAME) && ./configure --prefix=$(TOP)/$(BIN_DIST_INST_DIR) --with-gcc="$(WhatGccIsCalled)"
cd bindisttest/a/b/c/$(BIN_DIST_NAME) && ./configure --prefix=$(TOP)/$(BIN_DIST_INST_DIR) CC="$(CC)"
cd bindisttest/a/b/c/$(BIN_DIST_NAME) && $(MAKE) install
endif
ifeq "$(GhcProfiled)" "NO"
......
......@@ -33,6 +33,11 @@ fi
AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])
dnl this makes sure `./configure --target=<cross-compile-target>`
dnl works as expected, since we're slightly modifying how Autoconf
dnl interprets build/host/target and how this interacts with $CC tests
test -n "$target_alias" && ac_tool_prefix=$target_alias-
dnl ----------------------------------------------------------
dnl ** Find unixy sort and find commands,
dnl ** which are needed by FP_SETUP_PROJECT_VERSION
......@@ -107,6 +112,11 @@ AC_ARG_ENABLE(tarballs-autodownload,
TarballsAutodownload=YES,
TarballsAutodownload=NO
)
dnl CC_STAGE0 is like the "previous" variable CC (inherited by CC_STAGE[123])
dnl but instead used by stage0 for bootstrapping stage1
AC_ARG_VAR(CC_STAGE0, [C compiler command (bootstrap)])
if test "$WithGhc" != ""; then
FPTOOLS_GHC_VERSION([GhcVersion], [GhcMajVersion], [GhcMinVersion], [GhcPatchLevel])dnl
......@@ -121,7 +131,11 @@ if test "$WithGhc" != ""; then
GhcMinVersion2=`echo "$GhcMinVersion" | sed 's/^\\(.\\)$/0\\1/'`
GhcCanonVersion="$GhcMajVersion$GhcMinVersion2"
BOOTSTRAPPING_GHC_INFO_FIELD([CC_STAGE0],[C compiler command])
dnl infer CC_STAGE0 from `ghc --info` unless explicitly set by user
if test -z "$CC_STAGE0"; then
BOOTSTRAPPING_GHC_INFO_FIELD([CC_STAGE0],[C compiler command])
fi
BOOTSTRAPPING_GHC_INFO_FIELD([LD_STAGE0],[ld command])
BOOTSTRAPPING_GHC_INFO_FIELD([AR_STAGE0],[ar command])
BOOTSTRAPPING_GHC_INFO_FIELD([AR_OPTS_STAGE0],[ar flags])
......@@ -432,13 +446,19 @@ AC_SUBST(TargetPlatformFull)
dnl ** Which gcc to use?
dnl --------------------------------------------------------------
FIND_GCC([WhatGccIsCalled], [gcc], [gcc])
CC="$WhatGccIsCalled"
export CC
# If --with-gcc was used, and we're not cross-compiling, then it also
# applies to the stage0 compiler.
MAYBE_OVERRIDE_STAGE0([gcc],[CC_STAGE0])
AC_ARG_WITH([gcc],
AS_HELP_STRING([--with-gcc=ARG], [Use ARG as the path to gcc (obsolete, use CC=ARG instead) [default=autodetect]]),
AC_MSG_ERROR([--with-gcc=$withval is obsolete (use './configure CC=$withval' or 'CC=$withval ./configure' instead)]))
AC_ARG_WITH([clang],
AS_HELP_STRING([--with-clang=ARG], [Use ARG as the path to gcc (obsolete, use CC=ARG instead) [default=autodetect]]),
AC_MSG_ERROR([--with-clang=$withval is obsolete (use './configure CC=$withval' or 'CC=$withval ./configure' instead)]))
dnl detect compiler (prefer gcc over clang) and set $CC (unless CC already set),
dnl later CC is copied to CC_STAGE{1,2,3}
AC_PROG_CC([gcc clang])
MAYBE_OVERRIDE_STAGE0([ar],[AR_STAGE0])
dnl make extensions visible to allow feature-tests to detect them lateron
......@@ -1155,7 +1175,8 @@ else
fi
echo ["\
Using $CompilerName : $WhatGccIsCalled
Using (for bootstrapping) : $CC_STAGE0
Using $CompilerName : $CC
which is version : $GccVersion
Building a cross compiler : $CrossCompiling
hs-cpp : $HaskellCPPCmd
......
......@@ -59,9 +59,7 @@ XCODE_VERSION()
dnl ** Which gcc to use?
dnl --------------------------------------------------------------
FIND_GCC([WhatGccIsCalled], [gcc], [gcc])
CC="$WhatGccIsCalled"
export CC
AC_PROG_CC([gcc clang])
# --with-hs-cpp/--with-hs-cpp-flags
FP_CPP_CMD_WITH_ARGS(HaskellCPPCmd, HaskellCPPArgs)
......
......@@ -177,7 +177,7 @@ includes_GHCCONSTANTS_HASKELL_EXPORTS = includes/dist-derivedconstants/header/GH
INSTALL_LIBS += $(includes_GHCCONSTANTS_HASKELL_VALUE)
DERIVE_CONSTANTS_FLAGS += --gcc-program "$(WhatGccIsCalled)"
DERIVE_CONSTANTS_FLAGS += --gcc-program "$(CC)"
DERIVE_CONSTANTS_FLAGS += $(addprefix --gcc-flag$(space),$(includes_CC_OPTS) -fcommon)
DERIVE_CONSTANTS_FLAGS += --nm-program "$(NM)"
ifneq "$(OBJDUMP)" ""
......
......@@ -509,11 +509,10 @@ SUPPORTS_THIS_UNIT_ID = @SUPPORTS_THIS_UNIT_ID@
#-----------------------------------------------------------------------------
# C compiler
#
# NB. Don't override $(WhatGccIsCalled) using build.mk, re-configure using
# the flag --with-gcc=<blah> instead. The reason is that the configure script
# NB. Don't override $(CC) using build.mk, re-configure using
# the flag CC=<blah> instead. The reason is that the configure script
# needs to know which gcc you're using in order to perform its tests.
WhatGccIsCalled = @WhatGccIsCalled@
GccVersion = @GccVersion@
ifeq "$(phase)" "0"
CrossCompilePrefix =
......@@ -527,18 +526,19 @@ GccLT34 = @GccLT34@
GccLT46 = @GccLT46@
GccIsClang = @GccIsClang@
CC = $(WhatGccIsCalled)
CC = @CC@
CC_STAGE0 = @CC_STAGE0@
CC_STAGE1 = $(CC)
CC_STAGE2 = $(CC)
CC_STAGE3 = $(CC)
AS = $(WhatGccIsCalled)
AS = @CC@
AS_STAGE0 = @CC_STAGE0@
AS_STAGE1 = $(AS)
AS_STAGE2 = $(AS)
AS_STAGE3 = $(AS)
# why no LD=@LD@ ?
LD_STAGE0 = @LD_STAGE0@
LD_STAGE1 = $(LD)
LD_STAGE2 = $(LD)
......
......@@ -538,7 +538,7 @@ ifeq "$(TargetOS_CPP)" "darwin"
# Darwin has a flag to tell dtrace which cpp to use.
# Unfortunately, this isn't supported on Solaris (See Solaris Dynamic Tracing
# Guide, Chapter 16, for the configuration variables available on Solaris)
DTRACE_FLAGS = -x cpppath=$(WhatGccIsCalled)
DTRACE_FLAGS = -x cpppath=$(CC)
endif
DTRACEPROBES_SRC = rts/RtsProbes.d
......
......@@ -46,7 +46,7 @@ $$($1_$2_INPLACE_WRAPPER): $$($1_$2_INPLACE)
echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"' >> $$@
echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"' >> $$@
echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"' >> $$@
echo 'pgmgcc="$$(WhatGccIsCalled)"' >> $$@
echo 'pgmgcc="$$(CC)"' >> $$@
$$($1_$2_SHELL_WRAPPER_EXTRA)
$$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment