Makefile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_configargs := target_configargs='--enable-lite-exit --disable-newlib-register-fini'
  23. all: gnu
  24. clean:
  25. rm -rf *.build *~ *.bak \#* .\#* *.deps *.stamp
  26. spotless: clean
  27. rm -rf gnu
  28. .PHONY: gnu.src
  29. gnu.src:
  30. if [ -f ../../.gitmodules ] && \
  31. git submodule status --recursive | grep -q '^[+-]'; then \
  32. git submodule update --init --recursive ; \
  33. rm -rf gnu gnu.*.stamp ; \
  34. fi
  35. .PHONY: gnu
  36. gnu:
  37. $(MAKE) gnu.src
  38. $(MAKE) gnu.bin
  39. .PHONY: gnu.bin
  40. gnu.bin: gnu.riscv.build.stamp gnu.z80.build.stamp
  41. # Note: the riscv-gnu-toolchain repo has bugs when building in
  42. # parallel, so spoon feed it a sequence to avoid dependency problems.
  43. %.build.stamp:
  44. $(MAKE) $*.build
  45. .PHONY: gnu.riscv.build
  46. gnu.riscv.build:
  47. mkdir -p $@
  48. cd $@ && $(riscv_configargs) ../$(tooldir)/configure $(riscv_config)
  49. $(RMAKE) -C $@ $(riscv_configargs) build-binutils
  50. $(RMAKE) -C $@ $(riscv_configargs) newlib
  51. : >$@.stamp
  52. .PHONY: gnu.z80.build
  53. gnu.z80.build:
  54. mkdir -p $@
  55. cd $@ && ../$(binutils)/configure $(z80_config)
  56. $(RMAKE) -C $@
  57. $(RMAKE) -C $@ install
  58. : >$@.stamp