Makefile 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. define Stage1/Configure
  37. $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
  38. $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
  39. mkdir -p $(BUILD_DIR1)
  40. (cd $(BUILD_DIR1); rm -f config.cache; \
  41. SHELL="$(BASH)" \
  42. $(PKG_BUILD_DIR)/configure \
  43. --prefix=$(TOOLCHAIN_DIR) \
  44. --build=$(GNU_HOST_NAME) \
  45. --host=$(GNU_HOST_NAME) \
  46. --target=$(REAL_GNU_TARGET_NAME) \
  47. --enable-languages=c \
  48. --disable-shared \
  49. --with-sysroot=$(BUILD_DIR_HOST)/uClibc_dev/ \
  50. --disable-__cxa_atexit \
  51. --enable-target-optspace \
  52. --with-gnu-ld \
  53. --disable-nls \
  54. --disable-libmudflap \
  55. --disable-multilib \
  56. $(SOFT_FLOAT_CONFIG_OPTION) \
  57. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  58. );
  59. endef
  60. define Stage1/Compile
  61. export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) all-gcc
  62. endef
  63. define Stage1/Install
  64. export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) install-gcc
  65. endef
  66. define Stage2/Configure
  67. mkdir -p $(BUILD_DIR2)
  68. # Important! Required for limits.h to be fixed.
  69. rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
  70. ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
  71. rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
  72. ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
  73. (cd $(BUILD_DIR2); rm -f config.cache; \
  74. SHELL="$(BASH)" \
  75. $(PKG_BUILD_DIR)/configure \
  76. --prefix=$(TOOLCHAIN_DIR) \
  77. --build=$(GNU_HOST_NAME) \
  78. --host=$(GNU_HOST_NAME) \
  79. --target=$(REAL_GNU_TARGET_NAME) \
  80. --enable-languages=$(TARGET_LANGUAGES) \
  81. --enable-shared \
  82. --disable-__cxa_atexit \
  83. --enable-target-optspace \
  84. --with-gnu-ld \
  85. --disable-nls \
  86. --disable-libmudflap \
  87. --disable-multilib \
  88. $(SOFT_FLOAT_CONFIG_OPTION) \
  89. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  90. );
  91. endef
  92. define Stage2/Compile
  93. export SHELL="\$(BASH)"; \$(MAKE) -C \$(BUILD_DIR2) all
  94. endef
  95. define Stage2/Install
  96. $(MAKE) -C $(BUILD_DIR2) \
  97. SHELL="$(BASH)" \
  98. install
  99. # Set up the symlinks to enable lying about target name.
  100. set -e; \
  101. (cd $(TOOLCHAIN_DIR); \
  102. ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
  103. cd bin; \
  104. for app in $(REAL_GNU_TARGET_NAME)-* ; do \
  105. ln -sf $$$${app} \
  106. $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
  107. done; \
  108. );
  109. endef
  110. define Build/Prepare
  111. $(call Build/Prepare/Default)
  112. $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(PKG_BUILD_DIR)/gcc/version.c
  113. $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:https://dev.openwrt.org/>\2,' $(PKG_BUILD_DIR)/gcc/version.c
  114. (cd $(PKG_BUILD_DIR)/libstdc++-v3; autoconf;);
  115. $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(PKG_BUILD_DIR)/libstdc++-v3/configure
  116. endef
  117. define Build/Configure
  118. $(call Stage1/Configure)
  119. endef
  120. define Build/Compile
  121. $(call Stage1/Compile)
  122. $(if $(wildcard $(TOOLCHAIN_DIR)/bin/$(GNU_TARGET_NAME)-gcc),,$(call Stage1/Install))
  123. endef
  124. define Build/Install
  125. $(call Stage2/Configure)
  126. $(call Stage2/Compile)
  127. $(call Stage2/Install)
  128. endef
  129. define Build/Clean
  130. rm -rf \
  131. $(PKG_BUILD_DIR) \
  132. $(BUILD_DIR1) \
  133. $(BUILD_DIR2) \
  134. $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
  135. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
  136. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
  137. endef
  138. $(eval $(call HostBuild))