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