Makefile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. MAKEFLAGS += -R -r
  2. prefix := $(CURDIR)
  3. tooldir = riscv-gnu-toolchain
  4. binutils = $(tooldir)/riscv-binutils
  5. # --disable-gdb because the gdb with riscv-gnu-toolchain seems really broken
  6. all_config = --prefix=$(prefix)/gnu --with-system-zlib
  7. z80_config = $(all_config) \
  8. --target=z80-none-elf
  9. include ../riscv-opts.mk
  10. riscv_config = $(all_config) \
  11. --with-arch=rv32imc --with-abi=ilp32 \
  12. --with-target-cflags='$(riscv_target_flags)' \
  13. --with-target-cxxflags='$(riscv_target_flags)' \
  14. --enable-multilib --with-multilib-generator='rv32imc-ilp32--'
  15. # The tools don't seem to build correctly without buildin rules (sigh)
  16. # There isn't even an option to cancel them, so use this hideousness
  17. # to strip out the r and R option from MAKEFLAGS.
  18. _tail = $(wordlist 2,$(words $(1)),$(1))
  19. _strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2))
  20. strip_flags = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2)))
  21. RMAKE = +$(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
  22. riscv_target_configargs := --enable-lite-exit \
  23. --disable-newlib-register-fini --disable-newlib-mb \
  24. --disable-newlib-reent-check-verify --disable-newlib-wide-orient \
  25. --disable-newlib-multithread --disable-newlib-supplied-syscalls \
  26. --enable-newlib-nano-malloc --enable-newlib-io-c99-formats \
  27. --disable-newlib-fvwrite-in-streamio --disable-shared
  28. riscv_configargs := target_configargs='$(riscv_target_configargs)'
  29. all: gnu
  30. clean:
  31. rm -rf *.build *~ *.bak \#* .\#* *.deps *.stamp
  32. spotless: clean
  33. rm -rf gnu
  34. .PHONY: gnu.src
  35. gnu.src:
  36. if [ -f ../.gitmodules ] && \
  37. git submodule status --recursive | grep -q '^[+-]'; then \
  38. git submodule update --init --recursive ; \
  39. rm -rf gnu gnu.*.stamp ; \
  40. fi
  41. .PHONY: gnu
  42. gnu:
  43. $(MAKE) gnu.src
  44. $(MAKE) gnu.bin
  45. .PHONY: gnu.bin
  46. gnu.bin: gnu.riscv.build.stamp gnu.z80.build.stamp
  47. # Note: the riscv-gnu-toolchain repo has bugs when building in
  48. # parallel, so spoon feed it a sequence to avoid dependency problems.
  49. %.build.stamp:
  50. $(MAKE) $*.build
  51. .PHONY: gnu.riscv.build
  52. gnu.riscv.build:
  53. mkdir -p $@
  54. cd $@ && $(riscv_configargs) ../$(tooldir)/configure $(riscv_config)
  55. $(RMAKE) -C $@ $(riscv_configargs) build-binutils
  56. $(RMAKE) -C $@ $(riscv_configargs) newlib
  57. : >$@.stamp
  58. .PHONY: gnu.z80.build
  59. gnu.z80.build:
  60. mkdir -p $@
  61. cd $@ && ../$(binutils)/configure $(z80_config)
  62. $(RMAKE) -C $@
  63. $(RMAKE) -C $@ install
  64. : >$@.stamp