]> git.ipfire.org Git - ipfire-2.x.git/blob - lfs/gcc
binutils+gcc: Fix that the toolchain compiler is trying to link against host libraries
[ipfire-2.x.git] / lfs / gcc
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2021 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.1.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 --prefix=$(TOOLS_DIR) \
120 --with-local-prefix=$(TOOLS_DIR) \
121 --with-native-system-header-dir=$(TOOLS_DIR)/include \
122 --enable-languages=c,c++ \
123 --disable-libstdcxx-pch \
124 --disable-multilib \
125 --disable-libgomp
126 EXTRA_MAKE =
127 EXTRA_INSTALL =
128
129 ifeq "$(FULL_BOOTSTRAP)" "1"
130 EXTRA_CONFIG += --enable-bootstrap
131 else
132 EXTRA_CONFIG += --disable-bootstrap
133 endif
134 else
135 # PASS=L # libstdc++-v3
136 TARGET = $(DIR_INFO)/$(THISAPP)-libstdc++
137 EXTRA_ENV = \
138 CC="$(CROSSTARGET)-gcc" \
139 AR="$(CROSSTARGET)-ar" \
140 RANLIB="$(CROSSTARGET)-ranlib"
141 EXTRA_CONFIG = \
142 --host=$(CROSSTARGET) \
143 --prefix=$(TOOLS_DIR) \
144 --with-sysroot=$(ROOT) \
145 --disable-shared \
146 --disable-nls \
147 --disable-libstdcxx-threads \
148 --disable-libstdcxx-pch \
149 --with-gxx-include-dir=$(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)
150 EXTRA_MAKE =
151 EXTRA_INSTALL =
152 endif
153 endif
154 endif
155
156 ifeq "$(BUILD_ARCH)" "aarch64"
157 EXTRA_CONFIG += \
158 --enable-standard-branch-protection
159 endif
160
161 ifeq "$(BUILD_ARCH)" "armv7hl"
162 EXTRA_CONFIG += \
163 --with-float=hard
164 endif
165
166 ifeq "$(BUILD_ARCH)" "armv6l"
167 EXTRA_CONFIG += \
168 --with-arch=armv6zk+fp \
169 --with-float=softfp
170 # --disable-sjlj-exceptions
171 endif
172
173 ifeq "$(BUILD_ARCH)" "riscv64"
174 EXTRA_CONFIG += \
175 --with-arch=rv64gc \
176 --with-abi=lp64d
177 endif
178
179 EXTRA_CONFIG += \
180 --disable-multilib \
181 --with-bugurl=http://bugtracker.ipfire.org \
182 --disable-libunwind-exceptions \
183 --enable-gnu-unique-object
184
185 export XCFLAGS = $(CFLAGS)
186 export TCFLAGS = $(CFLAGS)
187
188 ###############################################################################
189 # Top-level Rules
190 ###############################################################################
191
192 objects = $(DL_FILE) \
193 gmp-$(GMP_VER).tar.xz \
194 mpfr-$(MPFR_VER).tar.xz \
195 mpc-$(MPC_VER).tar.gz
196
197 $(DL_FILE) = $(DL_FROM)/$(DL_FILE)
198 gmp-$(GMP_VER).tar.xz = $(DL_FROM)/gmp-$(GMP_VER).tar.xz
199 mpfr-$(MPFR_VER).tar.xz = $(DL_FROM)/mpfr-$(MPFR_VER).tar.xz
200 mpc-$(MPC_VER).tar.gz = $(DL_FROM)/mpc-$(MPC_VER).tar.gz
201
202 $(DL_FILE)_MD5 = 77f6252be0861ab918042acf42bc10ff
203 gmp-$(GMP_VER).tar.xz_MD5 = 0b82665c4a92fd2ade7440c13fcaa42b
204 mpfr-$(MPFR_VER).tar.xz_MD5 = bdd3d5efba9c17da8d83a35ec552baef
205 mpc-$(MPC_VER).tar.gz_MD5 = 9f16c976c25bb0f76b50be749cd7a3a8
206
207 install : $(TARGET)
208
209 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
210
211 download :$(patsubst %,$(DIR_DL)/%,$(objects))
212
213 md5 : $(subst %,%_MD5,$(objects))
214
215 ###############################################################################
216 # Downloading, checking, md5sum
217 ###############################################################################
218
219 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
220 @$(CHECK)
221
222 $(patsubst %,$(DIR_DL)/%,$(objects)) :
223 @$(LOAD)
224
225 $(subst %,%_MD5,$(objects)) :
226 @$(MD5)
227
228 ###############################################################################
229 # Installation Details
230 ###############################################################################
231
232 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
233 @$(PREBUILD)
234 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
235
236 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc/gcc.git-745dae5-remove_cyclades.patch
237
238
239 @mkdir $(DIR_SRC)/gcc-build
240
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
246 ifeq "$(TOOLCHAIN)" "1"
247 # Build gmp and mpfr internally in toolchain.
248 cd $(DIR_APP) && tar xfa $(DIR_DL)/gmp-$(GMP_VER).tar.xz
249 cd $(DIR_APP) && mv -v gmp-$(GMP_VER) gmp
250 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpfr-$(MPFR_VER).tar.xz
251 cd $(DIR_APP) && mv -v mpfr-$(MPFR_VER) mpfr
252 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpc-$(MPC_VER).tar.gz
253 cd $(DIR_APP) && mv -v mpc-$(MPC_VER) mpc
254
255 ifeq "$(PASS)" "2"
256 cd $(DIR_APP) && cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
257 `dirname $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name)`/include-fixed/limits.h
258 endif
259
260 for file in $$(find $(DIR_APP)/gcc/config -name linux64.h -o -name linux.h \
261 -o -name sysv4.h -o -name linux-eabi.h -o -name linux-elf.h -o -name aarch64-linux.h); do \
262 echo "Processing $${file}..."; \
263 sed -i $${file} \
264 -e 's@/lib\(64\)\?\(32\)\?/ld@$(TOOLS_DIR)&@g' \
265 -e 's@/usr@$(TOOLS_DIR)@g'; \
266 echo '#undef STANDARD_STARTFILE_PREFIX_1' >> $${file}; \
267 echo '#undef STANDARD_STARTFILE_PREFIX_2' >> $${file}; \
268 echo '#define STANDARD_STARTFILE_PREFIX_1 "$(TOOLS_DIR)/lib/"' >> $${file}; \
269 echo '#define STANDARD_STARTFILE_PREFIX_2 ""' >> $${file}; \
270 done
271 endif
272
273 ifeq "$(PASS)" "L"
274 # libstdc++ pass
275 cd $(DIR_SRC)/gcc-build && \
276 $(EXTRA_ENV) \
277 $(DIR_APP)/libstdc++-v3/configure \
278 $(EXTRA_CONFIG)
279 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
280 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
281
282 else
283 # The actual build.
284 cd $(DIR_SRC)/gcc-build && \
285 $(EXTRA_ENV) \
286 $(DIR_APP)/configure \
287 $(EXTRA_CONFIG)
288 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE) $(MAKETUNING)
289 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
290 endif
291
292 ifeq "$(TOOLCHAIN)" "1"
293 ifeq "$(PASS)" "1"
294 ln -svf libgcc.a $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/')
295 endif
296
297 ifeq "$(PASS)" "2"
298 ln -svf gcc $(TOOLS_DIR)/bin/cc
299 # remove gdb python files from libdir
300 rm -rf $(TOOLS_DIR)/lib/*-gdb.py
301 endif
302
303 ifeq "$(PASS)" "L"
304 # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70936
305 sed -e "s/^#include_next/#include/" -i $(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)/cstdlib
306 endif
307
308 else # 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
313 endif
314
315 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build
316 @$(POSTBUILD)