toolchain: fix full toolchain crossbuild
[ipfire-2.x.git] / lfs / gcc
CommitLineData
cd1a2927 1###############################################################################
cd1a2927 2# #
70df8302 3# IPFire.org - A linux based firewall #
3f8c9dc5 4# Copyright (C) 2007-2011 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
8675b78a 27VER = 4.9.3
82b312a9
MT
28
29GMP_VER = 5.0.5
30MPFR_VER = 2.4.2
8675b78a 31MPC_VER = 1.0.3
cd1a2927
MT
32
33THISAPP = gcc-$(VER)
8675b78a 34DL_FILE = $(THISAPP).tar.gz
dd714b8a 35DL_FROM = $(URL_IPFIRE)
cd1a2927 36DIR_APP = $(DIR_SRC)/$(THISAPP)
cd1a2927 37
ed635824
MT
38CFLAGS := $(patsubst -march=%,,$(CFLAGS))
39CFLAGS := $(patsubst -mtune=%,,$(CFLAGS))
62a430f9 40CFLAGS := $(patsubst -mfloat-abi=%,,$(CFLAGS))
8675b78a
MT
41CFLAGS := $(filter-out -fexceptions,$(CFLAGS))
42CXXFLAGS := $(CFLAGS)
ff1d5f3a 43
cd1a2927
MT
44# Normal build or /tools build.
45#
46ifeq "$(ROOT)" ""
47 TARGET = $(DIR_INFO)/$(THISAPP)
afbd9856
MT
48 EXTRA_CONFIG = \
49 --prefix=/usr \
50 --libexecdir=/usr/lib \
51 --enable-shared \
52 --enable-threads=posix \
53 --enable-__cxa_atexit \
54 --enable-clocale=gnu \
55 --enable-languages=c,c++ \
56 --disable-bootstrap \
57 --disable-nls
857d9bf2
MT
58 EXTRA_MAKE =
59 EXTRA_INSTALL =
cd1a2927 60else
15679d9f 61ifeq "$(PASS)" "1"
cd1a2927 62 TARGET = $(DIR_INFO)/$(THISAPP)-tools1
82b312a9
MT
63 EXTRA_CONFIG = \
64 --target=$(CROSSTARGET) \
65 --prefix=/tools \
764a3f1f 66 --with-sysroot=$(ROOT) \
82b312a9
MT
67 --disable-nls \
68 --disable-shared \
69 --disable-decimal-float \
70 --disable-threads \
764a3f1f 71 --disable-libatomic \
82b312a9
MT
72 --disable-libmudflap \
73 --disable-libssp \
74 --disable-libgomp \
75 --disable-libquadmath \
764a3f1f
AF
76 --disable-libstdc++-v3 \
77 --disable-libvtv \
78 --disable-libcilkrts \
79 --disable-libitm \
80 --disable-libsanitizer \
82b312a9
MT
81 --with-newlib \
82 --without-headers \
83 --without-ppl \
84 --without-cloog \
764a3f1f 85 --enable-languages=c,c++
575ea031 86 EXTRA_MAKE =
cd1a2927
MT
87 EXTRA_INSTALL =
88else
764a3f1f 89ifeq "$(PASS)" "2"
cd1a2927 90 TARGET = $(DIR_INFO)/$(THISAPP)-tools2
82b312a9
MT
91 EXTRA_ENV = \
92 CC="$(CROSSTARGET)-gcc -B/tools/lib/" \
764a3f1f 93 CXX="$(CROSSTARGET)-g++" \
82b312a9
MT
94 AR="$(CROSSTARGET)-ar" \
95 RANLIB="$(CROSSTARGET)-ranlib"
96 EXTRA_CONFIG = \
97 --host=$(BUILDTARGET) \
98 --build=$(BUILDTARGET) \
99 --target=$(BUILDTARGET) \
100 --prefix=/tools \
101 --with-local-prefix=/tools \
764a3f1f 102 --with-native-system-header-dir=/tools/include \
82b312a9
MT
103 --enable-clocale=gnu \
104 --enable-shared \
105 --enable-threads=posix \
106 --enable-__cxa_atexit \
107 --enable-languages=c,c++ \
108 --disable-libstdcxx-pch \
109 --disable-bootstrap
cd1a2927
MT
110 EXTRA_MAKE =
111 EXTRA_INSTALL =
764a3f1f
AF
112else
113 # PASS=L # libstdc++-v3
114 TARGET = $(DIR_INFO)/$(THISAPP)-libstdc++
115 EXTRA_ENV = \
116 CC="$(CROSSTARGET)-gcc -B/tools/lib/" \
117 AR="$(CROSSTARGET)-ar" \
118 RANLIB="$(CROSSTARGET)-ranlib"
119 EXTRA_CONFIG = \
120 --host=$(CROSSTARGET) \
121 --prefix=/tools \
122 --with-sysroot=$(ROOT) \
123 --disable-shared \
124 --disable-nls \
125 --disable-libstdcxx-threads \
126 --disable-libstdcxx-pch \
127 --with-gxx-include-dir=/tools/$(CROSSTARGET)/include/c++/$(VER)
128 EXTRA_MAKE =
129 EXTRA_INSTALL =
130endif
cd1a2927 131endif
3a317084
AF
132
133 # Disable stack protection in toolchain.
134 CFLAGS += -fno-stack-protector
cd1a2927
MT
135endif
136
cc72d5cb 137ifeq "$(MACHINE_TYPE)" "arm"
51f9e7ac 138 EXTRA_CONFIG += \
afbd9856
MT
139 --with-float=soft \
140 --disable-sjlj-exceptions
51f9e7ac
MT
141endif
142
ed635824
MT
143ifeq "$(MACHINE)" "i586"
144 EXTRA_CONFIG += \
145 --with-arch=i586 \
146 --with-tune=generic
147endif
148
81aa9714
MT
149ifeq "$(MACHINE)" "x86_64"
150 EXTRA_CONFIG += \
151 --disable-multilib
152endif
153
ed635824
MT
154EXTRA_CONFIG += \
155 --with-bugurl=http://bugtracker.ipfire.org \
156 --disable-libunwind-exceptions \
157 --enable-gnu-unique-object
158
51f9e7ac
MT
159export XCFLAGS = $(CFLAGS)
160export TCFLAGS = $(CFLAGS)
161
cd1a2927
MT
162###############################################################################
163# Top-level Rules
164###############################################################################
82b312a9
MT
165
166objects = $(DL_FILE) \
167 gmp-$(GMP_VER).tar.bz2 \
8675b78a
MT
168 mpfr-$(MPFR_VER).tar.bz2 \
169 mpc-$(MPC_VER).tar.gz
cd1a2927 170
41921bd9 171$(DL_FILE) = $(DL_FROM)/$(DL_FILE)
82b312a9
MT
172gmp-$(GMP_VER).tar.bz2 = $(DL_FROM)/gmp-$(GMP_VER).tar.bz2
173mpfr-$(MPFR_VER).tar.bz2 = $(DL_FROM)/mpfr-$(MPFR_VER).tar.bz2
8675b78a 174mpc-$(MPC_VER).tar.gz = $(DL_FROM)/mpc-$(MPC_VER).tar.gz
cd1a2927 175
8675b78a 176$(DL_FILE)_MD5 = 648bfba342bb41a4b5350fb685f85bc5
82b312a9
MT
177gmp-$(GMP_VER).tar.bz2_MD5 = 041487d25e9c230b0c42b106361055fe
178mpfr-$(MPFR_VER).tar.bz2_MD5 = 89e59fe665e2b3ad44a6789f40b059a0
8675b78a 179mpc-$(MPC_VER).tar.gz_MD5 = d6a1d5f8ddea3abd2cc3e98f58352d26
cd1a2927
MT
180
181install : $(TARGET)
182
183check : $(patsubst %,$(DIR_CHK)/%,$(objects))
184
185download :$(patsubst %,$(DIR_DL)/%,$(objects))
186
187md5 : $(subst %,%_MD5,$(objects))
188
189###############################################################################
190# Downloading, checking, md5sum
191###############################################################################
192
193$(patsubst %,$(DIR_CHK)/%,$(objects)) :
194 @$(CHECK)
195
196$(patsubst %,$(DIR_DL)/%,$(objects)) :
197 @$(LOAD)
198
199$(subst %,%_MD5,$(objects)) :
200 @$(MD5)
201
202###############################################################################
203# Installation Details
204###############################################################################
205
206$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
207 @$(PREBUILD)
8675b78a 208 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
dd714b8a 209 @mkdir $(DIR_SRC)/gcc-build
51f9e7ac 210
ed635824 211 # Apply patches.
8675b78a
MT
212 cd $(DIR_APP) && patch -Np0 < $(DIR_SRC)/src/patches/gcc/gcc49-i386-libgomp.patch
213 cd $(DIR_APP) && patch -Np0 < $(DIR_SRC)/src/patches/gcc/gcc49-libtool-no-rpath.patch
214 cd $(DIR_APP) && patch -Np0 < $(DIR_SRC)/src/patches/gcc/gcc49-no-add-needed.patch
215 cd $(DIR_APP) && patch -Np0 < $(DIR_SRC)/src/patches/gcc/gcc49-pr38757.patch
216 cd $(DIR_APP) && patch -Np0 < $(DIR_SRC)/src/patches/gcc/gcc49-pr64336.patch
217 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc/gcc-fix-inlining-issues.patch
defd8d00 218
82b312a9
MT
219ifneq "$(ROOT)" ""
220 # Build gmp and mpfr internally in toolchain.
221 cd $(DIR_APP) && tar xfa $(DIR_DL)/gmp-$(GMP_VER).tar.bz2
222 cd $(DIR_APP) && mv -v gmp-$(GMP_VER) gmp
223 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpfr-$(MPFR_VER).tar.bz2
224 cd $(DIR_APP) && mv -v mpfr-$(MPFR_VER) mpfr
8675b78a
MT
225 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpc-$(MPC_VER).tar.gz
226 cd $(DIR_APP) && mv -v mpc-$(MPC_VER) mpc
82b312a9
MT
227
228ifeq "$(PASS)" "1"
229 # GCC does not detect stack protection correctly, which causes problems
230 # for the build of libresolv_pic.a.
231 cd $(DIR_APP) && sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
764a3f1f
AF
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); do \
235 echo "Processing $${file}..."; \
236 sed -i $${file} \
237 -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
238 -e 's@/usr@/tools@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/lib/"' >> $${file}; \
242 echo '#define STANDARD_STARTFILE_PREFIX_2 ""' >> $${file}; \
243 done
82b312a9 244endif
51f9e7ac 245
82b312a9 246ifeq "$(PASS)" "2"
764a3f1f
AF
247 cd $(DIR_APP) && cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
248 `dirname $$(/tools/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name)`/include-fixed/limits.h
82b312a9
MT
249 for file in $$(find $(DIR_APP)/gcc/config -name linux64.h -o -name linux.h \
250 -o -name sysv4.h -o -name linux-eabi.h -o -name linux-elf.h); do \
251 echo "Processing $${file}..."; \
252 sed -i $${file} \
253 -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
254 -e 's@/usr@/tools@g'; \
764a3f1f
AF
255 echo '#undef STANDARD_STARTFILE_PREFIX_1' >> $${file}; \
256 echo '#undef STANDARD_STARTFILE_PREFIX_2' >> $${file}; \
257 echo '#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"' >> $${file}; \
82b312a9
MT
258 echo '#define STANDARD_STARTFILE_PREFIX_2 ""' >> $${file}; \
259 done
260endif
261endif
dd714b8a 262
afbd9856
MT
263 cd $(DIR_APP) && sed -i 's/install_to_$$(INSTALL_DEST) //' libiberty/Makefile.in
264 cd $(DIR_APP) && sed -i gcc/Makefile.in \
265 -e 's@\./fixinc\.sh@-c true@' \
266 -e 's/^T_CFLAGS =$$/& -fomit-frame-pointer/'
267
764a3f1f
AF
268ifeq "$(PASS)" "L"
269 # libstdc++ pass
270 cd $(DIR_SRC)/gcc-build && \
271 $(EXTRA_ENV) \
272 $(DIR_APP)/libstdc++-v3/configure \
273 $(EXTRA_CONFIG)
274 cd $(DIR_SRC)/gcc-build && make $(MAKETUNING) $(EXTRA_MAKE)
275 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
276else
82b312a9
MT
277 # The actual build.
278 cd $(DIR_SRC)/gcc-build && \
279 $(EXTRA_ENV) \
280 $(DIR_APP)/configure \
281 $(EXTRA_CONFIG)
f97be0a6
MT
282 cd $(DIR_SRC)/gcc-build && make $(MAKETUNING) $(EXTRA_MAKE)
283 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
764a3f1f 284endif
82b312a9 285
afbd9856
MT
286ifeq "$(ROOT)" ""
287 ln -svf ../usr/bin/cpp /lib
6753fbe0 288 ln -svf gcc /usr/bin/cc
afbd9856 289else
82b312a9
MT
290ifeq "$(PASS)" "1"
291 ln -svf libgcc.a $$(/tools/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/')
cd1a2927 292else
82b312a9 293 ln -svf gcc /tools/bin/cc
cd1a2927 294endif
cd1a2927
MT
295endif
296 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build
297 @$(POSTBUILD)