]> git.ipfire.org Git - ipfire-2.x.git/blob - lfs/gcc
Merge branch 'next' into temp-c169-development
[ipfire-2.x.git] / lfs / gcc
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 ###############################################################################
20
21 ###############################################################################
22 # Definitions
23 ###############################################################################
24
25 include Config
26
27 VER = 11.3.0
28
29 GMP_VER = 6.2.1
30 MPFR_VER = 4.1.0
31 MPC_VER = 1.2.1
32
33 THISAPP = gcc-$(VER)
34 DL_FILE = $(THISAPP).tar.xz
35 DL_FROM = $(URL_IPFIRE)
36 DIR_APP = $(DIR_SRC)/$(THISAPP)
37
38 ifeq "$(PASS)" "1"
39 CFLAGS := $(patsubst -march=%,,$(CFLAGS))
40 CFLAGS := $(patsubst -mfpu=%,,$(CFLAGS))
41 CFLAGS := $(patsubst -mtune=%,,$(CFLAGS))
42 CFLAGS := $(patsubst -mfloat-abi=%,,$(CFLAGS))
43 CFLAGS := $(filter-out -fexceptions,$(CFLAGS))
44
45 CFLAGS := $(patsubst -mindirect-branch=%,,$(CFLAGS))
46 CFLAGS := $(patsubst -mfunction-return=%,,$(CFLAGS))
47 CFLAGS := $(patsubst -fstack-clash-protection,,$(CFLAGS))
48 CFLAGS := $(patsubst -fcf-protection,,$(CFLAGS))
49 endif
50
51 CXXFLAGS := $(CFLAGS)
52
53 ifeq "$(BUILD_ARCH)" "armv7hl"
54 FULL_BOOTSTRAP = 1
55 endif
56
57 ifeq "$(BUILD_ARCH)" "armv6l"
58 FULL_BOOTSTRAP = 1
59 endif
60
61 # Normal build or $(TOOLS_DIR) build.
62 #
63 ifeq "$(ROOT)" ""
64 TARGET = $(DIR_INFO)/$(THISAPP)
65 EXTRA_CONFIG = \
66 --prefix=/usr \
67 --libexecdir=/usr/lib \
68 --enable-shared \
69 --enable-threads=posix \
70 --enable-__cxa_atexit \
71 --enable-clocale=gnu \
72 --enable-languages=c,c++ \
73 --disable-bootstrap \
74 --disable-nls
75 EXTRA_MAKE =
76 EXTRA_INSTALL =
77 else
78 ifeq "$(PASS)" "1"
79 TARGET = $(DIR_INFO)/$(THISAPP)-tools1
80 EXTRA_CONFIG = \
81 --target=$(CROSSTARGET) \
82 --prefix=$(TOOLS_DIR) \
83 --with-sysroot=$(ROOT) \
84 --with-local-prefix=$(TOOLS_DIR) \
85 --with-native-system-header-dir=$(TOOLS_DIR)/include \
86 --with-glibc-version=2.11 \
87 --disable-nls \
88 --disable-shared \
89 --disable-multilib \
90 --disable-decimal-float \
91 --disable-threads \
92 --disable-libatomic \
93 --disable-libmudflap \
94 --disable-libssp \
95 --disable-libmpx \
96 --disable-libgomp \
97 --disable-libquadmath \
98 --disable-libstdc++-v3 \
99 --disable-libvtv \
100 --disable-libcilkrts \
101 --disable-libitm \
102 --disable-libsanitizer \
103 --with-newlib \
104 --without-headers \
105 --without-ppl \
106 --without-cloog \
107 --enable-languages=c,c++
108 EXTRA_MAKE =
109 EXTRA_INSTALL =
110 else
111 ifeq "$(PASS)" "2"
112 TARGET = $(DIR_INFO)/$(THISAPP)-tools2
113 EXTRA_ENV = \
114 CC="$(CROSSTARGET)-gcc" \
115 CXX="$(CROSSTARGET)-g++" \
116 AR="$(CROSSTARGET)-ar" \
117 RANLIB="$(CROSSTARGET)-ranlib"
118 EXTRA_CONFIG = \
119 --build=$(BUILDTARGET) \
120 --host=$(BUILDTARGET) \
121 --prefix=$(TOOLS_DIR) \
122 --with-local-prefix=$(TOOLS_DIR) \
123 --with-native-system-header-dir=$(TOOLS_DIR)/include \
124 --enable-languages=c,c++ \
125 --disable-libstdcxx-pch \
126 --disable-multilib \
127 --disable-libgomp
128 EXTRA_MAKE =
129 EXTRA_INSTALL =
130
131 ifeq "$(FULL_BOOTSTRAP)" "1"
132 EXTRA_CONFIG += --enable-bootstrap
133 else
134 EXTRA_CONFIG += --disable-bootstrap
135 endif
136 else
137 # PASS=L # libstdc++-v3
138 TARGET = $(DIR_INFO)/$(THISAPP)-libstdc++
139 EXTRA_ENV = \
140 CC="$(CROSSTARGET)-gcc" \
141 AR="$(CROSSTARGET)-ar" \
142 RANLIB="$(CROSSTARGET)-ranlib"
143 EXTRA_CONFIG = \
144 --host=$(CROSSTARGET) \
145 --prefix=$(TOOLS_DIR) \
146 --with-sysroot=$(ROOT) \
147 --disable-shared \
148 --disable-nls \
149 --disable-libstdcxx-threads \
150 --disable-libstdcxx-pch \
151 --with-gxx-include-dir=$(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)
152 EXTRA_MAKE =
153 EXTRA_INSTALL =
154 endif
155 endif
156 endif
157
158 ifeq "$(BUILD_ARCH)" "aarch64"
159 EXTRA_CONFIG += \
160 --enable-standard-branch-protection
161 endif
162
163 ifeq "$(BUILD_ARCH)" "armv7hl"
164 EXTRA_CONFIG += \
165 --with-float=hard
166 endif
167
168 ifeq "$(BUILD_ARCH)" "armv6l"
169 EXTRA_CONFIG += \
170 --with-arch=armv6zk+fp \
171 --with-float=softfp
172 # --disable-sjlj-exceptions
173 endif
174
175 ifeq "$(BUILD_ARCH)" "riscv64"
176 EXTRA_CONFIG += \
177 --with-arch=rv64gc \
178 --with-abi=lp64d
179 endif
180
181 EXTRA_CONFIG += \
182 --disable-multilib \
183 --with-bugurl=https://bugzilla.ipfire.org \
184 --disable-libunwind-exceptions \
185 --enable-gnu-unique-object
186
187 export XCFLAGS = $(CFLAGS)
188 export TCFLAGS = $(CFLAGS)
189
190 ###############################################################################
191 # Top-level Rules
192 ###############################################################################
193
194 objects = $(DL_FILE) \
195 gmp-$(GMP_VER).tar.xz \
196 mpfr-$(MPFR_VER).tar.xz \
197 mpc-$(MPC_VER).tar.gz
198
199 $(DL_FILE) = $(DL_FROM)/$(DL_FILE)
200 gmp-$(GMP_VER).tar.xz = $(DL_FROM)/gmp-$(GMP_VER).tar.xz
201 mpfr-$(MPFR_VER).tar.xz = $(DL_FROM)/mpfr-$(MPFR_VER).tar.xz
202 mpc-$(MPC_VER).tar.gz = $(DL_FROM)/mpc-$(MPC_VER).tar.gz
203
204 $(DL_FILE)_BLAKE2 = 7e562d25446ca4ab9fe8cdb714866f66aba3744d78bf84f31bfb097c1a981e4c7f990cb1e6bcfec5ae6671836a4984e2b70eb8fed81dcef5e244f88da8623469
205 gmp-$(GMP_VER).tar.xz_BLAKE2 = c0d85f175392a50cfa01bc6b0a312b235946ad8b4f6f84f6dabd33d7a6f2cc75c9b0e1e33057be07750bfa0145b7c4cf3b6188a5be6ca9d7271ec2276c84ebcb
206 mpfr-$(MPFR_VER).tar.xz_BLAKE2 = 41d1be0c4b557760f12a4525ad3a84b6e2cd6f0927c935fcfba577ac0490e582d1ae4b581dce58e21e705cf9d7c88373054d7fb7a94bb32c69b339f99a25dc68
207 mpc-$(MPC_VER).tar.gz_BLAKE2 = 9cd03c6a71839e4cdb3c1f18d718cc4d3097c3f8ec307a5c756bd5df27c68aa013755156b3b156efee1acabfee2269602c6a3a358092ef0d522271c9c56c133d
208
209 install : $(TARGET)
210
211 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
212
213 download :$(patsubst %,$(DIR_DL)/%,$(objects))
214
215 b2 : $(subst %,%_BLAKE2,$(objects))
216
217 ###############################################################################
218 # Downloading, checking, b2sum
219 ###############################################################################
220
221 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
222 @$(CHECK)
223
224 $(patsubst %,$(DIR_DL)/%,$(objects)) :
225 @$(LOAD)
226
227 $(subst %,%_BLAKE2,$(objects)) :
228 @$(B2SUM)
229
230 ###############################################################################
231 # Installation Details
232 ###############################################################################
233
234 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
235 @$(PREBUILD)
236 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
237 @mkdir $(DIR_SRC)/gcc-build
238
239 cd $(DIR_APP) && sed -i 's/install_to_$$(INSTALL_DEST) //' libiberty/Makefile.in
240 cd $(DIR_APP) && sed -i gcc/Makefile.in \
241 -e 's@\./fixinc\.sh@-c true@' \
242 -e 's/^T_CFLAGS =$$/& -fomit-frame-pointer/'
243
244 ifeq "$(TOOLCHAIN)" "1"
245 # Build gmp and mpfr internally in toolchain.
246 cd $(DIR_APP) && tar xfa $(DIR_DL)/gmp-$(GMP_VER).tar.xz
247 cd $(DIR_APP) && mv -v gmp-$(GMP_VER) gmp
248 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpfr-$(MPFR_VER).tar.xz
249 cd $(DIR_APP)/mpfr-$(MPFR_VER) && patch -Np1 < $(DIR_SRC)/src/patches/mpfr-4.1.0-cumulative-patches-1-to-13.patch
250 cd $(DIR_APP) && mv -v mpfr-$(MPFR_VER) mpfr
251 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpc-$(MPC_VER).tar.gz
252 cd $(DIR_APP) && mv -v mpc-$(MPC_VER) mpc
253
254 ifeq "$(PASS)" "2"
255 cd $(DIR_APP) && cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
256 `dirname $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name)`/include-fixed/limits.h
257 endif
258
259 for file in $$(find $(DIR_APP)/gcc/config -name linux64.h -o -name linux.h \
260 -o -name sysv4.h -o -name linux-eabi.h -o -name linux-elf.h -o -name aarch64-linux.h); do \
261 echo "Processing $${file}..."; \
262 sed -i $${file} \
263 -e 's@/lib\(64\)\?\(32\)\?/ld@$(TOOLS_DIR)&@g' \
264 -e 's@/usr@$(TOOLS_DIR)@g'; \
265 echo '#undef STANDARD_STARTFILE_PREFIX_1' >> $${file}; \
266 echo '#undef STANDARD_STARTFILE_PREFIX_2' >> $${file}; \
267 echo '#define STANDARD_STARTFILE_PREFIX_1 "$(TOOLS_DIR)/lib/"' >> $${file}; \
268 echo '#define STANDARD_STARTFILE_PREFIX_2 ""' >> $${file}; \
269 done
270 endif
271
272 ifeq "$(PASS)" "L"
273 # libstdc++ pass
274 cd $(DIR_SRC)/gcc-build && \
275 $(EXTRA_ENV) \
276 $(DIR_APP)/libstdc++-v3/configure \
277 $(EXTRA_CONFIG)
278 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
279 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
280
281 else
282 # The actual build.
283 cd $(DIR_SRC)/gcc-build && \
284 $(EXTRA_ENV) \
285 $(DIR_APP)/configure \
286 $(EXTRA_CONFIG)
287 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE) $(MAKETUNING)
288 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
289 endif
290
291 ifeq "$(TOOLCHAIN)" "1"
292 ifeq "$(PASS)" "1"
293 ln -svf libgcc.a $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/')
294 endif
295
296 ifeq "$(PASS)" "2"
297 ln -svf gcc $(TOOLS_DIR)/bin/cc
298 # remove gdb python files from libdir
299 rm -rf $(TOOLS_DIR)/lib/*-gdb.py
300 endif
301
302 ifeq "$(PASS)" "L"
303 # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70936
304 sed -e "s/^#include_next/#include/" -i $(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)/cstdlib
305 endif
306
307 else # NON-TOOLCHAIN
308 ln -svf ../usr/bin/cpp /lib
309 ln -svf gcc /usr/bin/cc
310 # remove gdb python files from libdir
311 rm -rf /usr/lib/*-gdb.py
312 endif
313
314 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build
315 @$(POSTBUILD)