gcc: compile libgcc and libstdc++ with -O2 instead of -Os on power pc to avoid genera...
[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-2009 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 endif
64
65 PATCH_DIR=./patches/$(GCC_VERSION)
66
67 include $(INCLUDE_DIR)/toolchain-build.mk
68
69 HOST_STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
70
71 HOST_BUILD_DIR0:=$(HOST_BUILD_DIR)-minimal
72 HOST_BUILD_DIR1:=$(HOST_BUILD_DIR)-initial
73 HOST_BUILD_DIR2:=$(HOST_BUILD_DIR)-final
74
75 SEP:=,
76 TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
77
78 export libgcc_cv_fixed_point=no
79
80 GCC_CONFIGURE:= \
81         SHELL="$(BASH)" \
82         $(HOST_BUILD_DIR)/configure \
83                 --prefix=$(TOOLCHAIN_DIR)/usr \
84                 --build=$(GNU_HOST_NAME) \
85                 --host=$(GNU_HOST_NAME) \
86                 --target=$(REAL_GNU_TARGET_NAME) \
87                 --with-gnu-ld \
88                 --enable-target-optspace \
89                 --disable-libgomp \
90                 --disable-libmudflap \
91                 --disable-multilib \
92                 --disable-nls \
93                 $(SOFT_FLOAT_CONFIG_OPTION) \
94                 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
95                 $(if $(CONFIG_mips64)$(CONFIG_mips64el),--with-arch=mips64 --with-abi=64) \
96                 $(if $(CONFIG_GCC_VERSION_LLVM),--enable-llvm=$(BUILD_DIR_BASE)/host/llvm) \
97                 $(if $(CONFIG_GCC_VERSION_4_3_3_CS),--enable-poison-system-directories)
98
99 ifneq ($(CONFIG_GCC_VERSION_4_3)$(CONFIG_GCC_VERSION_4_4),)
100   GCC_BUILD_TARGET_LIBGCC:=y
101   GCC_CONFIGURE+= \
102                 --with-gmp=$(TOPDIR)/staging_dir/host \
103                 --with-mpfr=$(TOPDIR)/staging_dir/host \
104                 --disable-decimal-float
105 endif
106
107 ifneq ($(CONFIG_SSP_SUPPORT),)
108   GCC_CONFIGURE+= \
109                 --enable-libssp
110 else
111   GCC_CONFIGURE+= \
112                 --disable-libssp
113 endif
114
115 ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
116   GCC_CONFIGURE+= \
117                 --enable-biarch \
118                 --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
119 endif
120
121 ifeq ($(LIBC),uClibc)
122   GCC_CONFIGURE+= \
123                 --disable-__cxa_atexit
124 else
125   GCC_CONFIGURE+= \
126                 --enable-__cxa_atexit
127 endif
128
129 GCC_CONFIGURE_STAGE0:= \
130         $(GCC_CONFIGURE) \
131                 --with-newlib \
132                 --without-headers \
133                 --enable-languages=c \
134                 --disable-libssp \
135                 --disable-shared \
136                 --disable-threads \
137
138 GCC_CONFIGURE_STAGE1:= \
139         $(GCC_CONFIGURE) \
140                 --with-newlib \
141                 --with-sysroot=$(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev \
142                 --enable-languages=c \
143                 --disable-shared \
144                 --disable-threads \
145
146 GCC_CONFIGURE_STAGE2:= \
147         $(GCC_CONFIGURE) \
148                 --enable-languages=$(TARGET_LANGUAGES) \
149                 --enable-shared \
150                 --enable-threads \
151                 --disable-tls \
152                 --with-slibdir=$(TOOLCHAIN_DIR)/lib \
153
154 ifdef CONFIG_powerpc
155   TARGET_CFLAGS := $(patsubst -Os,-O2,$(TARGET_CFLAGS))
156 endif
157
158 GCC_MAKE:= \
159         export SHELL="$(BASH)"; \
160         $(MAKE) \
161                 CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
162                 CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
163
164 define Host/SetToolchainInfo
165         $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
166         $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
167 endef
168
169
170 define Stage0/Configure
171         mkdir -p $(HOST_BUILD_DIR0)
172         (cd $(HOST_BUILD_DIR0); rm -f config.cache; \
173                 $(GCC_CONFIGURE_STAGE0) \
174         );
175 endef
176
177 define Stage0/Compile
178         $(GCC_MAKE) -C $(HOST_BUILD_DIR0) all-gcc
179 endef
180
181 define Stage0/Install
182         $(GCC_MAKE) -C $(HOST_BUILD_DIR0) install-gcc
183 endef
184
185
186 define Stage1/Configure
187         mkdir -p $(HOST_BUILD_DIR1)
188         (cd $(HOST_BUILD_DIR1); rm -f config.cache; \
189                 $(GCC_CONFIGURE_STAGE1) \
190         );
191 endef
192
193 define Stage1/Compile
194         $(CP) $(BUILD_DIR_TOOLCHAIN)/linux-dev/* $(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev/
195         $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
196                 all-build-libiberty \
197                 all-gcc \
198                 $(if $(GCC_BUILD_TARGET_LIBGCC),all-target-libgcc)
199 endef
200
201 define Stage1/Install
202         $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
203                 install-gcc \
204                 $(if $(GCC_BUILD_TARGET_LIBGCC),install-target-libgcc)
205         
206         # XXX: glibc insists on linking against libgcc_eh
207         ( cd $(TOOLCHAIN_DIR)/usr/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION) ; \
208                 [ -e libgcc_eh.a ] || ln -sf libgcc.a libgcc_eh.a ; \
209                 cp libgcc.a libgcc_initial.a; \
210         )
211 endef
212
213
214 define Stage2/Configure
215         mkdir -p $(HOST_BUILD_DIR2) $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)
216         # Important!  Required for limits.h to be fixed.
217         rm -rf $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/sys-include
218         ln -sf ../include $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/sys-include
219         rm -rf $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
220         ln -sf ../lib $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
221         $(if $(CONFIG_mips64)$(CONFIG_mips64el)$(CONFIG_x86_64),ln -sf ../lib64 $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib64)
222         (cd $(HOST_BUILD_DIR2); rm -f config.cache; \
223                 $(GCC_CONFIGURE_STAGE2) \
224         );
225 endef
226
227 define Stage2/Compile
228         $(GCC_MAKE) -C $(HOST_BUILD_DIR2) all
229 endef
230
231 define SetupExtraArch
232         for app in $(TOOLCHAIN_DIR)/usr/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
233                 [ -e $$$$app ] || continue; \
234                 old_base=$$$$(basename $$$$app); \
235                 new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
236                 sed -e "s/@CC_BASE@/$$$$old_base/" \
237                         -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
238                          ./files/alternate-arch-cc.in > \
239                          $(TOOLCHAIN_DIR)/usr/bin/$$$$new_base; \
240                 chmod a+x $(TOOLCHAIN_DIR)/usr/bin/$$$$new_base; \
241         done
242 endef
243
244 define Stage2/Install
245         $(GCC_MAKE) -C $(HOST_BUILD_DIR2) install
246         # Set up the symlinks to enable lying about target name.
247         set -e; \
248         (cd $(TOOLCHAIN_DIR)/usr; \
249                 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
250                 cd bin; \
251                 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
252                         ln -sf $$$${app} \
253                         $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
254                 done; \
255         );
256         $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
257 endef
258
259
260 BUGURL=https://dev.openwrt.org/
261
262 define Host/Prepare
263         $(call Host/SetToolchainInfo)
264         $(call Host/Prepare/Default)
265         ln -snf $(GCC_DIR) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
266         $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/
267         $(SED) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(HOST_BUILD_DIR)/gcc/config/*/t-*
268         $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(HOST_BUILD_DIR)/gcc/version.c
269         $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:$(BUGURL)>\2,' $(HOST_BUILD_DIR)/gcc/version.c
270         $(SED) 's,http://gcc.gnu.org/bugs.html,$(BUGURL),' $(HOST_BUILD_DIR)/gcc/configure
271         #(cd $(HOST_BUILD_DIR)/libstdc++-v3; autoconf;);
272         $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(HOST_BUILD_DIR)/libstdc++-v3/configure
273         $(call Stage0/Configure)
274         $(call Stage0/Compile)
275         $(call Stage0/Install)
276 endef
277
278 define Host/Configure
279 endef
280
281 define Host/Compile
282         $(call Stage1/Configure)
283         $(call Stage1/Compile)
284         $(call Stage1/Install)
285 endef
286
287 define Host/Install
288         $(call Stage2/Configure)
289         $(call Stage2/Compile)
290         $(call Stage2/Install)
291 endef
292
293 define Host/Clean
294         rm -rf \
295                 $(HOST_BUILD_DIR) \
296                 $(HOST_BUILD_DIR0) \
297                 $(HOST_BUILD_DIR1) \
298                 $(HOST_BUILD_DIR2) \
299                 $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
300                 $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME) \
301                 $(TOOLCHAIN_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)-gc* \
302                 $(TOOLCHAIN_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)-c*
303 endef
304
305 $(eval $(call HostBuild))