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