Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. MAKEFLAGS += -R -r
  2. prefix := $(CURDIR)/gnu
  3. tooldir = gnusrc
  4. binutils = $(tooldir)/binutils
  5. all_config = --prefix=$(prefix)
  6. z80_config = $(all_config) --target=z80-none-elf
  7. include ../riscv-opts.mk
  8. export riscv_target_flags
  9. multilibs= rv32imc-ilp32--zicsr;rv32im-ilp32--zicsr;rv32i-ilp32--zicsr;rv32imc_zbb-ilp32--zicsr
  10. riscv_tuple=riscv32-unknown-elf
  11. riscv_config = $(all_config) \
  12. --target=riscv32-unknown-elf \
  13. --enable-languages=c,c++ \
  14. --with-arch=rv32imc_zicsr --with-abi=ilp32 \
  15. --with-newlib \
  16. --with-sysroot=$(prefix)/$(riscv_tuple) \
  17. --disable-shared --disable-threads \
  18. --disable-libmudflap --disable-libssp \
  19. --disable-libquadmath --disable-libgomp --disable-nls \
  20. --disable-tm-clone-registry \
  21. --enable-multilib --with-multilib-generator=$(multilibs)
  22. export riscv_config
  23. riscv_binutils_configargs := \
  24. --disable-gold --disable-gprof --disable-sim
  25. export riscv_binutils_configargs
  26. # The tools don't seem to build correctly without buildin rules (sigh)
  27. # There isn't even an option to cancel them, so use this hideousness
  28. # to strip out the r and R option from MAKEFLAGS.
  29. _tail = $(wordlist 2,$(words $(1)),$(1))
  30. _strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2))
  31. strip_flags = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2)))
  32. gnu_makeflags = $(call strip_flags,r R,$(MAKEFLAGS))
  33. RMAKE = +$(MAKE) MAKEFLAGS='$(gnu_makeflags)'
  34. riscv_newlib_configargs := \
  35. --disable-newlib-fseek-optimization \
  36. --disable-newlib-fvwrite-in-streamio \
  37. --disable-newlib-mb \
  38. --disable-newlib-multithread \
  39. --disable-newlib-reent-check-verify \
  40. --disable-newlib-register-fini \
  41. --disable-newlib-supplied-syscalls \
  42. --disable-newlib-unbuf-stream-opt \
  43. --disable-newlib-wide-orient \
  44. --enable-lite-exit \
  45. --enable-newlib-global-atexit \
  46. --enable-newlib-nano-formatted-io \
  47. --enable-newlib-io-c99-formats \
  48. --enable-newlib-nano-malloc \
  49. --enable-newlib-reent-small
  50. export riscv_newlib_configargs
  51. all: gnu
  52. clean:
  53. rm -rf *.build *~ *.bak \#* .\#* *.deps *.stamp
  54. spotless: clean
  55. rm -rf gnu
  56. .PHONY: gnu.src
  57. gnu.src:
  58. if [ -f ../.gitmodules ] && \
  59. git submodule status --recursive | grep -q '^[+-]'; then \
  60. git submodule update --init --recursive ; \
  61. rm -rf gnu gnu.*.stamp ; \
  62. fi
  63. .PHONY: gnu
  64. gnu:
  65. $(MAKE) gnu.src
  66. $(MAKE) gnu.bin
  67. .PHONY: gnu.bin
  68. gnu.bin: gnu.riscv.build gnu.z80.build.stamp
  69. # Note: the riscv-gnu-toolchain repo has bugs when building in
  70. # parallel, so spoon feed it a sequence to avoid dependency problems.
  71. %.build.stamp:
  72. $(MAKE) $*.build
  73. .PHONY: gnu.riscv.build
  74. gnu.riscv.build:
  75. MAKE='$(MAKE)' MAKEFLAGS='$(gnu_makeflags)' ./riscvbuild.sh
  76. .PHONY: gnu.z80.build
  77. gnu.z80.build:
  78. mkdir -p $@
  79. cd $@ && ../$(binutils)/configure $(z80_config)
  80. $(RMAKE) -C $@
  81. $(RMAKE) -C $@ install
  82. : >$@.stamp