Makefile 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. MAKEFLAGS += -R -r
  2. CROSS = riscv32-unknown-elf-
  3. prefix := $(CURDIR)
  4. target_flags = -fvisibility=hidden -fno-pic -mshorten-memrefs \
  5. -frename-registers -mdiv -mno-strict-align \
  6. -ffunction-sections -fdata-sections
  7. tooldir = riscv-gnu-toolchain
  8. # --disable-gdb because the gdb with riscv-gnu-toolchain seems really broken
  9. config = --prefix=$(prefix)/gnu \
  10. --with-arch=rv32imc --with-abi=ilp32 \
  11. --with-target-cflags='$(target_flags)' \
  12. --with-target-cxxflags='$(target_flags)' \
  13. --with-system-zlib \
  14. --disable-gdb \
  15. --enable-multilib --with-multilib-generator='rv32imc-ilp32--'
  16. # The tools don't seem to build correctly without buildin rules (sigh)
  17. # There isn't even an option to cancel them, so use this hideousness
  18. # to strip out the r and R option from MAKEFLAGS.
  19. _tail = $(wordlist 2,$(words $(1)),$(1))
  20. _strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2))
  21. strip_flags = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2)))
  22. RMAKE = $(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
  23. export target_configargs := --enable-lite-exit --disable-newlib-register-fini
  24. export PATH := $(prefix)/gnu/bin:$(PATH)
  25. all: gnu
  26. clean:
  27. rm -rf gnu *.build
  28. # Note: the riscv-gnu-toolchain repo has bugs when building in
  29. # parallel, so spoon feed it a sequence to avoid dependency problems.
  30. .PHONY: gnu
  31. gnu:
  32. [ ! -f ../../.gitmodules ] || \
  33. git submodule update --init --recursive
  34. mkdir -p gnu.build
  35. cd gnu.build && ../$(tooldir)/configure $(config)
  36. $(RMAKE) -C gnu.build build-binutils
  37. $(RMAKE) -C gnu.build newlib