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