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
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.
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.
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
21 include $(TOPDIR
)/rules.mk
24 GCC_VERSION
:=$(call qstrip
,$(CONFIG_GCC_VERSION
))
25 PKG_VERSION
:=$(firstword $(subst +, ,$(GCC_VERSION
)))
26 GCC_DIR
:=$(PKG_NAME
)-$(PKG_VERSION
)
28 ifdef CONFIG_GCC_VERSION_LLVM
29 PKG_SOURCE_VERSION
:=c98c494b72ff875884c0c7286be67f16f9f6d7ab
31 GCC_DIR
:=llvm-gcc-4.2
-r
$(PKG_REV
)
33 PKG_SOURCE
:=$(GCC_DIR
).
tar.gz
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
)
39 PKG_SOURCE_URL
:=@GNU
/gcc
/gcc-
$(PKG_VERSION
)
40 PKG_SOURCE
:=$(PKG_NAME
)-$(PKG_VERSION
).
tar.bz2
42 ifeq ($(PKG_VERSION
),3.4.6)
43 PKG_MD5SUM
:=4a21ac777d4b5617283ce488b808da7b
45 ifeq ($(PKG_VERSION
),4.1.2)
46 PKG_MD5SUM
:=a4a3eb15c96030906d8494959eeda23c
48 ifeq ($(PKG_VERSION
),4.2.4)
49 PKG_MD5SUM
:=d79f553e7916ea21c556329eacfeaa16
51 ifeq ($(PKG_VERSION
),4.3.3)
52 PKG_MD5SUM
:=cc3c5565fdb9ab87a05ddb106ba0bd1f
54 ifeq ($(PKG_VERSION
),4.4.0)
55 PKG_MD5SUM
:=cf5d787bee57f38168b74d65a7c0e6fd
57 ifeq ($(PKG_VERSION
),4,4,1)
58 PKG_MD5SUM
:=927eaac3d44b22f31f9c83df82f26436
60 ifeq ($(PKG_VERSION
),4.4.2)
61 PKG_MD5SUM
:=70f5ac588a79e3c9901d5b34f58d896d
63 ifeq ($(PKG_VERSION
),4.4.3)
64 PKG_MD5SUM
:=fe1ca818fc6d2caeffc9051fe67ff103
68 PATCH_DIR
=.
/patches
/$(GCC_VERSION
)
70 include $(INCLUDE_DIR
)/toolchain-build.mk
72 HOST_STAMP_BUILT
:=$(TOOLCHAIN_DIR
)/stamp
/.gcc-initial_installed
74 HOST_BUILD_DIR0
:=$(HOST_BUILD_DIR
)-minimal
75 HOST_BUILD_DIR1
:=$(HOST_BUILD_DIR
)-initial
76 HOST_BUILD_DIR2
:=$(HOST_BUILD_DIR
)-final
79 TARGET_LANGUAGES
:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
81 export libgcc_cv_fixed_point
=no
85 $(HOST_BUILD_DIR
)/configure \
86 --prefix=$(TOOLCHAIN_DIR
)/usr \
87 --build
=$(GNU_HOST_NAME
) \
88 --host
=$(GNU_HOST_NAME
) \
89 --target
=$(REAL_GNU_TARGET_NAME
) \
91 --enable-target-optspace \
93 --disable-libmudflap \
96 $(if
$(CONFIG_GCC_USE_GRAPHITE
),--with-host-libstdcxx
=-lstdc
++) \
97 $(SOFT_FLOAT_CONFIG_OPTION
) \
98 $(call qstrip
,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS
)) \
99 $(if
$(CONFIG_mips64
)$(CONFIG_mips64el
),--with-arch
=mips64
--with-abi
=64) \
100 $(if
$(CONFIG_GCC_VERSION_LLVM
),--enable-llvm
=$(BUILD_DIR_BASE
)/host
/llvm
) \
101 $(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
)
103 ifneq ($(CONFIG_GCC_VERSION_4_3
)$(CONFIG_GCC_VERSION_4_4
),)
104 GCC_BUILD_TARGET_LIBGCC
:=y
106 --with-gmp
=$(TOPDIR
)/staging_dir
/host \
107 --with-mpfr
=$(TOPDIR
)/staging_dir
/host \
108 --disable-decimal-float
111 ifneq ($(CONFIG_SSP_SUPPORT
),)
119 ifeq ($(CONFIG_TLS_SUPPORT
),)
124 ifneq ($(CONFIG_EXTRA_TARGET_ARCH
),)
127 --enable-targets
=$(call qstrip
,$(CONFIG_EXTRA_TARGET_ARCH_NAME
))-linux-
$(TARGET_SUFFIX
)
130 ifeq ($(LIBC
),uClibc
)
132 --disable-__cxa_atexit
135 --enable-__cxa_atexit
138 GCC_CONFIGURE_STAGE0
:= \
142 --enable-languages
=c \
147 GCC_CONFIGURE_STAGE1
:= \
150 --with-sysroot
=$(BUILD_DIR_TOOLCHAIN
)/$(LIBC
)-dev \
151 --enable-languages
=c \
155 GCC_CONFIGURE_STAGE2
:= \
157 --enable-languages
=$(TARGET_LANGUAGES
) \
160 --with-slibdir
=$(TOOLCHAIN_DIR
)/lib \
163 TARGET_CFLAGS
:= $(patsubst -Os
,-O2
,$(TARGET_CFLAGS
))
167 export SHELL
="$(BASH)"; \
169 CFLAGS_FOR_TARGET
="$(TARGET_CFLAGS)" \
170 CXXFLAGS_FOR_TARGET
="$(TARGET_CFLAGS)"
172 define Host
/SetToolchainInfo
173 $(SED
) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR
)/info.mk
174 $(SED
) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR
)/info.mk
178 define Stage0
/Configure
179 mkdir
-p
$(HOST_BUILD_DIR0
)
180 (cd
$(HOST_BUILD_DIR0
); rm -f config.cache
; \
181 $(GCC_CONFIGURE_STAGE0
) \
185 define Stage0
/Compile
186 $(GCC_MAKE
) -C
$(HOST_BUILD_DIR0
) all-gcc
189 define Stage0
/Install
190 $(GCC_MAKE
) -C
$(HOST_BUILD_DIR0
) install-gcc
194 define Stage1
/Configure
195 mkdir
-p
$(HOST_BUILD_DIR1
)
196 (cd
$(HOST_BUILD_DIR1
); rm -f config.cache
; \
197 $(GCC_CONFIGURE_STAGE1
) \
201 define Stage1
/Compile
202 $(CP
) $(BUILD_DIR_TOOLCHAIN
)/linux-dev
/* $(BUILD_DIR_TOOLCHAIN
)/$(LIBC
)-dev
/
203 $(GCC_MAKE
) -C
$(HOST_BUILD_DIR1
) \
204 all-build-libiberty \
206 $(if
$(GCC_BUILD_TARGET_LIBGCC
),all-target-libgcc
)
209 define Stage1
/Install
210 $(GCC_MAKE
) -C
$(HOST_BUILD_DIR1
) \
212 $(if
$(GCC_BUILD_TARGET_LIBGCC
),install-target-libgcc
)
214 # XXX: glibc insists on linking against libgcc_eh
215 ( cd
$(TOOLCHAIN_DIR
)/usr
/lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(PKG_VERSION
) ; \
216 [ -e libgcc_eh.a
] || ln
-sf libgcc.a libgcc_eh.a
; \
217 cp libgcc.a libgcc_initial.a
; \
222 define Stage2
/Configure
223 mkdir
-p
$(HOST_BUILD_DIR2
) $(TOOLCHAIN_DIR
)/usr
/$(REAL_GNU_TARGET_NAME
)
224 # Important! Required for limits.h to be fixed.
225 rm -rf
$(TOOLCHAIN_DIR
)/usr
/$(REAL_GNU_TARGET_NAME
)/sys-include
226 ln
-sf ..
/include $(TOOLCHAIN_DIR
)/usr
/$(REAL_GNU_TARGET_NAME
)/sys-include
227 rm -rf
$(TOOLCHAIN_DIR
)/usr
/$(REAL_GNU_TARGET_NAME
)/lib
228 ln
-sf ..
/lib
$(TOOLCHAIN_DIR
)/usr
/$(REAL_GNU_TARGET_NAME
)/lib
229 $(if
$(CONFIG_mips64
)$(CONFIG_mips64el
)$(CONFIG_x86_64
),ln
-sf ..
/lib64
$(TOOLCHAIN_DIR
)/usr
/$(REAL_GNU_TARGET_NAME
)/lib64
)
230 (cd
$(HOST_BUILD_DIR2
); rm -f config.cache
; \
231 $(GCC_CONFIGURE_STAGE2
) \
235 define Stage2
/Compile
236 $(GCC_MAKE
) -C
$(HOST_BUILD_DIR2
) all
239 define SetupExtraArch
240 for app in
$(TOOLCHAIN_DIR
)/usr
/bin
/$(OPTIMIZE_FOR_CPU
)*-{gcc
,gcc-
*,g
++}; do \
241 [ -e
$$$$app ] || continue
; \
242 old_base
=$$$$(basename $$$$app); \
243 new_base
=$(call qstrip
,$(CONFIG_EXTRA_TARGET_ARCH_NAME
))-$$$${old_base
##$(OPTIMIZE_FOR_CPU)-}; \
244 sed
-e
"s/@CC_BASE@/$$$$old_base/" \
245 -e
's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
246 .
/files
/alternate-arch-cc.in
> \
247 $(TOOLCHAIN_DIR
)/usr
/bin
/$$$$new_base; \
248 chmod a
+x
$(TOOLCHAIN_DIR
)/usr
/bin
/$$$$new_base; \
252 define Stage2
/Install
253 $(GCC_MAKE
) -C
$(HOST_BUILD_DIR2
) install
254 # Set up the symlinks to enable lying about target name.
256 (cd
$(TOOLCHAIN_DIR
)/usr
; \
257 ln
-sf
$(REAL_GNU_TARGET_NAME
) $(GNU_TARGET_NAME
); \
259 for app in
$(REAL_GNU_TARGET_NAME
)-* ; do \
261 $(GNU_TARGET_NAME
)$$$${app
##$(REAL_GNU_TARGET_NAME)}; \
264 $(if
$(CONFIG_EXTRA_TARGET_ARCH
),$(call SetupExtraArch
))
268 BUGURL
=https
://dev.openwrt.org
/
271 $(call Host
/SetToolchainInfo
)
272 $(call Host
/Prepare
/Default
)
273 ln
-snf
$(GCC_DIR
) $(BUILD_DIR_TOOLCHAIN
)/$(PKG_NAME
)
274 $(CP
) $(SCRIPT_DIR
)/config.
{guess
,sub
} $(HOST_BUILD_DIR
)/
275 $(SED
) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(HOST_BUILD_DIR
)/gcc
/config
/*/t-
*
276 $(SED
) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(HOST_BUILD_DIR
)/gcc
/version.c
277 $(SED
) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:$(BUGURL)>\2,' $(HOST_BUILD_DIR
)/gcc
/version.c
278 $(SED
) 's,http://gcc.gnu.org/bugs.html,$(BUGURL),' $(HOST_BUILD_DIR
)/gcc
/configure
279 #(cd $(HOST_BUILD_DIR)/libstdc++-v3; autoconf;);
280 $(SED
) 's,gcc_no_link=yes,gcc_no_link=no,' $(HOST_BUILD_DIR
)/libstdc
++-v3
/configure
281 $(call Stage0
/Configure
)
282 $(call Stage0
/Compile
)
283 $(call Stage0
/Install
)
286 define Host
/Configure
290 $(call Stage1
/Configure
)
291 $(call Stage1
/Compile
)
292 $(call Stage1
/Install
)
296 $(call Stage2
/Configure
)
297 $(call Stage2
/Compile
)
298 $(call Stage2
/Install
)
307 $(BUILD_DIR_TOOLCHAIN
)/$(PKG_NAME
) \
308 $(TOOLCHAIN_DIR
)/usr
/$(REAL_GNU_TARGET_NAME
) \
309 $(TOOLCHAIN_DIR
)/usr
/bin
/$(REAL_GNU_TARGET_NAME
)-gc
* \
310 $(TOOLCHAIN_DIR
)/usr
/bin
/$(REAL_GNU_TARGET_NAME
)-c
*
313 $(eval
$(call HostBuild
))