[toolchain] fix graphite options with gcc-4.5, add libelf for LTO, fix mbsd_multi...
[openwrt.git] / toolchain / gcc / Makefile
1 #
2 # Copyright (C) 2002-2003 Erik Andersen <andersen@uclibc.org>
3 # Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
4 # Copyright (C) 2005-2006 Felix Fietkau <nbd@openwrt.org>
5 # Copyright (C) 2006-2010 OpenWrt.org
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 include $(TOPDIR)/rules.mk
22
23 PKG_NAME:=gcc
24 GCC_VERSION:=$(call qstrip,$(CONFIG_GCC_VERSION))
25 PKG_VERSION:=$(firstword $(subst +, ,$(GCC_VERSION)))
26 GCC_DIR:=$(PKG_NAME)-$(PKG_VERSION)
27
28 ifdef CONFIG_GCC_VERSION_LLVM
29 PKG_SOURCE_VERSION:=c98c494b72ff875884c0c7286be67f16f9f6d7ab
30 PKG_REV:=83504
31 GCC_DIR:=llvm-gcc-4.2-r$(PKG_REV)
32 PKG_VERSION:=4.2.1
33 PKG_SOURCE:=$(GCC_DIR).tar.gz
34 PKG_SOURCE_PROTO:=git
35 PKG_SOURCE_URL:=git://repo.or.cz/llvm-gcc-4.2.git
36 PKG_SOURCE_SUBDIR:=$(GCC_DIR)
37 HOST_BUILD_DIR:=$(BUILD_DIR_TOOLCHAIN)/$(GCC_DIR)
38 else
39 PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
40 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
41
42 ifeq ($(PKG_VERSION),3.4.6)
43 PKG_MD5SUM:=4a21ac777d4b5617283ce488b808da7b
44 endif
45 ifeq ($(PKG_VERSION),4.1.2)
46 PKG_MD5SUM:=a4a3eb15c96030906d8494959eeda23c
47 endif
48 ifeq ($(PKG_VERSION),4.2.4)
49 PKG_MD5SUM:=d79f553e7916ea21c556329eacfeaa16
50 endif
51 ifeq ($(PKG_VERSION),4.3.3)
52 PKG_MD5SUM:=cc3c5565fdb9ab87a05ddb106ba0bd1f
53 endif
54 ifeq ($(PKG_VERSION),4.4.0)
55 PKG_MD5SUM:=cf5d787bee57f38168b74d65a7c0e6fd
56 endif
57 ifeq ($(PKG_VERSION),4,4,1)
58 PKG_MD5SUM:=927eaac3d44b22f31f9c83df82f26436
59 endif
60 ifeq ($(PKG_VERSION),4.4.2)
61 PKG_MD5SUM:=70f5ac588a79e3c9901d5b34f58d896d
62 endif
63 ifeq ($(PKG_VERSION),4.4.3)
64 PKG_MD5SUM:=fe1ca818fc6d2caeffc9051fe67ff103
65 endif
66 ifeq ($(PKG_VERSION),4.5.0)
67 PKG_MD5SUM:=ff27b7c4a5d5060c8a8543a44abca31f
68 endif
69 endif
70
71 PATCH_DIR=./patches/$(GCC_VERSION)
72
73 include $(INCLUDE_DIR)/toolchain-build.mk
74
75 HOST_STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
76
77 HOST_BUILD_DIR0:=$(HOST_BUILD_DIR)-minimal
78 HOST_BUILD_DIR1:=$(HOST_BUILD_DIR)-initial
79 HOST_BUILD_DIR2:=$(HOST_BUILD_DIR)-final
80
81 SEP:=,
82 TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
83
84 export libgcc_cv_fixed_point=no
85
86 GCC_CONFIGURE:= \
87 SHELL="$(BASH)" \
88 $(HOST_BUILD_DIR)/configure \
89 --prefix=$(TOOLCHAIN_DIR)/usr \
90 --build=$(GNU_HOST_NAME) \
91 --host=$(GNU_HOST_NAME) \
92 --target=$(REAL_GNU_TARGET_NAME) \
93 --with-gnu-ld \
94 --enable-target-optspace \
95 --disable-libgomp \
96 --disable-libmudflap \
97 --disable-multilib \
98 --disable-nls \
99 $(GRAPHITE_CONFIGURE) \
100 $(if $(CONFIG_GCC_USE_GRAPHITE),--with-host-libstdcxx=-lstdc++) \
101 $(SOFT_FLOAT_CONFIG_OPTION) \
102 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
103 $(if $(CONFIG_mips64)$(CONFIG_mips64el),--with-arch=mips64 --with-abi=64) \
104 $(if $(CONFIG_GCC_VERSION_LLVM),--enable-llvm=$(BUILD_DIR_BASE)/host/llvm) \
105 $(if $(CONFIG_GCC_VERSION_4_3_3_CS)$(CONFIG_GCC_VERSION_4_4_1_CS)$(CONFIG_GCC_VERSION_4_4_3_CS),--enable-poison-system-directories)
106
107 ifneq ($(CONFIG_GCC_VERSION_4_3)$(CONFIG_GCC_VERSION_4_4)$(CONFIG_GCC_VERSION_4_5),)
108 GCC_BUILD_TARGET_LIBGCC:=y
109 GCC_CONFIGURE+= \
110 --with-gmp=$(TOPDIR)/staging_dir/host \
111 --with-mpfr=$(TOPDIR)/staging_dir/host \
112 --disable-decimal-float
113 endif
114
115 ifneq ($(CONFIG_GCC_VERSION_4_5),)
116 GCC_BUILD_TARGET_LIBGCC:=y
117 GCC_CONFIGURE+= \
118 --with-gmp=$(TOPDIR)/staging_dir/host \
119 --with-mpc=$(TOPDIR)/staging_dir/host \
120 --with-mpfr=$(TOPDIR)/staging_dir/host \
121 --disable-decimal-float
122 endif
123
124 ifneq ($(CONFIG_SSP_SUPPORT),)
125 GCC_CONFIGURE+= \
126 --enable-libssp
127 else
128 GCC_CONFIGURE+= \
129 --disable-libssp
130 endif
131
132 ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
133 GCC_CONFIGURE+= \
134 --enable-biarch \
135 --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
136 endif
137
138 ifeq ($(LIBC),uClibc)
139 GCC_CONFIGURE+= \
140 --disable-__cxa_atexit
141 else
142 GCC_CONFIGURE+= \
143 --enable-__cxa_atexit
144 endif
145
146 GCC_CONFIGURE_STAGE0:= \
147 $(GCC_CONFIGURE) \
148 --with-newlib \
149 --without-headers \
150 --enable-languages=c \
151 --disable-libssp \
152 --disable-shared \
153 --disable-threads \
154
155 GCC_CONFIGURE_STAGE1:= \
156 $(GCC_CONFIGURE) \
157 --with-newlib \
158 --with-sysroot=$(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev \
159 --enable-languages=c \
160 --disable-shared \
161 --disable-threads \
162
163 GCC_CONFIGURE_STAGE2:= \
164 $(GCC_CONFIGURE) \
165 --enable-languages=$(TARGET_LANGUAGES) \
166 --enable-shared \
167 --enable-threads \
168 --with-slibdir=$(TOOLCHAIN_DIR)/lib
169
170 ifneq ($(CONFIG_GCC_VERSION_4_5),)
171 GCC_CONFIGURE_STAGE2+= \
172 --enable-lto \
173 --with-libelf=$(TOPDIR)/staging_dir/host
174 endif
175
176 ifneq ($(CONFIG_TLS_SUPPORT),)
177 GCC_CONFIGURE_STAGE2+= \
178 --enable-tls
179 else
180 GCC_CONFIGURE_STAGE2+= \
181 --disable-tls
182 endif
183
184 ifdef CONFIG_powerpc
185 TARGET_CFLAGS := $(patsubst -Os,-O2,$(TARGET_CFLAGS))
186 endif
187
188 GCC_MAKE:= \
189 export SHELL="$(BASH)"; \
190 $(MAKE) \
191 CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
192 CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
193
194 define Host/SetToolchainInfo
195 $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
196 $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
197 endef
198
199
200 define Stage0/Configure
201 mkdir -p $(HOST_BUILD_DIR0)
202 (cd $(HOST_BUILD_DIR0); rm -f config.cache; \
203 $(GCC_CONFIGURE_STAGE0) \
204 );
205 endef
206
207 define Stage0/Compile
208 $(GCC_MAKE) -C $(HOST_BUILD_DIR0) all-gcc
209 endef
210
211 define Stage0/Install
212 $(GCC_MAKE) -C $(HOST_BUILD_DIR0) install-gcc
213 endef
214
215
216 define Stage1/Configure
217 mkdir -p $(HOST_BUILD_DIR1)
218 (cd $(HOST_BUILD_DIR1); rm -f config.cache; \
219 $(GCC_CONFIGURE_STAGE1) \
220 );
221 endef
222
223 define Stage1/Compile
224 $(CP) $(BUILD_DIR_TOOLCHAIN)/linux-dev/* $(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev/
225 $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
226 all-build-libiberty \
227 all-gcc \
228 $(if $(GCC_BUILD_TARGET_LIBGCC),all-target-libgcc)
229 endef
230
231 define Stage1/Install
232 $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
233 install-gcc \
234 $(if $(GCC_BUILD_TARGET_LIBGCC),install-target-libgcc)
235
236 # XXX: glibc insists on linking against libgcc_eh
237 ( cd $(TOOLCHAIN_DIR)/usr/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION) ; \
238 [ -e libgcc_eh.a ] || ln -sf libgcc.a libgcc_eh.a ; \
239 cp libgcc.a libgcc_initial.a; \
240 )
241 endef
242
243
244 define Stage2/Configure
245 mkdir -p $(HOST_BUILD_DIR2) $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)
246 # Important! Required for limits.h to be fixed.
247 rm -rf $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/sys-include
248 ln -sf ../include $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/sys-include
249 rm -rf $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
250 ln -sf ../lib $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
251 $(if $(CONFIG_mips64)$(CONFIG_mips64el)$(CONFIG_x86_64),ln -sf ../lib64 $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib64)
252 (cd $(HOST_BUILD_DIR2); rm -f config.cache; \
253 $(GCC_CONFIGURE_STAGE2) \
254 );
255 endef
256
257 define Stage2/Compile
258 $(GCC_MAKE) -C $(HOST_BUILD_DIR2) all
259 endef
260
261 define SetupExtraArch
262 for app in $(TOOLCHAIN_DIR)/usr/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
263 [ -e $$$$app ] || continue; \
264 old_base=$$$$(basename $$$$app); \
265 new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
266 sed -e "s/@CC_BASE@/$$$$old_base/" \
267 -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
268 ./files/alternate-arch-cc.in > \
269 $(TOOLCHAIN_DIR)/usr/bin/$$$$new_base; \
270 chmod a+x $(TOOLCHAIN_DIR)/usr/bin/$$$$new_base; \
271 done
272 endef
273
274 define Stage2/Install
275 $(_SINGLE)$(GCC_MAKE) -C $(HOST_BUILD_DIR2) install
276 # Set up the symlinks to enable lying about target name.
277 set -e; \
278 (cd $(TOOLCHAIN_DIR)/usr; \
279 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
280 cd bin; \
281 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
282 ln -sf $$$${app} \
283 $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
284 done; \
285 );
286 $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
287 endef
288
289
290 BUGURL=https://dev.openwrt.org/
291
292 define Host/Prepare
293 $(call Host/SetToolchainInfo)
294 $(call Host/Prepare/Default)
295 ln -snf $(GCC_DIR) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
296 $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/
297 $(SED) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(HOST_BUILD_DIR)/gcc/config/*/t-*
298 $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(HOST_BUILD_DIR)/gcc/version.c
299 $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:$(BUGURL)>\2,' $(HOST_BUILD_DIR)/gcc/version.c
300 $(SED) 's,http://gcc.gnu.org/bugs.html,$(BUGURL),' $(HOST_BUILD_DIR)/gcc/configure
301 #(cd $(HOST_BUILD_DIR)/libstdc++-v3; autoconf;);
302 $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(HOST_BUILD_DIR)/libstdc++-v3/configure
303 $(call Stage0/Configure)
304 $(call Stage0/Compile)
305 $(call Stage0/Install)
306 endef
307
308 define Host/Configure
309 endef
310
311 define Host/Compile
312 $(call Stage1/Configure)
313 $(call Stage1/Compile)
314 $(call Stage1/Install)
315 endef
316
317 define Host/Install
318 $(call Stage2/Configure)
319 $(call Stage2/Compile)
320 $(call Stage2/Install)
321 endef
322
323 define Host/Clean
324 rm -rf \
325 $(HOST_BUILD_DIR) \
326 $(HOST_BUILD_DIR0) \
327 $(HOST_BUILD_DIR1) \
328 $(HOST_BUILD_DIR2) \
329 $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
330 $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME) \
331 $(TOOLCHAIN_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)-gc* \
332 $(TOOLCHAIN_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)-c*
333 endef
334
335 $(eval $(call HostBuild))
This page took 0.058729 seconds and 5 git commands to generate.