Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. MAKEFLAGS = -R -r
  2. prefix := $(CURDIR)/gnu
  3. bindir := $(prefix)/bin
  4. tooldir = gnusrc
  5. binutils = $(tooldir)/binutils
  6. all_config = --prefix=$(prefix)
  7. z80_config = $(all_config) --target=z80-none-elf
  8. all: gnu
  9. include ../riscv-opts.mk
  10. export riscv_target_flags
  11. multilibs= rv32imc-ilp32--zicsr;rv32im-ilp32--zicsr;rv32i-ilp32--zicsr;rv32imc_zbb-ilp32--zicsr
  12. riscv_tuple=riscv32-unknown-elf
  13. riscv_config = $(all_config) \
  14. --target=riscv32-unknown-elf \
  15. --enable-languages=c,c++ \
  16. --with-arch=rv32imc_zicsr --with-abi=ilp32 \
  17. --with-newlib \
  18. --with-sysroot=$(prefix)/$(riscv_tuple) \
  19. --disable-shared --disable-threads \
  20. --disable-libmudflap --disable-libssp \
  21. --disable-libquadmath --disable-libgomp --disable-nls \
  22. --disable-tm-clone-registry \
  23. --enable-multilib --with-multilib-generator=$(multilibs)
  24. export riscv_config
  25. riscv_binutils_configargs := \
  26. --disable-gold --disable-gprof --disable-sim
  27. export riscv_binutils_configargs
  28. pathify = PATH='$(bindir):$(PATH)'
  29. # -R -r fails, and one can't disable it, so strip all of MAKEFLAGS
  30. # except any job-related options. Sigh.
  31. gnu_makeflags = MAKEFLAGS=' $(filter -j% --job%,$(MAKEFLAGS))'
  32. rsetup = $(pathify) $(gnu_makeflags)
  33. RMAKE = $(rsetup) $(MAKE)
  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. clean:
  52. rm -rf *.build *~ *.bak \#* .\#* *.deps *.stamp
  53. spotless: clean
  54. rm -rf gnu
  55. .PHONY: gnu.src
  56. gnu.src:
  57. if [ -f ../.gitmodules ] && \
  58. git submodule status --recursive | grep -q '^[+-]'; then \
  59. git submodule update --init --recursive ; \
  60. rm -rf gnu gnu.*.stamp ; \
  61. fi
  62. .PHONY: gnu
  63. gnu:
  64. $(MAKE) gnu.src
  65. $(MAKE) autotools
  66. $(MAKE) gnu.bin
  67. .PHONY: gnu.bin
  68. gnu.bin: gnu.riscv.build gnu.z80.build.stamp
  69. # At least binutils is really picky about which version of autoconf
  70. # and aclocal (automake) it uses, so build it explicitly
  71. autoconf-ver := 2.69
  72. automake-ver := 1.15.1
  73. autoconf = autoconf-$(autoconf-ver)
  74. automake = automake-$(automake-ver)
  75. # Don't require these tools for autotools
  76. autotools-disable = EMACS=no GIT=no MAKEINFO=:
  77. .PHONY: autotools
  78. autotools: gnu.autotools.build.stamp
  79. .PHONY: gnu.autotools.build
  80. gnu.autotools.build:
  81. mkdir -p $@
  82. cd $@ && tar xvvf ../gnusrc/$(autoconf).tar.xz
  83. cd $@/$(autoconf) && \
  84. $(rsetup) $(autotools-disable) ./configure $(all_config)
  85. $(RMAKE) -C $@/$(autoconf)
  86. $(RMAKE) -C $@/$(autoconf) install
  87. cd $@ && tar xvvf ../gnusrc/$(automake).tar.xz
  88. cd $@/$(automake) && \
  89. $(rsetup) $(autotools-disable) ./configure $(all_config)
  90. $(RMAKE) -C $@/$(automake)
  91. $(RMAKE) -C $@/$(automake) install
  92. : >$@.stamp
  93. # Note: the riscv-gnu-toolchain repo has bugs when building in
  94. # parallel, so spoon feed it a sequence to avoid dependency problems.
  95. %.build.stamp:
  96. $(MAKE) $*.build
  97. .PHONY: gnu.riscv.build
  98. gnu.riscv.build: autotools
  99. $(rsetup) MAKE='$(MAKE)' ./riscvbuild.sh
  100. .PHONY: gnu.z80.build
  101. gnu.z80.build: autotools
  102. mkdir -p $@
  103. cd $@ && $(rsetup) ../$(binutils)/configure $(z80_config)
  104. $(RMAKE) -C $@
  105. $(RMAKE) -C $@ install
  106. : >$@.stamp