1# Makefile for to build a gcc/uClibc toolchain
2#
3# Copyright (C) 2002-2003 Erik Andersen <andersen@uclibc.org>
4# Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
5# Copyright (C) 2005-2006 Felix Fietkau <nbd@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
21include $(TOPDIR)/rules.mk
22
23PKG_NAME:=gcc
24PKG_VERSION:=$(strip $(subst ",, $(CONFIG_GCC_VERSION)))#"))
25
26ifeq ($(PKG_VERSION),3.4.6)
27  PKG_MD5SUM:=4a21ac777d4b5617283ce488b808da7b
28endif
29ifeq ($(PKG_VERSION),4.1.2)
30  PKG_MD5SUM:=a4a3eb15c96030906d8494959eeda23c
31endif
32ifeq ($(PKG_VERSION),4.2.4)
33  PKG_MD5SUM:=d79f553e7916ea21c556329eacfeaa16
34endif
35ifeq ($(PKG_VERSION),4.3.5)
36  PKG_MD5SUM:=e588cfde3bf323f82918589b94f14a15
37endif
38
39PATCH_DIR=./patches/$(PKG_VERSION)
40PKG_SOURCE_URL:=ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-$(PKG_VERSION) \
41	http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-$(PKG_VERSION) \
42	ftp://ftp.gnu.org/gnu/gcc/releases/gcc-$(PKG_VERSION)
43PKG_SOURCE:=gcc-$(PKG_VERSION).tar.bz2
44STAGING_DIR_HOST:=$(TOOLCHAIN_DIR)
45BUILD_DIR_HOST:=$(BUILD_DIR_TOOLCHAIN)
46
47include $(INCLUDE_DIR)/host-build.mk
48
49STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
50PKG_BUILD_DIR1:=$(PKG_BUILD_DIR)-initial
51PKG_BUILD_DIR2:=$(PKG_BUILD_DIR)-final
52
53SEP:=,
54TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
55
56EXTRA_TARGET=$(if $(CONFIG_EXTRA_TARGET_ARCH),--enable-biarch --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-uclibc)
57
58export libgcc_cv_fixed_point=no
59
60GCC_CONFIGURE:= \
61	SHELL="$(BASH)" \
62	$(PKG_BUILD_DIR)/configure \
63		--prefix=$(TOOLCHAIN_DIR) \
64		--build=$(GNU_HOST_NAME) \
65		--host=$(GNU_HOST_NAME) \
66		--target=$(REAL_GNU_TARGET_NAME) \
67		--with-gnu-ld \
68		--enable-target-optspace \
69		--disable-libgomp \
70		--disable-libmudflap \
71		--disable-multilib \
72		--disable-nls \
73		--disable-__cxa_atexit \
74		$(SOFT_FLOAT_CONFIG_OPTION) \
75		$(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
76
77ifneq ($(CONFIG_GCC_VERSION_4_3)$(CONFIG_GCC_VERSION_4_4),)
78  GCC_BUILD_TARGET_LIBGCC:=y
79  GCC_CONFIGURE+= \
80		--with-gmp=$(TOPDIR)/staging_dir/host \
81		--with-mpfr=$(TOPDIR)/staging_dir/host \
82		--disable-decimal-float
83endif
84
85ifneq ($(CONFIG_SSP_SUPPORT),)
86  GCC_CONFIGURE+= \
87		--enable-libssp
88else
89  GCC_CONFIGURE+= \
90		--disable-libssp
91endif
92
93ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
94  GCC_CONFIGURE+= \
95		--enable-biarch \
96		--enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
97endif
98
99GCC_CONFIGURE_STAGE1:= \
100	$(GCC_CONFIGURE) \
101		--with-newlib \
102		--with-sysroot=$(BUILD_DIR_HOST)/uClibc_dev/ \
103		--enable-languages=c \
104		--disable-shared \
105		--disable-threads \
106
107GCC_CONFIGURE_STAGE2:= \
108	$(GCC_CONFIGURE) \
109		--enable-languages=$(TARGET_LANGUAGES) \
110		--enable-shared \
111		--enable-threads \
112
113ifneq ($(CONFIG_TLS_SUPPORT),)
114  GCC_CONFIGURE_STAGE2+= \
115		--enable-tls
116else
117  GCC_CONFIGURE_STAGE2+= \
118		--disable-tls
119endif
120
121GCC_MAKE:= \
122	export SHELL="$(BASH)"; \
123	$(MAKE) \
124		CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
125		CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
126
127define Build/SetToolchainInfo
128	$(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
129	$(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
130endef
131
132
133define Stage1/Configure
134	mkdir -p $(PKG_BUILD_DIR1)
135	(cd $(PKG_BUILD_DIR1); rm -f config.cache; \
136		$(GCC_CONFIGURE_STAGE1) \
137	);
138endef
139
140define Stage1/Compile
141	$(GCC_MAKE) -C $(PKG_BUILD_DIR1) all-gcc \
142	    $(if $(GCC_BUILD_TARGET_LIBGCC),all-target-libgcc)
143endef
144
145define Stage1/Install
146	$(GCC_MAKE) -C $(PKG_BUILD_DIR1) install-gcc \
147	    $(if $(GCC_BUILD_TARGET_LIBGCC),install-target-libgcc)
148
149	# XXX: glibc insists on linking against libgcc_eh
150	( cd $(TOOLCHAIN_DIR)/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION) ; \
151	    [ -e libgcc_eh.a ] || ln -sf libgcc.a libgcc_eh.a ; \
152	    cp libgcc.a libgcc_initial.a; \
153	)
154endef
155
156define Stage2/Configure
157	mkdir -p $(PKG_BUILD_DIR2) $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)
158	# Important!  Required for limits.h to be fixed.
159	rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
160	ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
161	rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
162	ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
163	(cd $(PKG_BUILD_DIR2); rm -f config.cache; \
164		$(GCC_CONFIGURE_STAGE2) \
165	);
166endef
167
168define Stage2/Compile
169	$(GCC_MAKE) -C $(PKG_BUILD_DIR2) all
170endef
171
172define SetupExtraArch
173	for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
174		[ -e $$$$app ] || continue; \
175		old_base=$$$$(basename $$$$app); \
176		new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
177		sed -e "s/@CC_BASE@/$$$$old_base/" \
178			-e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
179			 ./files/alternate-arch-cc.in > \
180			 $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
181		chmod a+x $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
182	done
183endef
184
185define Stage2/Install
186	$(GCC_MAKE) -C $(PKG_BUILD_DIR2) install
187	# Set up the symlinks to enable lying about target name.
188	set -e; \
189	(cd $(TOOLCHAIN_DIR); \
190		ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
191		cd bin; \
192		for app in $(REAL_GNU_TARGET_NAME)-* ; do \
193			ln -sf $$$${app} \
194		   	$(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
195		done; \
196	);
197	$(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
198	$(RSTRIP) $(TOOLCHAIN_DIR)/libexec/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
199	-$(RSTRIP) $(TOOLCHAIN_DIR)/libexec/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/install-tools
200endef
201
202
203
204define Build/Prepare
205	$(call Build/Prepare/Default)
206	$(call Build/SetToolchainInfo)
207	$(CP) $(SCRIPT_DIR)/config.{guess,sub} $(PKG_BUILD_DIR)/
208	$(SED) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(PKG_BUILD_DIR)/gcc/config/*/t-*
209	#(cd $(PKG_BUILD_DIR)/libstdc++-v3; autoconf;);
210	$(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(PKG_BUILD_DIR)/libstdc++-v3/configure
211endef
212
213define Build/Configure
214	$(call Stage1/Configure)
215endef
216
217define Build/Compile
218	$(call Stage1/Compile)
219	$(call Stage1/Install)
220endef
221
222define Build/Install
223	$(call Stage2/Configure)
224	$(call Stage2/Compile)
225	$(call Stage2/Install)
226endef
227
228define Build/Clean
229	rm -rf \
230		$(PKG_BUILD_DIR) \
231		$(PKG_BUILD_DIR1) \
232		$(PKG_BUILD_DIR2) \
233		$(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
234		$(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
235		$(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
236endef
237
238$(eval $(call HostBuild))
239