Makefile 3.4 KB

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