blob: d7dc55e374d7547958cfc4aa923d16fa3bfc689b [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#
2# Copyright (C) 2002-2003 Erik Andersen <andersen@uclibc.org>
3# Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
4# Copyright (C) 2005-2006 Felix Fietkau <nbd@nbd.name>
5# Copyright (C) 2006-2014 OpenWrt.org
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
21include $(TOPDIR)/rules.mk
22
23PKG_NAME:=gcc
24GCC_VERSION:=$(call qstrip,$(CONFIG_GCC_VERSION))
25PKG_VERSION:=$(firstword $(subst +, ,$(GCC_VERSION)))
26GCC_MAJOR_VERSION:=$(word 1,$(subst ., ,$(PKG_VERSION)))
27GCC_DIR:=$(PKG_NAME)-$(PKG_VERSION)
28
29PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
30PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
31PKG_CPE_ID:=cpe:/a:gnu:gcc
32
33ifeq ($(PKG_VERSION),11.3.0)
34 PKG_HASH:=b47cf2818691f5b1e21df2bb38c795fac2cfbd640ede2d0a5e1c89e338a3ac39
35endif
36
37ifeq ($(PKG_VERSION),12.3.0)
38 PKG_HASH:=949a5d4f99e786421a93b532b22ffab5578de7321369975b91aec97adfda8c3b
39endif
40
41ifeq ($(PKG_VERSION),13.3.0)
42 PKG_HASH:=0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083
43endif
44
45ifeq ($(PKG_VERSION),14.2.0)
46 PKG_HASH:=a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9
47endif
48
49PATCH_DIR=../patches-$(GCC_MAJOR_VERSION).x
50
51BUGURL=http://bugs.openwrt.org/
52PKGVERSION=OpenWrt GCC $(PKG_VERSION) $(REVISION)
53
54HOST_BUILD_PARALLEL:=1
55
56include $(INCLUDE_DIR)/toolchain-build.mk
57
58HOST_SOURCE_DIR:=$(HOST_BUILD_DIR)
59ifeq ($(GCC_VARIANT),minimal)
60 GCC_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
61else
62 HOST_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
63 GCC_BUILD_DIR:=$(HOST_BUILD_DIR)
64endif
65
66HOST_STAMP_PREPARED:=$(HOST_BUILD_DIR)/.prepared
67HOST_STAMP_BUILT:=$(GCC_BUILD_DIR)/.built
68HOST_STAMP_CONFIGURED:=$(GCC_BUILD_DIR)/.configured
69HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.gcc_$(GCC_VARIANT)_installed
70
71SEP:=,
72TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)$(if $(CONFIG_INSTALL_GCCGO),$(SEP)go)"
73
74TAR_OPTIONS += \
75 --exclude-from='$(CURDIR)/../exclude-testsuite' --exclude=gcc/ada/*.ad* \
76 --exclude=libjava
77
78# this needs to be without -L/-lzstd flags or other parts fail to build
79# use an absolute path to ensure it really picks up our version
80export ac_cv_search_ZSTD_compress=$(STAGING_DIR_HOST)/lib/libzstd.a -pthread
81export libgcc_cv_fixed_point=no
82ifdef CONFIG_INSTALL_GCCGO
83 export libgo_cv_c_split_stack_supported=no
84endif
85
86ifdef CONFIG_GCC_USE_GRAPHITE
87 GRAPHITE_CONFIGURE:= --with-isl=$(STAGING_DIR_HOST)
88else
89 GRAPHITE_CONFIGURE:= --without-isl --without-cloog
90endif
91
92GCC_CONFIGURE:= \
93 SHELL="$(BASH)" \
94 $(HOST_SOURCE_DIR)/configure \
95 --with-bugurl=$(BUGURL) \
96 --with-pkgversion="$(PKGVERSION)" \
97 --prefix=$(TOOLCHAIN_DIR) \
98 --build=$(GNU_HOST_NAME) \
99 --host=$(GNU_HOST_NAME) \
100 --target=$(REAL_GNU_TARGET_NAME) \
101 --with-gnu-ld \
102 --enable-target-optspace \
103 --disable-libgomp \
104 --disable-libmudflap \
105 --disable-multilib \
106 --disable-libmpx \
107 --disable-nls \
108 --disable-libssp \
109 $(GRAPHITE_CONFIGURE) \
110 --with-host-libstdcxx=-lstdc++ \
111 $(SOFT_FLOAT_CONFIG_OPTION) \
112 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
113 $(if $(CONFIG_mips64)$(CONFIG_mips64el),--with-arch=mips64 \
114 --with-abi=$(call qstrip,$(CONFIG_MIPS64_ABI))) \
115 $(if $(CONFIG_arc),--with-cpu=$(CONFIG_CPU_TYPE)) \
116 $(if $(CONFIG_powerpc64), $(if $(CONFIG_USE_MUSL),--with-abi=elfv2)) \
117 --with-system-zlib=$(STAGING_DIR_HOST) \
118 --with-zstd=$(STAGING_DIR_HOST) \
119 --with-gmp=$(STAGING_DIR_HOST) \
120 --with-mpfr=$(STAGING_DIR_HOST) \
121 --with-mpc=$(STAGING_DIR_HOST) \
122 --disable-decimal-float \
123 --with-diagnostics-color=auto-if-env \
124 --enable-__cxa_atexit \
125 --enable-libstdcxx-dual-abi \
126 --with-default-libstdcxx-abi=new
127ifneq ($(CONFIG_mips)$(CONFIG_mipsel),)
128 GCC_CONFIGURE += --with-mips-plt
129endif
130
131ifneq ($(CONFIG_GCC_DEFAULT_PIE),)
132 GCC_CONFIGURE+= \
133 --enable-default-pie
134endif
135
136ifneq ($(CONFIG_GCC_DEFAULT_SSP),)
137 GCC_CONFIGURE+= \
138 --enable-default-ssp
139endif
140
141ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
142 GCC_CONFIGURE+= \
143 --enable-biarch \
144 --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
145endif
146
147ifdef CONFIG_sparc
148 GCC_CONFIGURE+= \
149 --enable-targets=all \
150 --with-long-double-128
151endif
152
153ifneq ($(GCC_ARCH),)
154 GCC_CONFIGURE+= --with-arch=$(GCC_ARCH)
155endif
156
157ifeq ($(CONFIG_arm),y)
158 GCC_CONFIGURE+= \
159 --with-cpu=$(word 1, $(subst +," ,$(CONFIG_CPU_TYPE)))
160
161 ifneq ($(CONFIG_SOFT_FLOAT),y)
162 GCC_CONFIGURE+= \
163 --with-fpu=$(word 2, $(subst +, ",$(CONFIG_CPU_TYPE))) \
164 --with-float=hard
165 endif
166
167 # Do not let TARGET_CFLAGS get poisoned by extra CPU optimization flags
168 # that do not belong here. The cpu,fpu type should be specified via
169 # --with-cpu and --with-fpu for ARM and not CFLAGS.
170 TARGET_CFLAGS:=$(filter-out -m%,$(call qstrip,$(TARGET_CFLAGS)))
171endif
172
173ifeq ($(CONFIG_TARGET_x86)$(CONFIG_USE_GLIBC)$(CONFIG_INSTALL_GCCGO),yyy)
174 TARGET_CFLAGS+=-fno-split-stack
175endif
176
177TARGET_CFLAGS := $(filter-out -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64,$(TARGET_CFLAGS))
178
179CFLAGS:=$(HOST_CFLAGS) -pipe
180ifneq ($(shell gcc --version 2>&1 | grep -E "Apple.(LLVM|clang)"),)
181 CFLAGS+= -fbracket-depth=512
182endif
183
184GCC_CONFIGURE+= \
185 CFLAGS="$(CFLAGS)" \
186 CXXFLAGS="$(CFLAGS)" \
187 CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
188 CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
189 GOCFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
190
191GCC_MAKE:= \
192 export SHELL="$(BASH)"; \
193 $(MAKE)
194
195define Host/SetToolchainInfo
196 $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
197 $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
198endef
199
200
201ifeq ($(GCC_MAJOR_VERSION),11)
202 GCC_VERSION_FILE:=gcc/version.c
203else
204 GCC_VERSION_FILE:=gcc/genversion.cc
205endif
206
207ifneq ($(GCC_PREPARE),)
208 define Host/Prepare
209 $(call Host/SetToolchainInfo)
210 $(call Host/Prepare/Default)
211 ln -snf $(GCC_DIR) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
212 $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_SOURCE_DIR)/
213 $(SED) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(HOST_SOURCE_DIR)/gcc/config/*/t-*
214 $(SED) 'd' $(HOST_SOURCE_DIR)/gcc/DEV-PHASE
215 $(SED) 's, DATESTAMP,,' $(HOST_SOURCE_DIR)/$(GCC_VERSION_FILE)
216 $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(HOST_SOURCE_DIR)/libstdc++-v3/configure
217 mkdir -p $(GCC_BUILD_DIR)
218 endef
219else
220 define Host/Prepare
221 mkdir -p $(GCC_BUILD_DIR)
222 endef
223endif
224
225define Host/Configure
226 (cd $(GCC_BUILD_DIR) && rm -f config.cache; \
227 $(GCC_CONFIGURE) \
228 );
229endef
230
231define Host/Clean
232 rm -rf $(if $(GCC_PREPARE),$(HOST_SOURCE_DIR)) \
233 $(HOST_BUILD_PREFIX)/stamp/.gcc_* \
234 $(HOST_BUILD_PREFIX)/stamp/.binutils_* \
235 $(GCC_BUILD_DIR) \
236 $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
237 $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
238 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
239 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
240endef