2
0

Makefile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. MAKEFLAGS += -R -r
  2. prefix := $(CURDIR)
  3. export PATH := $(prefix)/gnu/bin:$(PATH)
  4. tooldir = riscv-gnu-toolchain
  5. binutils = $(tooldir)/riscv-binutils
  6. # --disable-gdb because the gdb with riscv-gnu-toolchain seems really broken
  7. all_config = --prefix=$(prefix)/gnu --with-system-zlib
  8. z80_config = $(all_config) \
  9. --target=z80-none-elf
  10. include ../riscv-opts.mk
  11. riscv_config = $(all_config) \
  12. --with-arch=rv32imc --with-abi=ilp32 \
  13. --with-target-cflags='$(riscv_target_flags)' \
  14. --with-target-cxxflags='$(riscv_target_flags)' \
  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. riscv_configargs := target_configargs='--enable-lite-exit --disable-newlib-register-fini'
  24. all: gnu
  25. clean:
  26. rm -rf *.build *~ *.bak \#* .\#* *.deps *.stamp
  27. spotless: clean
  28. rm -rf gnu
  29. .PHONY: gnu.src
  30. gnu.src:
  31. if [ -f ../../.gitmodules ] && \
  32. git submodule status --recursive | grep -q '^[+-]'; then \
  33. git submodule update --init --recursive ; \
  34. rm -rf gnu gnu.*.stamp ; \
  35. fi
  36. .PHONY: gnu
  37. gnu:
  38. $(MAKE) gnu.src
  39. $(MAKE) gnu.bin
  40. .PHONY: gnu.bin
  41. gnu.bin: gnu.riscv.build.stamp gnu.z80.build.stamp
  42. # Note: the riscv-gnu-toolchain repo has bugs when building in
  43. # parallel, so spoon feed it a sequence to avoid dependency problems.
  44. %.build.stamp:
  45. $(MAKE) $*.build
  46. .PHONY: gnu.riscv.build
  47. gnu.riscv.build:
  48. mkdir -p $@
  49. cd $@ && $(riscv_configargs) ../$(tooldir)/configure $(riscv_config)
  50. $(RMAKE) -C $@ $(riscv_configargs) build-binutils
  51. $(RMAKE) -C $@ $(riscv_configargs) newlib
  52. : >$@.stamp
  53. .PHONY: gnu.z80.build
  54. gnu.z80.build:
  55. mkdir -p $@
  56. cd $@ && ../$(binutils)/configure $(z80_config)
  57. $(RMAKE) -C $@
  58. $(RMAKE) -C $@ install
  59. : >$@.stamp