From 19464804adf3a8ec03de55a29de984e053f6cb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCllner?= Date: Tue, 6 Feb 2024 10:21:22 +0100 Subject: Add support to build a host GCC for building the toolchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A significant amount of users of this project are using it for toolchain development. These users need to ensure that their code is warning free before submitting it upstream. Let's support this use case by adding a configure flag '--enable-host-gcc', which does exactly that: * build a host GCC before building other components * setting PATH such that this new GCC is used to build the cross toolchain * enable -Werror for the GCC build This patch was tested on a Fedora 39 machine (GCC 13), with the following modification in a GCC source file: #if __GNUC__ == 13 #error Host compiler in use! #endif This fails when building without the new flag and does not fail when building with latest upstream/master (GCC 14 prerelease). The '--enable-werror-always' was tested with a warning that showed up recently in upstream GCC. Signed-off-by: Christoph Müllner --- Makefile.in | 40 ++++++++++++++++++++++++++++++---------- README.md | 10 ++++++++++ configure | 17 +++++++++++++++++ configure.ac | 10 ++++++++++ 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Makefile.in b/Makefile.in index c849d77..daab494 100644 --- a/Makefile.in +++ b/Makefile.in @@ -119,8 +119,14 @@ MUSL_CC_FOR_TARGET ?= $(MUSL_TUPLE)-gcc MUSL_CXX_FOR_TARGET ?= $(MUSL_TUPLE)-g++ CONFIGURE_HOST = @configure_host@ +PREPARATION_STAMP:=stamps/check-write-permission all: @default_target@ +ifeq (@enable_host_gcc@,--enable-host-gcc) +PREPARATION_STAMP+= stamps/install-host-gcc +PATH := $(builddir)/install-host-gcc/bin:$(PATH) +GCC_CHECKING_FLAGS := $(GCC_CHECKING_FLAGS) --enable-werror-always +endif newlib: stamps/build-gcc-newlib-stage2 linux: stamps/build-gcc-linux-stage2 ifneq (,$(findstring riscv32,$(MUSL_TUPLE))) @@ -324,11 +330,25 @@ $(srcdir)/%/.git: flock `git rev-parse --git-dir`/config git submodule init $(dir $@) && \ flock `git rev-parse --git-dir`/config git submodule update $(dir $@) +stamps/install-host-gcc: $(GCC_SRCDIR) $(GCC_SRC_GIT) + if test -f $ $@ -stamps/build-qemu: $(QEMU_SRCDIR) $(QEMU_SRC_GIT) +stamps/build-qemu: $(QEMU_SRCDIR) $(QEMU_SRC_GIT) $(PREPARATION_STAMP) rm -rf $@ $(notdir $@) mkdir $(notdir $@) cd $(notdir $@) && $