modernize backfire 10.03 so it can be operational again
[openwrt-10.03/.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 PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
29 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
30
31 ifeq ($(PKG_VERSION),3.4.6)
32   PKG_MD5SUM:=4a21ac777d4b5617283ce488b808da7b
33 endif
34 ifeq ($(PKG_VERSION),4.1.2)
35   PKG_MD5SUM:=a4a3eb15c96030906d8494959eeda23c
36 endif
37 ifeq ($(PKG_VERSION),4.2.4)
38   PKG_MD5SUM:=d79f553e7916ea21c556329eacfeaa16
39 endif
40 ifeq ($(PKG_VERSION),4.3.3)
41   PKG_MD5SUM:=cc3c5565fdb9ab87a05ddb106ba0bd1f
42 endif
43 ifeq ($(PKG_VERSION),4.3.4)
44   PKG_MD5SUM:=60df63222dbffd53ca11492a2545044f
45 endif
46 ifeq ($(PKG_VERSION),4,4,1)
47   PKG_MD5SUM:=927eaac3d44b22f31f9c83df82f26436
48 endif
49 ifeq ($(PKG_VERSION),4.4.2)
50   PKG_MD5SUM:=70f5ac588a79e3c9901d5b34f58d896d
51 endif
52 ifeq ($(PKG_VERSION),4.4.3)
53   PKG_MD5SUM:=fe1ca818fc6d2caeffc9051fe67ff103
54 endif
55
56 PATCH_DIR=./patches/$(GCC_VERSION)
57
58 include $(INCLUDE_DIR)/toolchain-build.mk
59
60 HOST_STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
61
62 HOST_BUILD_DIR0:=$(HOST_BUILD_DIR)-minimal
63 HOST_BUILD_DIR1:=$(HOST_BUILD_DIR)-initial
64 HOST_BUILD_DIR2:=$(HOST_BUILD_DIR)-final
65
66 SEP:=,
67 TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
68
69 export libgcc_cv_fixed_point=no
70
71 GCC_CONFIGURE:= \
72         SHELL="$(BASH)" \
73         $(HOST_BUILD_DIR)/configure \
74                 --prefix=$(TOOLCHAIN_DIR) \
75                 --build=$(GNU_HOST_NAME) \
76                 --host=$(GNU_HOST_NAME) \
77                 --target=$(REAL_GNU_TARGET_NAME) \
78                 --with-gnu-ld \
79                 --disable-subdir-texinfo \
80                 MAKEINFO=missing \
81                 --enable-target-optspace \
82                 --disable-libgomp \
83                 --disable-libmudflap \
84                 --disable-multilib \
85                 --disable-nls \
86                 $(if $(CONFIG_GCC_USE_GRAPHITE),--with-host-libstdcxx=-lstdc++) \
87                 $(SOFT_FLOAT_CONFIG_OPTION) \
88                 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
89                 $(if $(CONFIG_GCC_VERSION_4_3_3_CS),--enable-poison-system-directories)
90
91 ifneq ($(CONFIG_GCC_VERSION_4_3)$(CONFIG_GCC_VERSION_4_4),)
92   GCC_BUILD_TARGET_LIBGCC:=y
93   GCC_CONFIGURE+= \
94                 --with-gmp=$(TOPDIR)/staging_dir/host \
95                 --with-mpfr=$(TOPDIR)/staging_dir/host \
96                 --disable-decimal-float
97 endif
98
99 ifneq ($(CONFIG_SSP_SUPPORT),)
100   GCC_CONFIGURE+= \
101                 --enable-libssp
102 else
103   GCC_CONFIGURE+= \
104                 --disable-libssp
105 endif
106
107 ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
108   GCC_CONFIGURE+= \
109                 --enable-biarch \
110                 --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
111 endif
112
113 ifeq ($(LIBC),uClibc)
114   GCC_CONFIGURE+= \
115                 --disable-__cxa_atexit
116 else
117   GCC_CONFIGURE+= \
118                 --enable-__cxa_atexit
119 endif
120
121 GCC_CONFIGURE_STAGE0:= \
122         $(GCC_CONFIGURE) \
123                 --with-newlib \
124                 --without-headers \
125                 --enable-languages=c \
126                 --disable-libssp \
127                 --disable-shared \
128                 --disable-threads \
129
130 GCC_CONFIGURE_STAGE1:= \
131         $(GCC_CONFIGURE) \
132                 --with-newlib \
133                 --with-sysroot=$(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev \
134                 --enable-languages=c \
135                 --disable-shared \
136                 --disable-threads \
137
138 GCC_CONFIGURE_STAGE2:= \
139         $(GCC_CONFIGURE) \
140                 --enable-languages=$(TARGET_LANGUAGES) \
141                 --enable-shared \
142                 --enable-threads \
143                 --with-slibdir=$(TOOLCHAIN_DIR)/lib \
144
145 ifneq ($(CONFIG_TLS_SUPPORT),)
146   GCC_CONFIGURE_STAGE2+= \
147                 --enable-tls
148 else
149   GCC_CONFIGURE_STAGE2+= \
150                 --disable-tls
151 endif
152
153 ifdef CONFIG_powerpc
154   TARGET_CFLAGS := $(patsubst -Os,-O2,$(TARGET_CFLAGS))
155 endif
156
157 GCC_MAKE:= \
158         export SHELL="$(BASH)"; \
159         $(MAKE) \
160                 CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
161                 CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
162
163 define Host/SetToolchainInfo
164         $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
165         $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
166 endef
167
168
169 define Stage0/Configure
170         mkdir -p $(HOST_BUILD_DIR0)
171         (cd $(HOST_BUILD_DIR0); rm -f config.cache; \
172                 $(GCC_CONFIGURE_STAGE0) \
173         );
174 endef
175
176 define Stage0/Compile
177         $(GCC_MAKE) -C $(HOST_BUILD_DIR0) all-gcc
178 endef
179
180 define Stage0/Install
181         $(GCC_MAKE) -C $(HOST_BUILD_DIR0) install-gcc
182 endef
183
184
185 define Stage1/Configure
186         mkdir -p $(HOST_BUILD_DIR1)
187         (cd $(HOST_BUILD_DIR1); rm -f config.cache; \
188                 $(GCC_CONFIGURE_STAGE1) \
189         );
190 endef
191
192 define Stage1/Compile
193         $(CP) $(BUILD_DIR_TOOLCHAIN)/linux-dev/* $(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev/
194         $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
195                 all-build-libiberty \
196                 all-gcc \
197                 $(if $(GCC_BUILD_TARGET_LIBGCC),all-target-libgcc)
198 endef
199
200 define Stage1/Install
201         $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
202                 install-gcc \
203                 $(if $(GCC_BUILD_TARGET_LIBGCC),install-target-libgcc)
204         
205         # XXX: glibc insists on linking against libgcc_eh
206         ( cd $(TOOLCHAIN_DIR)/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION) ; \
207                 [ -e libgcc_eh.a ] || ln -sf libgcc.a libgcc_eh.a ; \
208                 cp libgcc.a libgcc_initial.a; \
209         )
210 endef
211
212
213 define Stage2/Configure
214         mkdir -p $(HOST_BUILD_DIR2) $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)
215         # Important!  Required for limits.h to be fixed.
216         rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
217         ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
218         rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
219         ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
220         $(if $(CONFIG_mips64)$(CONFIG_mips64el)$(CONFIG_x86_64),ln -sf ../lib64 $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib64)
221         (cd $(HOST_BUILD_DIR2); rm -f config.cache; \
222                 $(GCC_CONFIGURE_STAGE2) \
223         );
224 endef
225
226 define Stage2/Compile
227         $(GCC_MAKE) -C $(HOST_BUILD_DIR2) all
228 endef
229
230 define SetupExtraArch
231         for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
232                 [ -e $$$$app ] || continue; \
233                 old_base=$$$$(basename $$$$app); \
234                 new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
235                 sed -e "s/@CC_BASE@/$$$$old_base/" \
236                         -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
237                          ./files/alternate-arch-cc.in > \
238                          $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
239                 chmod a+x $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
240         done
241 endef
242
243 define Stage2/Install
244         $(_SINGLE)$(GCC_MAKE) -C $(HOST_BUILD_DIR2) install
245         # Set up the symlinks to enable lying about target name.
246         set -e; \
247         (cd $(TOOLCHAIN_DIR); \
248                 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
249                 cd bin; \
250                 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
251                         ln -sf $$$${app} \
252                         $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
253                 done; \
254         );
255         $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
256         $(SCRIPT_DIR)/patch-specs.sh "$(TOOLCHAIN_DIR)"
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)/$(REAL_GNU_TARGET_NAME) \
301                 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
302                 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
303 endef
304
305 $(eval $(call HostBuild))