]> git.ipfire.org Git - ipfire-2.x.git/blob - lfs/gcc
Merge branch 'master' into next
[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 = 13.1.0
28
29 GMP_VER = 6.2.1
30 MPFR_VER = 4.2.0
31 MPC_VER = 1.3.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 # Normal build or $(TOOLS_DIR) build.
54 #
55 ifeq "$(ROOT)" ""
56 TARGET = $(DIR_INFO)/$(THISAPP)
57 EXTRA_CONFIG = \
58 --prefix=/usr \
59 --libexecdir=/usr/lib \
60 --enable-shared \
61 --enable-threads=posix \
62 --enable-__cxa_atexit \
63 --enable-clocale=gnu \
64 --enable-languages=c,c++ \
65 --disable-bootstrap \
66 --disable-nls
67 EXTRA_MAKE =
68 EXTRA_INSTALL =
69 ifeq "$(PASS)" "A"
70 TARGET = $(DIR_INFO)/$(THISAPP)-libatomic
71 endif
72 else
73 ifeq "$(PASS)" "1"
74 TARGET = $(DIR_INFO)/$(THISAPP)-tools1
75 EXTRA_CONFIG = \
76 --target=$(CROSSTARGET) \
77 --prefix=$(TOOLS_DIR) \
78 --with-sysroot=$(ROOT) \
79 --with-local-prefix=$(TOOLS_DIR) \
80 --with-native-system-header-dir=$(TOOLS_DIR)/include \
81 --with-glibc-version=2.11 \
82 --disable-nls \
83 --disable-shared \
84 --disable-multilib \
85 --disable-decimal-float \
86 --disable-threads \
87 --disable-libatomic \
88 --disable-libmudflap \
89 --disable-libssp \
90 --disable-libmpx \
91 --disable-libgomp \
92 --disable-libquadmath \
93 --disable-libstdc++-v3 \
94 --disable-libvtv \
95 --disable-libcilkrts \
96 --disable-libitm \
97 --disable-libsanitizer \
98 --with-newlib \
99 --without-headers \
100 --without-ppl \
101 --without-cloog \
102 --enable-languages=c,c++
103 EXTRA_MAKE =
104 EXTRA_INSTALL =
105 else
106 ifeq "$(PASS)" "2"
107 TARGET = $(DIR_INFO)/$(THISAPP)-tools2
108 EXTRA_ENV = \
109 CC="$(CROSSTARGET)-gcc" \
110 CXX="$(CROSSTARGET)-g++" \
111 AR="$(CROSSTARGET)-ar" \
112 RANLIB="$(CROSSTARGET)-ranlib"
113 EXTRA_CONFIG = \
114 --build=$(BUILDTARGET) \
115 --host=$(BUILDTARGET) \
116 --prefix=$(TOOLS_DIR) \
117 --with-local-prefix=$(TOOLS_DIR) \
118 --with-native-system-header-dir=$(TOOLS_DIR)/include \
119 --disable-bootstrap \
120 --enable-languages=c,c++ \
121 --disable-libstdcxx-pch \
122 --disable-multilib \
123 --disable-libgomp
124 EXTRA_MAKE =
125 EXTRA_INSTALL =
126 else
127 # PASS=L # libstdc++-v3
128 TARGET = $(DIR_INFO)/$(THISAPP)-libstdc++
129 EXTRA_ENV = \
130 CC="$(CROSSTARGET)-gcc" \
131 AR="$(CROSSTARGET)-ar" \
132 RANLIB="$(CROSSTARGET)-ranlib"
133 EXTRA_CONFIG = \
134 --host=$(CROSSTARGET) \
135 --prefix=$(TOOLS_DIR) \
136 --with-sysroot=$(ROOT) \
137 --disable-shared \
138 --disable-nls \
139 --disable-libstdcxx-threads \
140 --disable-libstdcxx-pch \
141 --with-gxx-include-dir=$(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)
142 EXTRA_MAKE =
143 EXTRA_INSTALL =
144 endif
145 endif
146 endif
147
148 ifeq "$(BUILD_ARCH)" "aarch64"
149 EXTRA_CONFIG += \
150 --enable-standard-branch-protection
151 endif
152
153 ifeq "$(BUILD_ARCH)" "riscv64"
154 EXTRA_CONFIG += \
155 --with-arch=rv64gc \
156 --with-abi=lp64d
157 endif
158
159 EXTRA_CONFIG += \
160 --disable-multilib \
161 --with-bugurl=https://bugzilla.ipfire.org \
162 --disable-libunwind-exceptions \
163 --enable-gnu-unique-object
164
165 export XCFLAGS = $(CFLAGS)
166 export TCFLAGS = $(CFLAGS)
167
168 ###############################################################################
169 # Top-level Rules
170 ###############################################################################
171
172 objects = $(DL_FILE) \
173 gmp-$(GMP_VER).tar.xz \
174 mpfr-$(MPFR_VER).tar.xz \
175 mpc-$(MPC_VER).tar.gz
176
177 $(DL_FILE) = $(DL_FROM)/$(DL_FILE)
178 gmp-$(GMP_VER).tar.xz = $(DL_FROM)/gmp-$(GMP_VER).tar.xz
179 mpfr-$(MPFR_VER).tar.xz = $(DL_FROM)/mpfr-$(MPFR_VER).tar.xz
180 mpc-$(MPC_VER).tar.gz = $(DL_FROM)/mpc-$(MPC_VER).tar.gz
181
182 $(DL_FILE)_BLAKE2 = b956a773cffe8b43bd6c9a99fe614f53f665438925a6b320975d301f547923e45d4d6fa577a143467fb03e0a9c1bab2b6719a1011d672367f3e644433a2d7606
183 gmp-$(GMP_VER).tar.xz_BLAKE2 = c0d85f175392a50cfa01bc6b0a312b235946ad8b4f6f84f6dabd33d7a6f2cc75c9b0e1e33057be07750bfa0145b7c4cf3b6188a5be6ca9d7271ec2276c84ebcb
184 mpfr-$(MPFR_VER).tar.xz_BLAKE2 = dd88ae3a6a910ad8faeb791b49c3b1085de5d0d4c49c637c124bf4d9bc79fb621d0d1d69e07d0642b9b678f6d355a5830d083dfd189e1e91d0e04c970c10bd64
185 mpc-$(MPC_VER).tar.gz_BLAKE2 = 76434e6f8830af3571836d51576bfebbc9701e9bbb5c4686f134081cd96cd90ae02f7ff42bf9e3957c7a7ba92b6b2d9cdabe18f0269271147521cd7f6a2d551c
186
187 install : $(TARGET)
188
189 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
190
191 download :$(patsubst %,$(DIR_DL)/%,$(objects))
192
193 b2 : $(subst %,%_BLAKE2,$(objects))
194
195 ###############################################################################
196 # Downloading, checking, b2sum
197 ###############################################################################
198
199 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
200 @$(CHECK)
201
202 $(patsubst %,$(DIR_DL)/%,$(objects)) :
203 @$(LOAD)
204
205 $(subst %,%_BLAKE2,$(objects)) :
206 @$(B2SUM)
207
208 ###############################################################################
209 # Installation Details
210 ###############################################################################
211
212 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
213 @$(PREBUILD)
214 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
215 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc/gcc-13.1.0-riscv_use_log2_from_cheader_without_namespace.patch
216
217 @mkdir $(DIR_SRC)/gcc-build
218
219 cd $(DIR_APP) && sed -i 's/install_to_$$(INSTALL_DEST) //' libiberty/Makefile.in
220 cd $(DIR_APP) && sed -i gcc/Makefile.in \
221 -e 's@\./fixinc\.sh@-c true@' \
222 -e 's/^T_CFLAGS =$$/& -fomit-frame-pointer/'
223
224 ifeq "$(TOOLCHAIN)" "1"
225 # Build gmp and mpfr internally in toolchain.
226 cd $(DIR_APP) && tar xfa $(DIR_DL)/gmp-$(GMP_VER).tar.xz
227 cd $(DIR_APP) && mv -v gmp-$(GMP_VER) gmp
228 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpfr-$(MPFR_VER).tar.xz
229 cd $(DIR_APP) && mv -v mpfr-$(MPFR_VER) mpfr
230 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpc-$(MPC_VER).tar.gz
231 cd $(DIR_APP) && mv -v mpc-$(MPC_VER) mpc
232
233 ifeq "$(PASS)" "2"
234 cd $(DIR_APP) && cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
235 `dirname $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name)`/include-fixed/limits.h
236 endif
237
238 for file in $$(find $(DIR_APP)/gcc/config -name linux64.h -o -name linux.h \
239 -o -name sysv4.h -o -name linux-eabi.h -o -name linux-elf.h -o -name aarch64-linux.h); do \
240 echo "Processing $${file}..."; \
241 sed -i $${file} \
242 -e 's@/lib\(64\)\?\(32\)\?/ld@$(TOOLS_DIR)&@g' \
243 -e 's@/usr@$(TOOLS_DIR)@g'; \
244 echo '#undef STANDARD_STARTFILE_PREFIX_1' >> $${file}; \
245 echo '#undef STANDARD_STARTFILE_PREFIX_2' >> $${file}; \
246 echo '#define STANDARD_STARTFILE_PREFIX_1 "$(TOOLS_DIR)/lib/"' >> $${file}; \
247 echo '#define STANDARD_STARTFILE_PREFIX_2 ""' >> $${file}; \
248 done
249 endif
250
251 ifeq "$(PASS)" "L"
252 # libstdc++ pass
253 cd $(DIR_SRC)/gcc-build && \
254 $(EXTRA_ENV) \
255 $(DIR_APP)/libstdc++-v3/configure \
256 $(EXTRA_CONFIG)
257 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
258 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
259 else
260 ifeq "$(PASS)" "A"
261 # libatomic pass
262 cd $(DIR_SRC)/gcc-build && \
263 $(EXTRA_ENV) \
264 $(DIR_APP)/libatomic/configure \
265 $(EXTRA_CONFIG)
266 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
267 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
268 else
269 # The actual build.
270 cd $(DIR_SRC)/gcc-build && \
271 $(EXTRA_ENV) \
272 $(DIR_APP)/configure \
273 $(EXTRA_CONFIG)
274 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE) $(MAKETUNING)
275 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
276 endif
277 endif
278
279 ifeq "$(TOOLCHAIN)" "1"
280 ifeq "$(PASS)" "1"
281 ln -svf libgcc.a $$($(TOOLS_DIR)/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/')
282 endif
283
284 ifeq "$(PASS)" "2"
285 ln -svf gcc $(TOOLS_DIR)/bin/cc
286 # remove gdb python files from libdir
287 rm -rf $(TOOLS_DIR)/lib/*-gdb.py
288 endif
289
290 ifeq "$(PASS)" "L"
291 # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70936
292 sed -e "s/^#include_next/#include/" -i $(TOOLS_DIR)/$(CROSSTARGET)/include/c++/$(VER)/cstdlib
293 endif
294
295 else # NON-TOOLCHAIN
296 ln -svf ../usr/bin/cpp /lib
297 ln -svf gcc /usr/bin/cc
298 # remove gdb python files from libdir
299 rm -rf /usr/lib/*-gdb.py
300 endif
301
302 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build
303 @$(POSTBUILD)