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