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