Set default gcc for ps3 - gcc-3.4.6 and gcc-4.1.2 do not work at all
[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-2008 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 PKG_VERSION:=$(call qstrip,$(CONFIG_GCC_VERSION))
25
26 PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
27 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
28
29 ifeq ($(PKG_VERSION),3.4.6)
30   PKG_MD5SUM:=4a21ac777d4b5617283ce488b808da7b
31 endif
32 ifeq ($(PKG_VERSION),4.1.2)
33   PKG_MD5SUM:=a4a3eb15c96030906d8494959eeda23c
34 endif
35 ifeq ($(PKG_VERSION),4.2.4)
36   PKG_MD5SUM:=d79f553e7916ea21c556329eacfeaa16
37 endif
38
39 PATCH_DIR=./patches/$(PKG_VERSION)
40
41 STAGING_DIR_HOST:=$(TOOLCHAIN_DIR)
42 BUILD_DIR_HOST:=$(BUILD_DIR_TOOLCHAIN)
43
44 override CONFIG_AUTOREBUILD=
45
46 include $(INCLUDE_DIR)/host-build.mk
47
48 STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
49
50 PKG_BUILD_DIR0:=$(PKG_BUILD_DIR)-minimal
51 PKG_BUILD_DIR1:=$(PKG_BUILD_DIR)-initial
52 PKG_BUILD_DIR2:=$(PKG_BUILD_DIR)-final
53
54 SEP:=,
55 TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
56
57 GCC_CONFIGURE_COMMON:= \
58         SHELL="$(BASH)" \
59         $(PKG_BUILD_DIR)/configure \
60                 --prefix=$(TOOLCHAIN_DIR)/usr \
61                 --build=$(GNU_HOST_NAME) \
62                 --host=$(GNU_HOST_NAME) \
63                 --target=$(REAL_GNU_TARGET_NAME) \
64                 --with-gnu-ld \
65                 --enable-target-optspace \
66                 --disable-libmudflap \
67                 --disable-multilib \
68                 --disable-nls \
69                 $(SOFT_FLOAT_CONFIG_OPTION) \
70                 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
71
72 ifneq ($(CONFIG_SSP_SUPPORT),)
73         GCC_CONFIGURE_COMMON+= \
74                 --enable-libssp
75 else
76         GCC_CONFIGURE_COMMON+= \
77                 --disable-libssp
78 endif
79
80 ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
81         GCC_CONFIGURE_COMMON+= \
82                 --enable-biarch \
83                 --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
84 endif
85
86 ifeq ($(LIBC),uClibc)
87         GCC_CONFIGURE_COMMON+= \
88                 --disable-__cxa_atexit
89 else
90         GCC_CONFIGURE_COMMON+= \
91                 --enable-__cxa_atexit
92 endif
93
94 GCC_CONFIGURE_STAGE0:= \
95         $(GCC_CONFIGURE_COMMON) \
96                 --with-newlib \
97                 --without-headers \
98                 --enable-languages=c \
99                 --disable-libgomp \
100                 --disable-libssp \
101                 --disable-shared \
102                 --disable-threads \
103
104 GCC_CONFIGURE_STAGE1:= \
105         $(GCC_CONFIGURE_COMMON) \
106                 --with-newlib \
107                 --with-sysroot=$(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev \
108                 --enable-languages=c \
109                 --disable-shared \
110                 --disable-threads \
111
112 GCC_CONFIGURE_STAGE2:= \
113         $(GCC_CONFIGURE_COMMON) \
114                 --enable-languages=$(TARGET_LANGUAGES) \
115                 --enable-shared \
116                 --enable-threads \
117                 --with-slibdir=$(TOOLCHAIN_DIR)/lib \
118
119 GCC_MAKE:= \
120         export SHELL="$(BASH)"; \
121         $(MAKE) \
122
123
124 define Build/SetToolchainInfo
125         $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
126         $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
127 endef
128
129
130 define Stage0/Configure
131         mkdir -p $(PKG_BUILD_DIR0)
132         (cd $(PKG_BUILD_DIR0); rm -f config.cache; \
133                 $(GCC_CONFIGURE_STAGE0) \
134         );
135 endef
136
137 define Stage0/Compile
138         $(GCC_MAKE) -C $(PKG_BUILD_DIR0) all-gcc
139 endef
140
141 define Stage0/Install
142         $(GCC_MAKE) -C $(PKG_BUILD_DIR0) install-gcc
143 endef
144
145
146 define Stage1/Configure
147         mkdir -p $(PKG_BUILD_DIR1)
148         (cd $(PKG_BUILD_DIR1); rm -f config.cache; \
149                 $(GCC_CONFIGURE_STAGE1) \
150         );
151 endef
152
153 define Stage1/Compile
154         $(GCC_MAKE) -C $(PKG_BUILD_DIR1) all-build-libiberty all-gcc
155 endef
156
157 define Stage1/Install
158         $(GCC_MAKE) -C $(PKG_BUILD_DIR1) install-gcc
159         # XXX: glibc insists on linking against libgcc_eh
160         ( cd $(TOOLCHAIN_DIR)/usr/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION) ; \
161                 [ -e libgcc_eh.a ] || ln -sf libgcc.a libgcc_eh.a ; \
162         )
163 endef
164
165
166 define Stage2/Configure
167         mkdir -p $(PKG_BUILD_DIR2) $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)
168         # Important!  Required for limits.h to be fixed.
169         rm -rf $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/sys-include
170         ln -sf ../include $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/sys-include
171         rm -rf $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
172         ln -sf ../lib $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
173         (cd $(PKG_BUILD_DIR2); rm -f config.cache; \
174                 $(GCC_CONFIGURE_STAGE2) \
175         );
176 endef
177
178 define Stage2/Compile
179         $(GCC_MAKE) -C $(PKG_BUILD_DIR2) all
180 endef
181
182 define SetupExtraArch
183         for app in $(TOOLCHAIN_DIR)/usr/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
184                 [ -e $$$$app ] || continue; \
185                 old_base=$$$$(basename $$$$app); \
186                 new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
187                 sed -e "s/@CC_BASE@/$$$$old_base/" \
188                         -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
189                          ./files/alternate-arch-cc.in > \
190                          $(TOOLCHAIN_DIR)/usr/bin/$$$$new_base; \
191                 chmod a+x $(TOOLCHAIN_DIR)/usr/bin/$$$$new_base; \
192         done
193 endef
194
195 define Stage2/Install
196         $(GCC_MAKE) -C $(PKG_BUILD_DIR2) install
197         # Set up the symlinks to enable lying about target name.
198         set -e; \
199         (cd $(TOOLCHAIN_DIR)/usr; \
200                 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
201                 cd bin; \
202                 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
203                         ln -sf $$$${app} \
204                         $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
205                 done; \
206         );
207         $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
208 endef
209
210
211 define Build/Prepare
212         $(call Build/SetToolchainInfo)
213         $(call Build/Prepare/Default)
214         ln -snf $(PKG_NAME)-$(PKG_VERSION) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
215         $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(PKG_BUILD_DIR)/
216         $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(PKG_BUILD_DIR)/gcc/version.c
217         $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:https://dev.openwrt.org/>\2,' $(PKG_BUILD_DIR)/gcc/version.c
218         (cd $(PKG_BUILD_DIR)/libstdc++-v3; autoconf;);
219         $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(PKG_BUILD_DIR)/libstdc++-v3/configure
220         $(call Stage0/Configure)
221         $(call Stage0/Compile)
222         $(call Stage0/Install)
223 endef
224
225 define Build/Configure
226 endef
227
228 define Build/Compile
229         $(call Stage1/Configure)
230         $(call Stage1/Compile)
231         $(call Stage1/Install)
232 endef
233
234 define Build/Install
235         $(call Stage2/Configure)
236         $(call Stage2/Compile)
237         $(call Stage2/Install)
238 endef
239
240 define Build/Clean
241         rm -rf \
242                 $(PKG_BUILD_DIR) \
243                 $(PKG_BUILD_DIR0) \
244                 $(PKG_BUILD_DIR1) \
245                 $(PKG_BUILD_DIR2) \
246                 $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
247                 $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME) \
248                 $(TOOLCHAIN_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)-gc* \
249                 $(TOOLCHAIN_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)-c*
250 endef
251
252 $(eval $(call HostBuild))