You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
6.9 KiB

  1. #
  2. # Copyright (C) 2008 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. define Package/gcc/description
  9. Build a native toolchain for compiling on target
  10. device.
  11. endef
  12. define Package/gcc
  13. SECTION:=devel
  14. CATEGORY:=Development
  15. TITLE:=gcc
  16. MAINTAINER:=Noble Pepper <gccmaintain@noblepepper.com>
  17. DEPENDS:= +binutils +libstdcpp @!arc
  18. MENU:=1
  19. endef
  20. PKG_NAME:=gcc
  21. # PKG_VERSION=7.3.0
  22. PKG_VERSION=7.4.0
  23. PKG_RELEASE:=4
  24. PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
  25. PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
  26. PKG_INSTALL:=1
  27. PKG_FIXUP:=libtool
  28. PKG_BUILD_PARALLEL:=1
  29. ifeq ($(PKG_VERSION),7.3.0)
  30. PKG_HASH:=832ca6ae04636adbb430e865a1451adf6979ab44ca1c8374f61fba65645ce15c
  31. endif
  32. ifeq ($(PKG_VERSION),7.4.0)
  33. PKG_HASH:=eddde28d04f334aec1604456e536416549e9b1aa137fc69204e65eb0c009fe51
  34. endif
  35. define Package/gcc/config
  36. source "$(SOURCE)/Config.in"
  37. endef
  38. ifeq ($(CONFIG_INCLUDE_STATIC_LIBC),y)
  39. COPY_STATIC_LIBC=cp -a $(TOOLCHAIN_DIR)/lib/libc.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  40. endif
  41. ifeq ($(CONFIG_INCLUDE_STATIC_LIBPTHREAD),y)
  42. COPY_STATIC_LIBPTHREAD=cp -a $(TOOLCHAIN_DIR)/lib/libpthread.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  43. endif
  44. ifeq ($(CONFIG_INCLUDE_STATIC_LIBSTDC),y)
  45. COPY_STATIC_LIBSTDC=cp -a $(TOOLCHAIN_DIR)/lib/libstdc++.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  46. endif
  47. ifeq ($(CONFIG_INCLUDE_STATIC_LINK_SPEC),y)
  48. INSTALL_STATIC_SPEC=g++ -dumpspecs |sed s/--start-group}\ %G\ %L\ /--start-group}\ %G\ %L\ -lstdc++\ -lgcc_pic\ / >/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/specs
  49. REMOVE_STATIC_SPEC=rm /usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/specs
  50. endif
  51. include $(INCLUDE_DIR)/package.mk
  52. TARGET_LANGUAGES:="c,c++"
  53. BUGURL=https://dev.openwrt.org/
  54. PKGVERSION=OpenWrt GCC $(PKG_VERSION)
  55. TARGET_CPPFLAGS += -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS
  56. # not using sstrip here as this fucks up the .so's somehow
  57. STRIP:=$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)strip
  58. RSTRIP:= \
  59. NM="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)nm" \
  60. STRIP="$(STRIP)" \
  61. STRIP_KMOD="$(STRIP) --strip-debug" \
  62. $(SCRIPT_DIR)/rstrip.sh
  63. ifneq ($(CONFIG_SOFT_FLOAT),y)
  64. ifeq ($(CONFIG_arm),y)
  65. ARM_FLOAT_OPTION:= --with-float=hard
  66. endif
  67. endif
  68. GMPSRC=gmp-6.1.0
  69. define Download/gmp
  70. URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
  71. FILE:=$(GMPSRC).tar.bz2
  72. HASH:=498449a994efeba527885c10405993427995d3f86b8768d8cdf8d9dd7c6b73e8
  73. endef
  74. $(eval $(call Download,gmp))
  75. MPCSRC=mpc-1.0.3
  76. define Download/mpc
  77. URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
  78. FILE:=$(MPCSRC).tar.gz
  79. HASH:=617decc6ea09889fb08ede330917a00b16809b8db88c29c31bfbb49cbf88ecc3
  80. endef
  81. $(eval $(call Download,mpc))
  82. MPFRSRC=mpfr-3.1.4
  83. define Download/mpfr
  84. URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
  85. FILE:=$(MPFRSRC).tar.bz2
  86. HASH:=d3103a80cdad2407ed581f3618c4bed04e0c92d1cf771a65ead662cc397f7775
  87. endef
  88. $(eval $(call Download,mpfr))
  89. define Build/Prepare
  90. $(PKG_UNPACK)
  91. # we have to download and unpack additional stuff before patching
  92. tar -C $(PKG_BUILD_DIR) -xvjf $(DL_DIR)/$(GMPSRC).tar.bz2
  93. ln -sf $(PKG_BUILD_DIR)/$(GMPSRC) $(PKG_BUILD_DIR)/gmp
  94. tar -C $(PKG_BUILD_DIR) -xvzf $(DL_DIR)/$(MPCSRC).tar.gz
  95. ln -sf $(PKG_BUILD_DIR)/$(MPCSRC) $(PKG_BUILD_DIR)/mpc
  96. tar -C $(PKG_BUILD_DIR) -xvjf $(DL_DIR)/$(MPFRSRC).tar.bz2
  97. ln -sf $(PKG_BUILD_DIR)/$(MPFRSRC) $(PKG_BUILD_DIR)/mpfr
  98. $(Build/Patch)
  99. # poor man's fix for `none-openwrt-linux' not recognized when building with musl
  100. cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/mpfr/
  101. cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/gmp/
  102. chmod u+w $(PKG_BUILD_DIR)/mpc/config.sub
  103. cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/mpc/
  104. endef
  105. CONFIGURE_ARGS += CXXFLAGS_FOR_TARGET="-g -O2 -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS"
  106. define Build/Configure
  107. (cd $(PKG_BUILD_DIR); rm -f config.cache; \
  108. SHELL="$(BASH)" \
  109. $(TARGET_CONFIGURE_OPTS) \
  110. $(PKG_BUILD_DIR)/configure \
  111. $(CONFIGURE_ARGS) \
  112. --build=$(GNU_HOST_NAME) \
  113. --host=$(REAL_GNU_TARGET_NAME) \
  114. --target=$(REAL_GNU_TARGET_NAME) \
  115. --enable-languages=$(TARGET_LANGUAGES) \
  116. --with-bugurl=$(BUGURL) \
  117. --with-pkgversion="$(PKGVERSION)" \
  118. --enable-shared \
  119. $(if $(CONFIG_LIBC_USE_GLIBC),--enable,--disable)-__cxa_atexit \
  120. --with-default-libstdcxx-abi=gcc4-compatible \
  121. --enable-target-optspace \
  122. --with-gnu-ld \
  123. --disable-nls \
  124. --disable-libsanitizer \
  125. --disable-libvtv \
  126. --disable-libcilkrts \
  127. --disable-libmudflap \
  128. --disable-multilib \
  129. --disable-libgomp \
  130. --disable-libquadmath \
  131. --disable-libssp \
  132. --disable-decimal-float \
  133. --disable-libstdcxx-pch \
  134. --with-host-libstdcxx=-lstdc++ \
  135. --prefix=/usr \
  136. --libexecdir=/usr/lib \
  137. --with-local-prefix=/usr \
  138. --with-stage1-ldflags=-lstdc++ \
  139. $(ARM_FLOAT_OPTION) \
  140. $(SOFT_FLOAT_CONFIG_OPTION) \
  141. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  142. );
  143. endef
  144. define Build/Compile
  145. export SHELL="$(BASH)"; $(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) \
  146. DESTDIR="$(PKG_INSTALL_DIR)" $(MAKE_ARGS) all install
  147. endef
  148. ENVCFLAGS:="$(TARGET_OPTIMIZATION) $(EXTRA_OPTIMIZATION)
  149. ifeq ($(CONFIG_SOFT_FLOAT),y)
  150. ifeq ($(CONFIG_arm),y)
  151. ENVCFLAGS+= -mfloat-abi=soft
  152. else
  153. ENVCFLAGS+= -msoft-float
  154. endif
  155. endif
  156. ENVCFLAGS+="
  157. ENVLDFLAGS:="-Wl,-rpath=/usr/lib -Wl,--dynamic-linker=/usr/lib/$(DYNLINKER) -L/usr/lib, -lstdc++"
  158. define Package/gcc/install
  159. $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  160. cp -ar $(PKG_INSTALL_DIR)/usr/include $(1)/usr
  161. cp -a $(PKG_INSTALL_DIR)/usr/bin/{$(REAL_GNU_TARGET_NAME)-{g++,gcc},cpp,gcov} $(1)/usr/bin
  162. ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/c++
  163. ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/g++
  164. ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/$(REAL_GNU_TARGET_NAME)-c++
  165. ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/gcc
  166. ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/$(REAL_GNU_TARGET_NAME)-gcc-$(PKG_VERSION)
  167. cp -ar $(PKG_INSTALL_DIR)/usr/lib/gcc $(1)/usr/lib
  168. cp -ar $(TOOLCHAIN_DIR)/include $(1)/usr
  169. cp -a $(TOOLCHAIN_DIR)/lib/*.{o,so*} $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  170. cp -a $(TOOLCHAIN_DIR)/lib/*nonshared*.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  171. cp -a $(TOOLCHAIN_DIR)/lib/libm.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  172. $(COPY_STATIC_LIBC)
  173. $(COPY_STATIC_LIBPTHREAD)
  174. $(COPY_STATIC_LIBSTDC)
  175. rm -f $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/libgo*
  176. rm -f $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/libcc1*
  177. echo '#!/bin/sh' > $(1)/usr/bin/gcc_env.sh
  178. echo 'export LDFLAGS=$(ENVLDFLAGS)' >> $(1)/usr/bin/gcc_env.sh
  179. echo 'export CFLAGS=$(ENVCFLAGS)' >> $(1)/usr/bin/gcc_env.sh
  180. chmod +x $(1)/usr/bin/gcc_env.sh
  181. endef
  182. define Package/gcc/postinst
  183. #!/bin/sh
  184. $(INSTALL_STATIC_SPEC)
  185. endef
  186. define Package/gcc/postrm
  187. #!/bin/sh
  188. $(REMOVE_STATIC_SPEC)
  189. endef
  190. $(eval $(call BuildPackage,gcc))