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