]> git.ipfire.org Git - ipfire-2.x.git/blame - lfs/gcc
toolchain: fix build with gcc<8 on builder.
[ipfire-2.x.git] / lfs / gcc
CommitLineData
cd1a2927 1###############################################################################
cd1a2927 2# #
70df8302 3# IPFire.org - A linux based firewall #
d83422d1 4# Copyright (C) 2007-2020 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
0c30619a 27VER = 10.2.0
82b312a9 28
854df4df
MT
29GMP_VER = 6.2.0
30MPFR_VER = 4.1.0
210b27e1 31MPC_VER = 1.1.0
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
ed635824 38CFLAGS := $(patsubst -march=%,,$(CFLAGS))
f3c01b39 39CFLAGS := $(patsubst -mfpu=%,,$(CFLAGS))
ed635824 40CFLAGS := $(patsubst -mtune=%,,$(CFLAGS))
62a430f9 41CFLAGS := $(patsubst -mfloat-abi=%,,$(CFLAGS))
8675b78a 42CFLAGS := $(filter-out -fexceptions,$(CFLAGS))
11b5e5cb
AF
43
44ifeq "$(PASS)" "1"
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
57ifeq "$(BUILD_ARCH)" "armv5tel"
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 \
82b312a9
MT
86 --disable-nls \
87 --disable-shared \
88 --disable-decimal-float \
89 --disable-threads \
764a3f1f 90 --disable-libatomic \
82b312a9
MT
91 --disable-libmudflap \
92 --disable-libssp \
8bc5ded2 93 --disable-libmpx \
82b312a9
MT
94 --disable-libgomp \
95 --disable-libquadmath \
764a3f1f
AF
96 --disable-libstdc++-v3 \
97 --disable-libvtv \
98 --disable-libcilkrts \
99 --disable-libitm \
100 --disable-libsanitizer \
82b312a9
MT
101 --with-newlib \
102 --without-headers \
103 --without-ppl \
104 --without-cloog \
764a3f1f 105 --enable-languages=c,c++
575ea031 106 EXTRA_MAKE =
cd1a2927
MT
107 EXTRA_INSTALL =
108else
764a3f1f 109ifeq "$(PASS)" "2"
cd1a2927 110 TARGET = $(DIR_INFO)/$(THISAPP)-tools2
82b312a9 111 EXTRA_ENV = \
6f8f4522 112 CC="$(CROSSTARGET)-gcc" \
764a3f1f 113 CXX="$(CROSSTARGET)-g++" \
82b312a9
MT
114 AR="$(CROSSTARGET)-ar" \
115 RANLIB="$(CROSSTARGET)-ranlib"
116 EXTRA_CONFIG = \
82b312a9 117 --build=$(BUILDTARGET) \
6c4cc7ea
MT
118 --prefix=$(TOOLS_DIR) \
119 --with-local-prefix=$(TOOLS_DIR) \
120 --with-native-system-header-dir=$(TOOLS_DIR)/include \
82b312a9
MT
121 --enable-languages=c,c++ \
122 --disable-libstdcxx-pch \
b45e371f 123 --disable-libgomp
cd1a2927
MT
124 EXTRA_MAKE =
125 EXTRA_INSTALL =
b45e371f
MT
126
127 ifeq "$(FULL_BOOTSTRAP)" "1"
128 EXTRA_CONFIG += --enable-bootstrap
129 else
130 EXTRA_CONFIG += --disable-bootstrap
131 endif
764a3f1f
AF
132else
133 # PASS=L # libstdc++-v3
134 TARGET = $(DIR_INFO)/$(THISAPP)-libstdc++
135 EXTRA_ENV = \
6f8f4522 136 CC="$(CROSSTARGET)-gcc" \
764a3f1f
AF
137 AR="$(CROSSTARGET)-ar" \
138 RANLIB="$(CROSSTARGET)-ranlib"
139 EXTRA_CONFIG = \
140 --host=$(CROSSTARGET) \
6c4cc7ea 141 --prefix=$(TOOLS_DIR) \
764a3f1f
AF
142 --with-sysroot=$(ROOT) \
143 --disable-shared \
144 --disable-nls \
145 --disable-libstdcxx-threads \
146 --disable-libstdcxx-pch \
6c4cc7ea 147 --with-gxx-include-dir=$(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)
764a3f1f
AF
148 EXTRA_MAKE =
149 EXTRA_INSTALL =
150endif
cd1a2927
MT
151endif
152endif
153
0c30619a
MT
154ifeq "$(BUILD_ARCH)" "aarch64"
155 EXTRA_CONFIG += \
156 --enable-standard-branch-protection
157endif
158
dc7d6b20 159ifeq "$(BUILD_ARCH)" "armv7hl"
0c24d56d
MT
160 EXTRA_CONFIG += \
161 --with-float=hard
162endif
163
dc7d6b20 164ifeq "$(BUILD_ARCH)" "armv5tel"
51f9e7ac 165 EXTRA_CONFIG += \
afbd9856
MT
166 --with-float=soft \
167 --disable-sjlj-exceptions
51f9e7ac
MT
168endif
169
dc7d6b20 170ifeq "$(BUILD_ARCH)" "i586"
ed635824
MT
171 EXTRA_CONFIG += \
172 --with-arch=i586 \
173 --with-tune=generic
174endif
175
176EXTRA_CONFIG += \
51777e5d 177 --disable-multilib \
ed635824
MT
178 --with-bugurl=http://bugtracker.ipfire.org \
179 --disable-libunwind-exceptions \
180 --enable-gnu-unique-object
181
51f9e7ac
MT
182export XCFLAGS = $(CFLAGS)
183export TCFLAGS = $(CFLAGS)
184
cd1a2927
MT
185###############################################################################
186# Top-level Rules
187###############################################################################
82b312a9
MT
188
189objects = $(DL_FILE) \
11b5e5cb
AF
190 gmp-$(GMP_VER).tar.xz \
191 mpfr-$(MPFR_VER).tar.xz \
8675b78a 192 mpc-$(MPC_VER).tar.gz
cd1a2927 193
41921bd9 194$(DL_FILE) = $(DL_FROM)/$(DL_FILE)
176b1cc6 195gmp-$(GMP_VER).tar.xz = $(DL_FROM)/gmp-$(GMP_VER).tar.xz
11b5e5cb 196mpfr-$(MPFR_VER).tar.xz = $(DL_FROM)/mpfr-$(MPFR_VER).tar.xz
8675b78a 197mpc-$(MPC_VER).tar.gz = $(DL_FROM)/mpc-$(MPC_VER).tar.gz
cd1a2927 198
0c30619a 199$(DL_FILE)_MD5 = e9fd9b1789155ad09bcf3ae747596b50
854df4df
MT
200gmp-$(GMP_VER).tar.xz_MD5 = a325e3f09e6d91e62101e59f9bda3ec1
201mpfr-$(MPFR_VER).tar.xz_MD5 = bdd3d5efba9c17da8d83a35ec552baef
210b27e1 202mpc-$(MPC_VER).tar.gz_MD5 = 4125404e41e482ec68282a2e687f6c73
cd1a2927
MT
203
204install : $(TARGET)
205
206check : $(patsubst %,$(DIR_CHK)/%,$(objects))
207
208download :$(patsubst %,$(DIR_DL)/%,$(objects))
209
210md5 : $(subst %,%_MD5,$(objects))
211
212###############################################################################
213# Downloading, checking, md5sum
214###############################################################################
215
216$(patsubst %,$(DIR_CHK)/%,$(objects)) :
217 @$(CHECK)
218
219$(patsubst %,$(DIR_DL)/%,$(objects)) :
220 @$(LOAD)
221
222$(subst %,%_MD5,$(objects)) :
223 @$(MD5)
224
225###############################################################################
226# Installation Details
227###############################################################################
228
229$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
230 @$(PREBUILD)
8675b78a 231 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
dd714b8a 232 @mkdir $(DIR_SRC)/gcc-build
51f9e7ac 233
991d11d7
MT
234 cd $(DIR_APP) && sed -i 's/install_to_$$(INSTALL_DEST) //' libiberty/Makefile.in
235 cd $(DIR_APP) && sed -i gcc/Makefile.in \
236 -e 's@\./fixinc\.sh@-c true@' \
237 -e 's/^T_CFLAGS =$$/& -fomit-frame-pointer/'
238
239ifeq "$(TOOLCHAIN)" "1"
82b312a9 240 # Build gmp and mpfr internally in toolchain.
11b5e5cb 241 cd $(DIR_APP) && tar xfa $(DIR_DL)/gmp-$(GMP_VER).tar.xz
82b312a9 242 cd $(DIR_APP) && mv -v gmp-$(GMP_VER) gmp
11b5e5cb 243 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpfr-$(MPFR_VER).tar.xz
82b312a9 244 cd $(DIR_APP) && mv -v mpfr-$(MPFR_VER) mpfr
8675b78a
MT
245 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpc-$(MPC_VER).tar.gz
246 cd $(DIR_APP) && mv -v mpc-$(MPC_VER) mpc
82b312a9 247
991d11d7 248ifeq "$(PASS)" "2"
764a3f1f 249 cd $(DIR_APP) && cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
6c4cc7ea 250 `dirname $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name)`/include-fixed/limits.h
991d11d7
MT
251endif
252
82b312a9 253 for file in $$(find $(DIR_APP)/gcc/config -name linux64.h -o -name linux.h \
cfd39a32 254 -o -name sysv4.h -o -name linux-eabi.h -o -name linux-elf.h -o -name aarch64-linux.h); do \
82b312a9
MT
255 echo "Processing $${file}..."; \
256 sed -i $${file} \
6c4cc7ea
MT
257 -e 's@/lib\(64\)\?\(32\)\?/ld@$(TOOLS_DIR)&@g' \
258 -e 's@/usr@$(TOOLS_DIR)@g'; \
764a3f1f
AF
259 echo '#undef STANDARD_STARTFILE_PREFIX_1' >> $${file}; \
260 echo '#undef STANDARD_STARTFILE_PREFIX_2' >> $${file}; \
6c4cc7ea 261 echo '#define STANDARD_STARTFILE_PREFIX_1 "$(TOOLS_DIR)/lib/"' >> $${file}; \
82b312a9
MT
262 echo '#define STANDARD_STARTFILE_PREFIX_2 ""' >> $${file}; \
263 done
82b312a9 264endif
dd714b8a 265
991d11d7 266ifeq "$(PASS)" "L"
764a3f1f
AF
267 # libstdc++ pass
268 cd $(DIR_SRC)/gcc-build && \
269 $(EXTRA_ENV) \
270 $(DIR_APP)/libstdc++-v3/configure \
271 $(EXTRA_CONFIG)
79ccd55d 272 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
764a3f1f 273 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
cfd39a32 274
764a3f1f 275else
82b312a9
MT
276 # The actual build.
277 cd $(DIR_SRC)/gcc-build && \
278 $(EXTRA_ENV) \
279 $(DIR_APP)/configure \
280 $(EXTRA_CONFIG)
79ccd55d 281 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
f97be0a6 282 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
764a3f1f 283endif
82b312a9 284
991d11d7
MT
285ifeq "$(TOOLCHAIN)" "1"
286 ifeq "$(PASS)" "1"
6c4cc7ea 287 ln -svf libgcc.a $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/')
991d11d7
MT
288 endif
289
290 ifeq "$(PASS)" "2"
6c4cc7ea 291 ln -svf gcc $(TOOLS_DIR)/bin/cc
8f2ac12a 292 # remove gdb python files from libdir
6c4cc7ea 293 rm -rf $(TOOLS_DIR)/lib/*-gdb.py
991d11d7
MT
294 endif
295
296 ifeq "$(PASS)" "L"
297 # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70936
6c4cc7ea 298 sed -e "s/^#include_next/#include/" -i $(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)/cstdlib
991d11d7
MT
299 endif
300
301else # NON-TOOLCHAIN
302 ln -svf ../usr/bin/cpp /lib
303 ln -svf gcc /usr/bin/cc
304 # remove gdb python files from libdir
305 rm -rf /usr/lib/*-gdb.py
cd1a2927 306endif
991d11d7 307
cd1a2927
MT
308 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build
309 @$(POSTBUILD)