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