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