Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # Makefile for to build a gcc/uClibc toolchain
  2. #
  3. # Copyright (C) 2002-2003 Erik Andersen <[email protected]>
  4. # Copyright (C) 2004 Manuel Novoa III <[email protected]>
  5. # Copyright (C) 2005-2006 Felix Fietkau <[email protected]>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. include $(TOPDIR)/rules.mk
  21. PKG_NAME:=gcc
  22. PKG_VERSION:=$(strip $(subst ",, $(CONFIG_GCC_VERSION)))#"))
  23. PATCH_DIR=./patches/$(PKG_VERSION)
  24. PKG_SOURCE_URL:=ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-$(PKG_VERSION) \
  25. http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-$(PKG_VERSION) \
  26. ftp://ftp.gnu.org/gnu/gcc/releases/gcc-$(PKG_VERSION)
  27. PKG_SOURCE:=gcc-$(PKG_VERSION).tar.bz2
  28. STAGING_DIR_HOST:=$(TOOLCHAIN_DIR)
  29. BUILD_DIR_HOST:=$(BUILD_DIR_TOOLCHAIN)
  30. include $(INCLUDE_DIR)/host-build.mk
  31. STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
  32. BUILD_DIR1:=$(BUILD_DIR_HOST)/gcc-$(PKG_VERSION)-initial
  33. BUILD_DIR2:=$(BUILD_DIR_HOST)/gcc-$(PKG_VERSION)-final
  34. SEP:=,
  35. TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
  36. EXTRA_TARGET=$(if $(CONFIG_EXTRA_TARGET_ARCH),--enable-biarch --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-uclibc)
  37. define Stage1/Configure
  38. $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
  39. $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
  40. mkdir -p $(BUILD_DIR1)
  41. (cd $(BUILD_DIR1); rm -f config.cache; \
  42. SHELL="$(BASH)" \
  43. $(PKG_BUILD_DIR)/configure \
  44. --prefix=$(TOOLCHAIN_DIR) \
  45. --build=$(GNU_HOST_NAME) \
  46. --host=$(GNU_HOST_NAME) \
  47. --target=$(REAL_GNU_TARGET_NAME) \
  48. --enable-languages=c \
  49. --disable-shared \
  50. --with-sysroot=$(BUILD_DIR_HOST)/uClibc_dev/ \
  51. --disable-__cxa_atexit \
  52. --enable-target-optspace \
  53. --with-gnu-ld \
  54. --disable-nls \
  55. --disable-libmudflap \
  56. --disable-multilib \
  57. $(EXTRA_TARGET) \
  58. $(SOFT_FLOAT_CONFIG_OPTION) \
  59. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  60. );
  61. endef
  62. define Stage1/Compile
  63. export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) all-gcc
  64. endef
  65. define Stage1/Install
  66. export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) install-gcc
  67. endef
  68. define Stage2/Configure
  69. mkdir -p $(BUILD_DIR2) $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)
  70. # Important! Required for limits.h to be fixed.
  71. rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
  72. ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
  73. rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
  74. ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
  75. (cd $(BUILD_DIR2); rm -f config.cache; \
  76. SHELL="$(BASH)" \
  77. $(PKG_BUILD_DIR)/configure \
  78. --prefix=$(TOOLCHAIN_DIR) \
  79. --build=$(GNU_HOST_NAME) \
  80. --host=$(GNU_HOST_NAME) \
  81. --target=$(REAL_GNU_TARGET_NAME) \
  82. --enable-languages=$(TARGET_LANGUAGES) \
  83. --enable-shared \
  84. --disable-__cxa_atexit \
  85. --enable-target-optspace \
  86. --with-gnu-ld \
  87. --disable-nls \
  88. --disable-libmudflap \
  89. --disable-multilib \
  90. $(EXTRA_TARGET) \
  91. $(SOFT_FLOAT_CONFIG_OPTION) \
  92. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  93. );
  94. endef
  95. define Stage2/Compile
  96. export SHELL="\$(BASH)"; \$(MAKE) -C \$(BUILD_DIR2) all
  97. endef
  98. define SetupExtraArch
  99. for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
  100. [ -e $$$$app ] || continue; \
  101. old_base=$$$$(basename $$$$app); \
  102. new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
  103. sed -e "s/@CC_BASE@/$$$$old_base/" \
  104. -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
  105. ./files/alternate-arch-cc.in > \
  106. $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
  107. chmod a+x $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
  108. done
  109. endef
  110. define Stage2/Install
  111. $(MAKE) -C $(BUILD_DIR2) \
  112. SHELL="$(BASH)" \
  113. install
  114. # Set up the symlinks to enable lying about target name.
  115. set -e; \
  116. (cd $(TOOLCHAIN_DIR); \
  117. ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
  118. cd bin; \
  119. for app in $(REAL_GNU_TARGET_NAME)-* ; do \
  120. ln -sf $$$${app} \
  121. $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
  122. done; \
  123. );
  124. $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
  125. endef
  126. define Build/Prepare
  127. $(call Build/Prepare/Default)
  128. $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(PKG_BUILD_DIR)/gcc/version.c
  129. $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:https://dev.openwrt.org/>\2,' $(PKG_BUILD_DIR)/gcc/version.c
  130. (cd $(PKG_BUILD_DIR)/libstdc++-v3; autoconf;);
  131. $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(PKG_BUILD_DIR)/libstdc++-v3/configure
  132. endef
  133. define Build/Configure
  134. $(call Stage1/Configure)
  135. endef
  136. define Build/Compile
  137. $(call Stage1/Compile)
  138. $(if $(wildcard $(TOOLCHAIN_DIR)/bin/$(GNU_TARGET_NAME)-gcc),,$(call Stage1/Install))
  139. endef
  140. define Build/Install
  141. $(call Stage2/Configure)
  142. $(call Stage2/Compile)
  143. $(call Stage2/Install)
  144. endef
  145. define Build/Clean
  146. rm -rf \
  147. $(PKG_BUILD_DIR) \
  148. $(BUILD_DIR1) \
  149. $(BUILD_DIR2) \
  150. $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
  151. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
  152. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
  153. endef
  154. $(eval $(call HostBuild))