Makefile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.riscv.build gnu.z80.build
  25. clean:
  26. rm -rf *.build *~ *.bak \#* .\#*
  27. spotless: clean
  28. rm -rf gnu
  29. .PHONY: src
  30. src:
  31. [ ! -f ../../.gitmodules ] || \
  32. git submodule update --init --recursive
  33. # Note: the riscv-gnu-toolchain repo has bugs when building in
  34. # parallel, so spoon feed it a sequence to avoid dependency problems.
  35. .PHONY: gnu.riscv.build
  36. gnu.riscv.build: src
  37. mkdir -p $@
  38. cd $@ && $(riscv_configargs) ../$(tooldir)/configure $(riscv_config)
  39. $(RMAKE) -C $@ $(riscv_configargs) build-binutils
  40. $(RMAKE) -C $@ $(riscv_configargs) newlib
  41. .PHONY: gnu.z80.build
  42. gnu.z80.build: src
  43. mkdir -p $@
  44. cd $@ && ../$(binutils)/configure $(z80_config)
  45. $(RMAKE) -C $@
  46. $(RMAKE) -C $@ install