|
@@ -0,0 +1,47 @@
|
|
|
+MAKEFLAGS += -R -r
|
|
|
+
|
|
|
+CROSS = riscv32-unknown-elf-
|
|
|
+prefix := $(CURDIR)
|
|
|
+target_flags = -fvisibility=hidden -fno-pic -mshorten-memrefs \
|
|
|
+ -frename-registers -mdiv -mno-strict-align \
|
|
|
+ -ffunction-sections -fdata-sections
|
|
|
+
|
|
|
+tooldir = riscv-gnu-toolchain
|
|
|
+
|
|
|
+# --disable-gdb because the gdb with riscv-gnu-toolchain seems really broken
|
|
|
+config = --prefix=$(prefix)/gnu \
|
|
|
+ --with-arch=rv32imc --with-abi=ilp32 \
|
|
|
+ --with-target-cflags='$(target_flags)' \
|
|
|
+ --with-target-cxxflags='$(target_flags)' \
|
|
|
+ --with-system-zlib \
|
|
|
+ --disable-gdb \
|
|
|
+ --enable-multilib --with-multilib-generator='rv32imc-ilp32--'
|
|
|
+
|
|
|
+# The tools don't seem to build correctly without buildin rules (sigh)
|
|
|
+# There isn't even an option to cancel them, so use this hideousness
|
|
|
+# to strip out the r and R option from MAKEFLAGS.
|
|
|
+_tail = $(wordlist 2,$(words $(1)),$(1))
|
|
|
+_strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2))
|
|
|
+strip_flags = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2)))
|
|
|
+
|
|
|
+RMAKE = $(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
|
|
|
+
|
|
|
+export target_configargs := --enable-lite-exit --disable-newlib-register-fini
|
|
|
+
|
|
|
+export PATH := $(prefix)/gnu/bin:$(PATH)
|
|
|
+
|
|
|
+all: gnu
|
|
|
+
|
|
|
+clean:
|
|
|
+ rm -rf gnu *.build
|
|
|
+
|
|
|
+# Note: the riscv-gnu-toolchain repo has bugs when building in
|
|
|
+# parallel, so spoon feed it a sequence to avoid dependency problems.
|
|
|
+.PHONY: gnu
|
|
|
+gnu:
|
|
|
+ [ ! -f ../../.gitmodules ] || \
|
|
|
+ git submodule update --init --recursive
|
|
|
+ mkdir -p gnu.build
|
|
|
+ cd gnu.build && ../$(tooldir)/configure $(config)
|
|
|
+ $(RMAKE) -C gnu.build build-binutils
|
|
|
+ $(RMAKE) -C gnu.build newlib
|