Makefile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. GMP_VER=6.2.0
  2. GMP_URL=https://ftp.gnu.org/gnu/gmp/gmp-$(GMP_VER).tar.bz2
  3. GMP_TAR=gmp-$(GMP_VER).tar.bz2
  4. GMP_DIR=gmp-$(GMP_VER)
  5. GMP_SUM=f51c99cb114deb21a60075ffb494c1a210eb9d7cb729ed042ddb7de9534451ea
  6. MPFR_VER=4.1.0
  7. MPFR_URL=https://ftp.gnu.org/gnu/mpfr/mpfr-$(MPFR_VER).tar.bz2
  8. MPFR_TAR=mpfr-$(MPFR_VER).tar.bz2
  9. MPFR_DIR=mpfr-$(MPFR_VER)
  10. MPFR_SUM=feced2d430dd5a97805fa289fed3fc8ff2b094c02d05287fd6133e7f1f0ec926
  11. MPC_VER=1.1.0
  12. MPC_URL=https://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VER).tar.gz
  13. MPC_TAR=mpc-$(MPC_VER).tar.gz
  14. MPC_DIR=mpc-$(MPC_VER)
  15. MPC_SUM=6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e
  16. BINUTILS_VER=2.35
  17. BINUTILS_URL=https://ftp.gnu.org/gnu/binutils/binutils-$(BINUTILS_VER).tar.bz2
  18. BINUTILS_TAR=binutils-$(BINUTILS_VER).tar.bz2
  19. BINUTILS_DIR=binutils-$(BINUTILS_VER)
  20. BINUTILS_PATCHES=local/patches/binutils-2.34_fixup.patch local/patches/binutils.patch
  21. BINUTILS_SUM=7d24660f87093670738e58bcc7b7b06f121c0fcb0ca8fc44368d675a5ef9cff7
  22. GCC_VER=10.2.0
  23. GCC_URL=https://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VER)/gcc-$(GCC_VER).tar.gz
  24. GCC_TAR=gcc-$(GCC_VER).tar.gz
  25. GCC_DIR=gcc-$(GCC_VER)
  26. GCC_PATCHES=local/patches/gcc.patch
  27. GCC_SUM=27e879dccc639cd7b0cc08ed575c1669492579529b53c9ff27b0b96265fa867d
  28. BASEDIR=$(shell pwd)
  29. TOOLCHAIN_DIR=$(BASEDIR)/toolchain
  30. TARGET=xtensa-elf
  31. DL_DIR=$(TOOLCHAIN_DIR)/dl
  32. BUILD_DIR=$(TOOLCHAIN_DIR)/build
  33. all: toolchain
  34. # 1: package name
  35. # 2: configure arguments
  36. # 3: make command
  37. define Common/Compile
  38. mkdir -p $(BUILD_DIR)/$($(1)_DIR)
  39. +cd $(BUILD_DIR)/$($(1)_DIR) && \
  40. $(DL_DIR)/$($(1)_DIR)/configure \
  41. --prefix=$(TOOLCHAIN_DIR)/inst \
  42. $(2) && \
  43. $(3)
  44. endef
  45. define GMP/Compile
  46. $(call Common/Compile,GMP, \
  47. --disable-shared --enable-static, \
  48. $(MAKE) && $(MAKE) check && $(MAKE) -j1 install \
  49. )
  50. endef
  51. define MPFR/Compile
  52. $(call Common/Compile,MPFR, \
  53. --disable-shared --enable-static \
  54. --with-gmp=$(TOOLCHAIN_DIR)/inst, \
  55. $(MAKE) && $(MAKE) check && $(MAKE) -j1 install \
  56. )
  57. endef
  58. define MPC/Compile
  59. $(call Common/Compile,MPC, \
  60. --disable-shared --enable-static \
  61. --with-gmp=$(TOOLCHAIN_DIR)/inst \
  62. --with-mpfr=$(TOOLCHAIN_DIR)/inst, \
  63. $(MAKE) && $(MAKE) check && $(MAKE) -j1 install \
  64. )
  65. endef
  66. define BINUTILS/Compile
  67. $(call Common/Compile,BINUTILS, \
  68. --target=$(TARGET) \
  69. --disable-werror, \
  70. $(MAKE) && $(MAKE) -j1 install \
  71. )
  72. endef
  73. define GCC/Compile
  74. $(call Common/Compile,GCC, \
  75. --target=$(TARGET) \
  76. --enable-languages=c \
  77. --disable-libssp \
  78. --disable-shared \
  79. --disable-libquadmath \
  80. --with-gmp=$(TOOLCHAIN_DIR)/inst \
  81. --with-mpfr=$(TOOLCHAIN_DIR)/inst \
  82. --with-mpc=$(TOOLCHAIN_DIR)/inst \
  83. --with-newlib, \
  84. $(MAKE) && $(MAKE) -j1 install \
  85. )
  86. endef
  87. # 1: package name
  88. # 2: dependencies on other packages
  89. define Build
  90. $(DL_DIR)/$($(1)_TAR):
  91. mkdir -p $(DL_DIR)
  92. wget -N -P $(DL_DIR) $($(1)_URL)
  93. printf "%s %s\n" $($(1)_SUM) $$@ | shasum -a 256 -c
  94. $(DL_DIR)/$($(1)_DIR)/.prepared: $(DL_DIR)/$($(1)_TAR)
  95. tar -C $(DL_DIR) -x$(if $(findstring bz2,$($(1)_TAR)),j,z)f $(DL_DIR)/$($(1)_TAR)
  96. $(if $($(1)_PATCHES), \
  97. cat $($(1)_PATCHES) | \
  98. patch -p1 -d $(DL_DIR)/$($(1)_DIR))
  99. touch $$@
  100. $(1)_DEPENDS = $(foreach pkg,$(2),$(BUILD_DIR)/$($(pkg)_DIR)/.built)
  101. $(BUILD_DIR)/$($(1)_DIR)/.built: $(DL_DIR)/$($(1)_DIR)/.prepared $$($(1)_DEPENDS)
  102. mkdir -p $(BUILD_DIR)/$($(1)_DIR)
  103. $($(1)/Compile)
  104. touch $$@
  105. clean-dl-$(1):
  106. rm -rf $(DL_DIR)/$($(1)_DIR)
  107. toolchain: $(BUILD_DIR)/$($(1)_DIR)/.built
  108. clean-dl: clean-dl-$(1)
  109. download: $(DL_DIR)/$($(1)_DIR)/.prepared
  110. endef
  111. all: toolchain firmware
  112. toolchain-clean:
  113. rm -rf $(TOOLCHAIN_DIR)/build $(TOOLCHAIN_DIR)/inst
  114. clean-dl:
  115. download:
  116. toolchain:
  117. clean:
  118. $(MAKE) -C target_firmware clean
  119. firmware: toolchain
  120. +$(MAKE) -C target_firmware
  121. .PHONY: all toolchain-clean clean clean-dl download toolchain firmware
  122. $(eval $(call Build,GMP))
  123. $(eval $(call Build,MPFR,GMP))
  124. $(eval $(call Build,MPC,GMP MPFR))
  125. $(eval $(call Build,BINUTILS))
  126. $(eval $(call Build,GCC,MPC MPFR))