[toolchain] gcc: build with HOST_CFLAGS
[openwrt.git] / toolchain / gcc / common.mk
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-2012 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 ifeq ($(findstring linaro, $(CONFIG_GCC_VERSION)),linaro)
40     ifeq ($(CONFIG_GCC_VERSION),"4.5-linaro")
41       PKG_REV:=4.5-2012.03
42       PKG_VERSION:=4.5.4
43       PKG_VERSION_MAJOR:=4.5
44       PKG_MD5SUM:=0c25f93e15e362e352c933e4649a7fc6
45     endif
46     ifeq ($(CONFIG_GCC_VERSION),"4.6-linaro")
47       PKG_REV:=4.6-2012.11
48       PKG_VERSION:=4.6.4
49       PKG_VERSION_MAJOR:=4.6
50       PKG_MD5SUM:=d2632b8d3c0e44025dd1c8661db0c201
51     endif
52     ifeq ($(CONFIG_GCC_VERSION),"4.7-linaro")
53       PKG_REV:=4.7-2012.11
54       PKG_VERSION:=4.7.3
55       PKG_VERSION_MAJOR:=4.7
56       PKG_MD5SUM:=590481ff4aff1a9e0f9a206516248877
57     endif
58     PKG_SOURCE_URL:=http://launchpad.net/gcc-linaro/$(PKG_VERSION_MAJOR)/$(PKG_REV)/+download/
59     PKG_SOURCE:=$(PKG_NAME)-linaro-$(PKG_REV).tar.bz2
60     GCC_DIR:=gcc-linaro-$(PKG_REV)
61     HOST_BUILD_DIR:=$(BUILD_DIR_TOOLCHAIN)/$(GCC_DIR)
62 else
63   PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
64   PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
65
66   ifeq ($(PKG_VERSION),4.4.7)
67     PKG_MD5SUM:=295709feb4441b04e87dea3f1bab4281
68   endif
69   ifeq ($(PKG_VERSION),4.6.2)
70     PKG_MD5SUM:=028115c4fbfb6cfd75d6369f4a90d87e
71   endif
72   ifeq ($(PKG_VERSION),4.6.3)
73     PKG_MD5SUM:=773092fe5194353b02bb0110052a972e
74   endif
75   ifeq ($(PKG_VERSION),4.7.0)
76     PKG_MD5SUM:=2a0f1d99fda235c29d40b561f81d9a77
77   endif
78   ifeq ($(PKG_VERSION),4.7.2)
79     PKG_MD5SUM:=cc308a0891e778cfda7a151ab8a6e762
80   endif
81 endif
82 endif
83
84 PATCH_DIR=../patches/$(GCC_VERSION)
85
86 BUGURL=https://dev.openwrt.org/
87
88 HOST_BUILD_PARALLEL:=1
89
90 include $(INCLUDE_DIR)/toolchain-build.mk
91
92 HOST_SOURCE_DIR:=$(HOST_BUILD_DIR)
93 ifeq ($(GCC_VARIANT),minimal)
94   GCC_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
95 else
96   HOST_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
97   GCC_BUILD_DIR:=$(HOST_BUILD_DIR)
98 endif
99
100 HOST_STAMP_PREPARED:=$(HOST_BUILD_DIR)/.prepared
101 HOST_STAMP_BUILT:=$(GCC_BUILD_DIR)/.built
102 HOST_STAMP_CONFIGURED:=$(GCC_BUILD_DIR)/.configured
103 HOST_STAMP_INSTALLED:=$(STAGING_DIR_HOST)/stamp/.gcc_$(GCC_VARIANT)_installed
104
105 SEP:=,
106 TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)"
107
108 export libgcc_cv_fixed_point=no
109 ifdef CONFIG_USE_UCLIBC
110   export glibcxx_cv_c99_math_tr1=no
111 endif
112
113 GCC_CONFIGURE:= \
114         SHELL="$(BASH)" \
115         $(HOST_SOURCE_DIR)/configure \
116                 --prefix=$(TOOLCHAIN_DIR) \
117                 --build=$(GNU_HOST_NAME) \
118                 --host=$(GNU_HOST_NAME) \
119                 --target=$(REAL_GNU_TARGET_NAME) \
120                 --with-gnu-ld \
121                 --enable-target-optspace \
122                 --disable-libgomp \
123                 --disable-libmudflap \
124                 --disable-multilib \
125                 --disable-nls \
126                 $(GRAPHITE_CONFIGURE) \
127                 --with-host-libstdcxx=-lstdc++ \
128                 $(SOFT_FLOAT_CONFIG_OPTION) \
129                 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
130                 $(if $(CONFIG_mips64)$(CONFIG_mips64el),--with-arch=mips64 --with-abi=64) \
131                 $(if $(CONFIG_GCC_VERSION_LLVM),--enable-llvm=$(BUILD_DIR_BASE)/host/llvm) \
132                 $(if $(CONFIG_sparc),--with-long-double-128) \
133
134 ifeq ($(CONFIG_GCC_LLVM),)
135   GCC_BUILD_TARGET_LIBGCC:=y
136   GCC_CONFIGURE+= \
137                 --with-gmp=$(TOPDIR)/staging_dir/host \
138                 --with-mpfr=$(TOPDIR)/staging_dir/host \
139                 --disable-decimal-float
140   ifneq ($(CONFIG_mips)$(CONFIG_mipsel),)
141     GCC_CONFIGURE += --with-mips-plt
142   endif
143 endif
144
145 ifneq ($(CONFIG_GCC_VERSION_4_5)$(CONFIG_GCC_VERSION_4_6),)
146   GCC_CONFIGURE+= \
147                 --with-mpc=$(TOPDIR)/staging_dir/host
148 endif
149
150 ifneq ($(CONFIG_SSP_SUPPORT),)
151   GCC_CONFIGURE+= \
152                 --enable-libssp
153 else
154   GCC_CONFIGURE+= \
155                 --disable-libssp
156 endif
157
158 ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
159   GCC_CONFIGURE+= \
160                 --enable-biarch \
161                 --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
162 endif
163
164 ifdef CONFIG_sparc
165   GCC_CONFIGURE+= --enable-targets=all
166 endif
167
168 ifeq ($(LIBC),uClibc)
169   GCC_CONFIGURE+= \
170                 --disable-__cxa_atexit
171 else
172   GCC_CONFIGURE+= \
173                 --enable-__cxa_atexit
174 endif
175
176 ifneq ($(GCC_ARCH),)
177   GCC_CONFIGURE+= --with-arch=$(GCC_ARCH)
178 endif
179
180 GCC_MAKE:= \
181         export SHELL="$(BASH)"; \
182         $(MAKE) \
183                 CFLAGS="$(HOST_CFLAGS)" \
184                 CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
185                 CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
186
187 define Host/Prepare
188         mkdir -p $(GCC_BUILD_DIR)
189 endef
190
191 define Host/Configure
192         (cd $(GCC_BUILD_DIR) && rm -f config.cache; \
193                 $(GCC_CONFIGURE) \
194         );
195 endef
196
197 define Host/Clean
198         rm -rf \
199                 $(STAGING_DIR_HOST)/stamp/.gcc_* \
200                 $(STAGING_DIR_HOST)/stamp/.binutils_* \
201                 $(GCC_BUILD_DIR) \
202                 $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
203                 $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
204                 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
205                 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
206 endef