2
0

Makefile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. riscv_target_flags = -fvisibility=hidden -fno-pic -mshorten-memrefs \
  11. -frename-registers -mdiv -mno-strict-align \
  12. -ffunction-sections -fdata-sections
  13. riscv_config = $(all_config) \
  14. --with-arch=rv32imc --with-abi=ilp32 \
  15. --with-target-cflags='$(riscv_target_flags)' \
  16. --with-target-cxxflags='$(riscv_target_flags)' \
  17. --enable-multilib --with-multilib-generator='rv32imc-ilp32--'
  18. # The tools don't seem to build correctly without buildin rules (sigh)
  19. # There isn't even an option to cancel them, so use this hideousness
  20. # to strip out the r and R option from MAKEFLAGS.
  21. _tail = $(wordlist 2,$(words $(1)),$(1))
  22. _strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2))
  23. strip_flags = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2)))
  24. RMAKE = $(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
  25. riscv_configargs := target_configargs='--enable-lite-exit --disable-newlib-register-fini'
  26. all: gnu.riscv.build gnu.z80.build
  27. clean:
  28. rm -rf *.build *~ *.bak \#* .\#*
  29. spotless: clean
  30. rm -rf gnu
  31. .PHONY: src
  32. src:
  33. [ ! -f ../../.gitmodules ] || \
  34. git submodule update --init --recursive
  35. # Note: the riscv-gnu-toolchain repo has bugs when building in
  36. # parallel, so spoon feed it a sequence to avoid dependency problems.
  37. .PHONY: gnu.riscv.build
  38. gnu.riscv.build: src
  39. mkdir -p $@
  40. cd $@ && $(riscv_configargs) ../$(tooldir)/configure $(riscv_config)
  41. $(RMAKE) -C $@ $(riscv_configargs) build-binutils
  42. $(RMAKE) -C $@ $(riscv_configargs) newlib
  43. .PHONY: gnu.z80.build
  44. gnu.z80.build: src
  45. mkdir -p $@
  46. cd $@ && ../$(binutils)/configure $(z80_config)
  47. $(RMAKE) -C $@
  48. $(RMAKE) -C $@ install