]> git.ipfire.org Git - ipfire-2.x.git/blob - lfs/gcc
make.sh: Cleanup of polluted environment
[ipfire-2.x.git] / lfs / gcc
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2016 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 = 6.3.0
28
29 GMP_VER = 5.0.5
30 MPFR_VER = 2.4.2
31 MPC_VER = 1.0.3
32
33 THISAPP = gcc-$(VER)
34 DL_FILE = $(THISAPP).tar.gz
35 DL_FROM = $(URL_IPFIRE)
36 DIR_APP = $(DIR_SRC)/$(THISAPP)
37
38 CFLAGS := $(patsubst -march=%,,$(CFLAGS))
39 CFLAGS := $(patsubst -mtune=%,,$(CFLAGS))
40 CFLAGS := $(patsubst -mfloat-abi=%,,$(CFLAGS))
41 CFLAGS := $(filter-out -fexceptions,$(CFLAGS))
42 CXXFLAGS := $(CFLAGS)
43
44 # Normal build or /tools build.
45 #
46 ifeq "$(ROOT)" ""
47 TARGET = $(DIR_INFO)/$(THISAPP)
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
58 EXTRA_MAKE =
59 EXTRA_INSTALL =
60 else
61 ifeq "$(PASS)" "1"
62 TARGET = $(DIR_INFO)/$(THISAPP)-tools1
63 EXTRA_CONFIG = \
64 --target=$(CROSSTARGET) \
65 --prefix=/tools \
66 --with-sysroot=$(ROOT) \
67 --with-local-prefix=/tools \
68 --with-native-system-header-dir=/tools/include \
69 --disable-nls \
70 --disable-shared \
71 --disable-decimal-float \
72 --disable-threads \
73 --disable-libatomic \
74 --disable-libmudflap \
75 --disable-libssp \
76 --disable-libgomp \
77 --disable-libquadmath \
78 --disable-libstdc++-v3 \
79 --disable-libvtv \
80 --disable-libcilkrts \
81 --disable-libitm \
82 --disable-libsanitizer \
83 --with-newlib \
84 --without-headers \
85 --without-ppl \
86 --without-cloog \
87 --enable-languages=c,c++
88 EXTRA_MAKE =
89 EXTRA_INSTALL =
90 else
91 ifeq "$(PASS)" "2"
92 TARGET = $(DIR_INFO)/$(THISAPP)-tools2
93 EXTRA_ENV = \
94 CC="$(CROSSTARGET)-gcc" \
95 CXX="$(CROSSTARGET)-g++" \
96 AR="$(CROSSTARGET)-ar" \
97 RANLIB="$(CROSSTARGET)-ranlib"
98 EXTRA_CONFIG = \
99 --host=$(BUILDTARGET) \
100 --build=$(BUILDTARGET) \
101 --target=$(BUILDTARGET) \
102 --prefix=/tools \
103 --with-local-prefix=/tools \
104 --with-native-system-header-dir=/tools/include \
105 --enable-clocale=gnu \
106 --enable-shared \
107 --enable-threads=posix \
108 --enable-__cxa_atexit \
109 --enable-languages=c,c++ \
110 --disable-libstdcxx-pch \
111 --disable-bootstrap
112 EXTRA_MAKE =
113 EXTRA_INSTALL =
114 else
115 # PASS=L # libstdc++-v3
116 TARGET = $(DIR_INFO)/$(THISAPP)-libstdc++
117 EXTRA_ENV = \
118 CC="$(CROSSTARGET)-gcc" \
119 AR="$(CROSSTARGET)-ar" \
120 RANLIB="$(CROSSTARGET)-ranlib"
121 EXTRA_CONFIG = \
122 --host=$(CROSSTARGET) \
123 --prefix=/tools \
124 --with-sysroot=$(ROOT) \
125 --disable-shared \
126 --disable-nls \
127 --disable-libstdcxx-threads \
128 --disable-libstdcxx-pch \
129 --with-gxx-include-dir=/tools/$(CROSSTARGET)/include/c++/$(VER)
130 EXTRA_MAKE =
131 EXTRA_INSTALL =
132 endif
133 endif
134 endif
135
136 ifeq "$(BUILD_ARCH)" "armv7hl"
137 EXTRA_CONFIG += \
138 --with-float=hard
139 endif
140
141 ifeq "$(BUILD_ARCH)" "armv5tel"
142 EXTRA_CONFIG += \
143 --with-float=soft \
144 --disable-sjlj-exceptions
145 endif
146
147 ifeq "$(BUILD_ARCH)" "i586"
148 EXTRA_CONFIG += \
149 --with-arch=i586 \
150 --with-tune=generic
151 endif
152
153 ifeq "$(BUILD_ARCH)" "x86_64"
154 EXTRA_CONFIG += \
155 --disable-multilib
156 endif
157
158 EXTRA_CONFIG += \
159 --with-bugurl=http://bugtracker.ipfire.org \
160 --disable-libunwind-exceptions \
161 --enable-gnu-unique-object
162
163 export XCFLAGS = $(CFLAGS)
164 export TCFLAGS = $(CFLAGS)
165
166 ###############################################################################
167 # Top-level Rules
168 ###############################################################################
169
170 objects = $(DL_FILE) \
171 gmp-$(GMP_VER).tar.bz2 \
172 mpfr-$(MPFR_VER).tar.bz2 \
173 mpc-$(MPC_VER).tar.gz
174
175 $(DL_FILE) = $(DL_FROM)/$(DL_FILE)
176 gmp-$(GMP_VER).tar.bz2 = $(DL_FROM)/gmp-$(GMP_VER).tar.bz2
177 mpfr-$(MPFR_VER).tar.bz2 = $(DL_FROM)/mpfr-$(MPFR_VER).tar.bz2
178 mpc-$(MPC_VER).tar.gz = $(DL_FROM)/mpc-$(MPC_VER).tar.gz
179
180 $(DL_FILE)_MD5 = 6e5ea04789678f1250c1b30c4d9ec417
181 gmp-$(GMP_VER).tar.bz2_MD5 = 041487d25e9c230b0c42b106361055fe
182 mpfr-$(MPFR_VER).tar.bz2_MD5 = 89e59fe665e2b3ad44a6789f40b059a0
183 mpc-$(MPC_VER).tar.gz_MD5 = d6a1d5f8ddea3abd2cc3e98f58352d26
184
185 install : $(TARGET)
186
187 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
188
189 download :$(patsubst %,$(DIR_DL)/%,$(objects))
190
191 md5 : $(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)
212 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
213 @mkdir $(DIR_SRC)/gcc-build
214
215 cd $(DIR_APP) && sed -i 's/install_to_$$(INSTALL_DEST) //' libiberty/Makefile.in
216 cd $(DIR_APP) && sed -i gcc/Makefile.in \
217 -e 's@\./fixinc\.sh@-c true@' \
218 -e 's/^T_CFLAGS =$$/& -fomit-frame-pointer/'
219
220 ifeq "$(TOOLCHAIN)" "1"
221 # Build gmp and mpfr internally in toolchain.
222 cd $(DIR_APP) && tar xfa $(DIR_DL)/gmp-$(GMP_VER).tar.bz2
223 cd $(DIR_APP) && mv -v gmp-$(GMP_VER) gmp
224 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpfr-$(MPFR_VER).tar.bz2
225 cd $(DIR_APP) && mv -v mpfr-$(MPFR_VER) mpfr
226 cd $(DIR_APP) && tar xfa $(DIR_DL)/mpc-$(MPC_VER).tar.gz
227 cd $(DIR_APP) && mv -v mpc-$(MPC_VER) mpc
228
229 ifeq "$(PASS)" "2"
230 cd $(DIR_APP) && cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
231 `dirname $$(/tools/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name)`/include-fixed/limits.h
232 endif
233
234 for file in $$(find $(DIR_APP)/gcc/config -name linux64.h -o -name linux.h \
235 -o -name sysv4.h -o -name linux-eabi.h -o -name linux-elf.h -o -name aarch64-linux.h); do \
236 echo "Processing $${file}..."; \
237 sed -i $${file} \
238 -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
239 -e 's@/usr@/tools@g'; \
240 echo '#undef STANDARD_STARTFILE_PREFIX_1' >> $${file}; \
241 echo '#undef STANDARD_STARTFILE_PREFIX_2' >> $${file}; \
242 echo '#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"' >> $${file}; \
243 echo '#define STANDARD_STARTFILE_PREFIX_2 ""' >> $${file}; \
244 done
245 endif
246
247 ifeq "$(PASS)" "L"
248 # libstdc++ pass
249 cd $(DIR_SRC)/gcc-build && \
250 $(EXTRA_ENV) \
251 $(DIR_APP)/libstdc++-v3/configure \
252 $(EXTRA_CONFIG)
253 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
254 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
255
256 else
257 # The actual build.
258 cd $(DIR_SRC)/gcc-build && \
259 $(EXTRA_ENV) \
260 $(DIR_APP)/configure \
261 $(EXTRA_CONFIG)
262 cd $(DIR_SRC)/gcc-build && make $(EXTRA_MAKE)
263 cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
264 endif
265
266 ifeq "$(TOOLCHAIN)" "1"
267 ifeq "$(PASS)" "1"
268 ln -svf libgcc.a $$(/tools/bin/$(CROSSTARGET)-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/')
269 endif
270
271 ifeq "$(PASS)" "2"
272 ln -svf gcc /tools/bin/cc
273 # remove gdb python files from libdir
274 rm -rf /tools/lib/*-gdb.py
275 endif
276
277 ifeq "$(PASS)" "L"
278 # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70936
279 sed -e "s/^#include_next/#include/" -i /tools/$(CROSSTARGET)/include/c++/$(VER)/cstdlib
280 endif
281
282 else # NON-TOOLCHAIN
283 ln -svf ../usr/bin/cpp /lib
284 ln -svf gcc /usr/bin/cc
285 # remove gdb python files from libdir
286 rm -rf /usr/lib/*-gdb.py
287 endif
288
289 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build
290 @$(POSTBUILD)