nuke binutils 2.16.1 - old, unused, buggy
[openwrt/staging/florian.git] / toolchain / gcc / Makefile
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
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.0)
36 PKG_MD5SUM:=4798c23548dc791ea12a139e18940684
37 endif
38 ifeq ($(PKG_VERSION),4.2.1)
39 PKG_MD5SUM:=cba410e6ff70f7d7f4be7a0267707fd0
40 endif
41 ifeq ($(PKG_VERSION),4.2.2)
42 PKG_MD5SUM:=7ae33781417a35a2eb03ee098a9f4490
43 endif
44 ifeq ($(PKG_VERSION),4.2.3)
45 PKG_MD5SUM:=ef2a4d9991b3644115456ea05b2b8163
46 endif
47 ifeq ($(PKG_VERSION),4.2.4)
48 PKG_MD5SUM:=d79f553e7916ea21c556329eacfeaa16
49 endif
50
51 PATCH_DIR=./patches/$(PKG_VERSION)
52
53 STAGING_DIR_HOST:=$(TOOLCHAIN_DIR)
54 BUILD_DIR_HOST:=$(BUILD_DIR_TOOLCHAIN)
55 override CONFIG_AUTOREBUILD=
56
57 include $(INCLUDE_DIR)/host-build.mk
58
59 STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
60 BUILD_DIR1:=$(BUILD_DIR_HOST)/gcc-$(PKG_VERSION)-initial
61 BUILD_DIR2:=$(BUILD_DIR_HOST)/gcc-$(PKG_VERSION)-final
62
63 SEP:=,
64 TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
65
66 ifeq ($(CONFIG_SSP_SUPPORT),y)
67 SSP:=--enable-ssp
68 else
69 SSP:=--disable-ssp
70 endif
71
72 EXTRA_TARGET=$(if $(CONFIG_EXTRA_TARGET_ARCH),--enable-biarch --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-uclibc)
73
74 define Stage1/Configure
75 $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
76 $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
77 mkdir -p $(BUILD_DIR1)
78 (cd $(BUILD_DIR1); rm -f config.cache; \
79 SHELL="$(BASH)" \
80 $(PKG_BUILD_DIR)/configure \
81 --prefix=$(TOOLCHAIN_DIR) \
82 --build=$(GNU_HOST_NAME) \
83 --host=$(GNU_HOST_NAME) \
84 --target=$(REAL_GNU_TARGET_NAME) \
85 --enable-languages=c \
86 --disable-shared \
87 --with-sysroot=$(BUILD_DIR_HOST)/uClibc_dev/ \
88 --disable-__cxa_atexit \
89 --enable-target-optspace \
90 --with-gnu-ld \
91 --disable-nls \
92 --disable-libmudflap \
93 --disable-multilib \
94 $(SSP) \
95 $(EXTRA_TARGET) \
96 $(SOFT_FLOAT_CONFIG_OPTION) \
97 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
98 );
99 endef
100 define Stage1/Compile
101 export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) all-gcc
102 endef
103 define Stage1/Install
104 export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) install-gcc
105 endef
106
107 define Stage2/Configure
108 mkdir -p $(BUILD_DIR2) $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)
109 # Important! Required for limits.h to be fixed.
110 rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
111 ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
112 rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
113 ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
114 (cd $(BUILD_DIR2); rm -f config.cache; \
115 SHELL="$(BASH)" \
116 $(PKG_BUILD_DIR)/configure \
117 --prefix=$(TOOLCHAIN_DIR) \
118 --build=$(GNU_HOST_NAME) \
119 --host=$(GNU_HOST_NAME) \
120 --target=$(REAL_GNU_TARGET_NAME) \
121 --enable-languages=$(TARGET_LANGUAGES) \
122 --enable-shared \
123 --disable-__cxa_atexit \
124 --enable-target-optspace \
125 --with-gnu-ld \
126 --disable-nls \
127 --disable-libmudflap \
128 --disable-multilib \
129 $(SSP) \
130 $(EXTRA_TARGET) \
131 $(SOFT_FLOAT_CONFIG_OPTION) \
132 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
133 );
134 endef
135
136 define Stage2/Compile
137 export SHELL="\$(BASH)"; \$(MAKE) -C \$(BUILD_DIR2) all
138 endef
139
140 define SetupExtraArch
141 for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
142 [ -e $$$$app ] || continue; \
143 old_base=$$$$(basename $$$$app); \
144 new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
145 sed -e "s/@CC_BASE@/$$$$old_base/" \
146 -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
147 ./files/alternate-arch-cc.in > \
148 $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
149 chmod a+x $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
150 done
151 endef
152
153 define Stage2/Install
154 $(MAKE) -C $(BUILD_DIR2) \
155 SHELL="$(BASH)" \
156 install
157 # Set up the symlinks to enable lying about target name.
158 set -e; \
159 (cd $(TOOLCHAIN_DIR); \
160 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
161 cd bin; \
162 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
163 ln -sf $$$${app} \
164 $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
165 done; \
166 );
167 $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
168 endef
169
170 define Build/Prepare
171 $(call Build/Prepare/Default)
172 $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(PKG_BUILD_DIR)/gcc/version.c
173 $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:https://dev.openwrt.org/>\2,' $(PKG_BUILD_DIR)/gcc/version.c
174 (cd $(PKG_BUILD_DIR)/libstdc++-v3; autoconf;);
175 $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(PKG_BUILD_DIR)/libstdc++-v3/configure
176 endef
177
178 define Build/Configure
179 $(call Stage1/Configure)
180 endef
181
182 define Build/Compile
183 $(call Stage1/Compile)
184 $(if $(wildcard $(TOOLCHAIN_DIR)/bin/$(GNU_TARGET_NAME)-gcc),,$(call Stage1/Install))
185 endef
186
187 define Build/Install
188 $(call Stage2/Configure)
189 $(call Stage2/Compile)
190 $(call Stage2/Install)
191 endef
192
193 define Build/Clean
194 rm -rf \
195 $(PKG_BUILD_DIR) \
196 $(BUILD_DIR1) \
197 $(BUILD_DIR2) \
198 $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
199 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
200 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
201 endef
202
203 $(eval $(call HostBuild))