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.

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