aboutsummaryrefslogtreecommitdiff
path: root/Makefile.in
diff options
context:
space:
mode:
authorChristoph Müllner <christoph.muellner@vrull.eu>2022-09-28 00:14:41 +0200
committerKito Cheng <kito.cheng@sifive.com>2023-05-17 14:01:44 +0800
commitea26fd6cb82aaa8e7fc95adc704442dc466dac9e (patch)
treea9edf205efb85f89dbb0509a5ccfa9e3212adf65 /Makefile.in
parentee1bb922707b53b479552b4aa8fb009b35ce8d22 (diff)
downloadriscv-gnu-toolchain-ea26fd6cb82aaa8e7fc95adc704442dc466dac9e.zip
riscv-gnu-toolchain-ea26fd6cb82aaa8e7fc95adc704442dc466dac9e.tar.gz
riscv-gnu-toolchain-ea26fd6cb82aaa8e7fc95adc704442dc466dac9e.tar.bz2
Add support to build LLVM/clang with C and C++ support
We currently have a stale "llvm" branch, that does not build. However, there is clear demand in the RISC-V toolchain community for a working LLVM on top of a recent GNU toolchain. In order to build such a toolchain, quite some LLVM and clang know-how is required to avoid path issues at LLVM build time or later when using clang. The main purpose of this commit is to demonstrate a way to combine the RISC-V GNU toolchain repo with LLVM, with the intent to save others hours of frustration, debugging time or support time. Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
Diffstat (limited to 'Makefile.in')
-rw-r--r--Makefile.in54
1 files changed, 53 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in
index 71369ab..d4cc9a4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -12,6 +12,7 @@ GDB_SRCDIR := @with_gdb_src@
QEMU_SRCDIR := @with_qemu_src@
SPIKE_SRCDIR := @with_spike_src@
PK_SRCDIR := @with_pk_src@
+LLVM_SRCDIR := @with_llvm_src@
SIM ?= @WITH_SIM@
@@ -115,8 +116,16 @@ newlib: stamps/build-gdb-newlib
linux: stamps/build-gdb-linux
endif
linux-native: stamps/build-gcc-linux-native
+ifeq (@enable_llvm@,--enable-llvm)
+all: stamps/build-llvm-@default_target@
+newlib: stamps/build-llvm-newlib
+linux: stamps/build-llvm-linux
+ifeq (@multilib_flags@,--enable-multilib)
+$(error "Setting multilib flags for LLVM builds is not supported.")
+endif
+endif
-.PHONY: build-binutils build-gdb build-gcc1 build-libc build-gcc2 build-qemu
+.PHONY: build-binutils build-gdb build-gcc1 build-libc build-gcc2 build-qemu build-llvm
build-binutils: stamps/build-binutils-@default_target@
build-gdb: stamps/build-gdb-@default_target@
build-gcc%: stamps/build-gcc-@default_target@-stage%
@@ -127,6 +136,7 @@ build-libc: stamps/build-newlib stamps/build-newlib-nano \
stamps/merge-newlib-nano
endif
build-qemu: stamps/build-qemu
+build-llvm: stamps/build-llvm-@default_target@
REGRESSION_TEST_LIST = gcc
@@ -272,6 +282,12 @@ else
SPIKE_SRC_GIT :=
endif
+ifeq ($(findstring $(srcdir),$(LLVM_SRCDIR)),$(srcdir))
+LLVM_SRC_GIT := $(LLVM_SRCDIR)/.git
+else
+LLVM_SRC_GIT :=
+endif
+
ifneq ("$(wildcard $(GCC_SRCDIR)/.git)","")
GCCPKGVER := g$(shell git -C $(GCC_SRCDIR) describe --always --dirty --exclude '*')
else
@@ -865,6 +881,42 @@ stamps/build-qemu: $(QEMU_SRCDIR) $(QEMU_SRC_GIT)
mkdir -p $(dir $@)
date > $@
+stamps/build-llvm-linux: $(LLVM_SRCDIR) $(LLVM_SRC_GIT) \
+ stamps/build-gcc-linux-stage2
+ # We have the following situation:
+ # - sysroot directory: $(INSTALL_DIR)/sysroot
+ # - GCC install directory: $(INSTALL_DIR)
+ # However, LLVM does not allow to set a GCC install prefix
+ # (-DGCC_INSTALL_PREFIX) if a sysroot (-DDEFAULT_SYSROOT) is set
+ # (the GCC install prefix will be ignored silently).
+ # Without a proper sysroot path feature.h won't be found by clang.
+ # Without a proper GCC install directory libgcc won't be found.
+ # As a workaround we have to merge both paths:
+ mkdir -p $(SYSROOT)/lib/
+ ln -s $(INSTALL_DIR)/lib/gcc $(SYSROOT)/lib/gcc
+ rm -rf $@ $(notdir $@)
+ mkdir $(notdir $@)
+ cd $(notdir $@) && \
+ cmake $(LLVM_SRCDIR)/llvm \
+ -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DLLVM_TARGETS_TO_BUILD="RISCV" \
+ -DLLVM_ENABLE_PROJECTS="clang;lld" \
+ -DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
+ -DLLVM_DEFAULT_TARGET_TRIPLE="$(LINUX_TUPLE)" \
+ -DDEFAULT_SYSROOT="$(INSTALL_DIR)/sysroot" \
+ -DLLVM_RUNTIME_TARGETS=$(call make_tuple,$(XLEN),linux-gnu) \
+ -DLLVM_INSTALL_TOOLCHAIN_ONLY=On \
+ -DLLVM_PARALLEL_LINK_JOBS=4
+ $(MAKE) -C $(notdir $@)
+ $(MAKE) -C $(notdir $@) install
+ cd $(INSTALL_DIR)/bin && ln -s clang $(LINUX_TUPLE)-clang
+ mkdir -p $(dir $@) && touch $@
+
+stamps/build-llvm-newlib:
+ echo "Building LLVM is only supported in combination with a Linux toolchain."
+ exit 1
+
stamps/build-dejagnu: $(srcdir)/dejagnu $(srcdir)/dejagnu/.git
rm -rf $@ $(notdir $@)
mkdir $(notdir $@)