binutils & gcc patches from uclibc buildroot
[openwrt.git] / openwrt / toolchain / gcc / gcc-uclibc-3.x.mk
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 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 GCC_VERSION:=$(strip $(GCC_VERSION))
21
22 #GCC_SITE:=ftp://ftp.gnu.org/gnu/gcc/releases/gcc-$(GCC_VERSION)
23 GCC_SITE:=http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-$(GCC_VERSION)
24
25 #
26 # snapshots....
27 #GCC_VERSION:=3.3-20031013
28 #GCC_SITE:=http://gcc.get-software.com/snapshots/$(GCC_VERSION)
29 #
30 GCC_SOURCE:=gcc-$(GCC_VERSION).tar.bz2
31 GCC_DIR:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)
32 GCC_CAT:=bzcat
33 GCC_STRIP_HOST_BINARIES:=true
34
35 #############################################################
36 #
37 # Setup some initial stuff
38 #
39 #############################################################
40
41 ifeq ($(BR2_INSTALL_LIBGCJ),y)
42 TARGET_LANGUAGES:=c,c++,java
43 else
44 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
45 TARGET_LANGUAGES:=c,c++
46 else
47 TARGET_LANGUAGES:=c
48 endif
49 endif
50
51 #############################################################
52 #
53 # build the first pass gcc compiler
54 #
55 #############################################################
56 GCC_BUILD_DIR1:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-initial
57
58 $(DL_DIR)/$(GCC_SOURCE):
59 mkdir -p $(DL_DIR)
60 $(WGET) -P $(DL_DIR) $(GCC_SITE)/$(GCC_SOURCE)
61
62 $(GCC_DIR)/.unpacked: $(DL_DIR)/$(GCC_SOURCE)
63 mkdir -p $(TOOL_BUILD_DIR)
64 $(GCC_CAT) $(DL_DIR)/$(GCC_SOURCE) | tar -C $(TOOL_BUILD_DIR) $(TAR_OPTIONS) -
65 touch $(GCC_DIR)/.unpacked
66
67 $(GCC_DIR)/.patched: $(GCC_DIR)/.unpacked
68 # Apply any files named gcc-*.patch from the source directory to gcc
69 $(SCRIPT_DIR)/patch-kernel.sh $(GCC_DIR) ./$(GCC_VERSION) \*.patch
70 # Note: The soft float situation has improved considerably with gcc 3.4.x.
71 # We can dispense with the custom spec files, as well as libfloat for the arm case.
72 # However, we still need a patch for arm. There's a similar patch for gcc 3.3.x
73 # which needs to be integrated so we can kill of libfloat for good, except for
74 # anyone (?) who might still be using gcc 2.95. mjn3
75 ifeq ($(BR2_SOFT_FLOAT),y)
76 ifeq ("$(strip $(ARCH))","arm")
77 $(SCRIPT_DIR)/patch-kernel.sh $(GCC_DIR) ./$(GCC_VERSION) arm-softfloat.patch.conditional
78 endif
79 ifeq ("$(strip $(ARCH))","armeb")
80 $(SCRIPT_DIR)/patch-kernel.sh $(GCC_DIR) ./$(GCC_VERSION) arm-softfloat.patch.conditional
81 endif
82 # Not yet updated to 3.4.1.
83 #ifeq ("$(strip $(ARCH))","i386")
84 #toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc i386-gcc-soft-float.patch
85 #endif
86 endif
87 touch $(GCC_DIR)/.patched
88
89 # The --without-headers option stopped working with gcc 3.0 and has never been
90 # # fixed, so we need to actually have working C library header files prior to
91 # # the step or libgcc will not build...
92
93 $(GCC_BUILD_DIR1)/.configured: $(GCC_DIR)/.patched
94 mkdir -p $(GCC_BUILD_DIR1)
95 (cd $(GCC_BUILD_DIR1); PATH=$(TARGET_PATH) \
96 $(GCC_DIR)/configure \
97 --prefix=$(STAGING_DIR) \
98 --build=$(GNU_HOST_NAME) \
99 --host=$(GNU_HOST_NAME) \
100 --target=$(REAL_GNU_TARGET_NAME) \
101 --enable-languages=c \
102 --disable-shared \
103 --with-sysroot=$(TOOL_BUILD_DIR)/uClibc_dev/ \
104 --disable-__cxa_atexit \
105 --enable-target-optspace \
106 --with-gnu-ld \
107 $(DISABLE_NLS) \
108 $(MULTILIB) \
109 $(SOFT_FLOAT_CONFIG_OPTION) \
110 $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
111 $(EXTRA_GCC_CONFIG_OPTIONS));
112 touch $(GCC_BUILD_DIR1)/.configured
113
114 $(GCC_BUILD_DIR1)/.compiled: $(GCC_BUILD_DIR1)/.configured
115 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) all-gcc
116 touch $(GCC_BUILD_DIR1)/.compiled
117
118 $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc: $(GCC_BUILD_DIR1)/.compiled
119 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) install-gcc
120 #rm -f $(STAGING_DIR)/bin/gccbug $(STAGING_DIR)/bin/gcov
121 #rm -rf $(STAGING_DIR)/info $(STAGING_DIR)/man $(STAGING_DIR)/share/doc $(STAGING_DIR)/share/locale
122
123 gcc_initial: $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc
124
125 gcc_initial-clean:
126 rm -rf $(GCC_BUILD_DIR1)
127
128 gcc_initial-toolclean:
129 rm -rf $(GCC_BUILD_DIR1)
130
131 #############################################################
132 #
133 # second pass compiler build. Build the compiler targeting
134 # the newly built shared uClibc library.
135 #
136 #############################################################
137 #
138 # Sigh... I had to rework things because using --with-gxx-include-dir
139 # causes issues with include dir search order for g++. This seems to
140 # have something to do with "path translations" and possibly doesn't
141 # affect gcc-target. However, I haven't tested gcc-target yet so no
142 # guarantees. mjn3
143
144 GCC_BUILD_DIR2:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-final
145 $(GCC_BUILD_DIR2)/.configured: $(GCC_DIR)/.patched $(STAGING_DIR)/lib/libc.a
146 mkdir -p $(GCC_BUILD_DIR2)
147 # Important! Required for limits.h to be fixed.
148 ln -sf ../include $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
149 (cd $(GCC_BUILD_DIR2); PATH=$(TARGET_PATH) \
150 $(GCC_DIR)/configure \
151 --prefix=$(STAGING_DIR) \
152 --build=$(GNU_HOST_NAME) \
153 --host=$(GNU_HOST_NAME) \
154 --target=$(REAL_GNU_TARGET_NAME) \
155 --enable-languages=$(TARGET_LANGUAGES) \
156 --enable-shared \
157 --disable-__cxa_atexit \
158 --enable-target-optspace \
159 --with-gnu-ld \
160 $(DISABLE_NLS) \
161 $(MULTILIB) \
162 $(SOFT_FLOAT_CONFIG_OPTION) \
163 $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
164 $(GCC_USE_SJLJ_EXCEPTIONS) \
165 $(EXTRA_GCC_CONFIG_OPTIONS));
166 touch $(GCC_BUILD_DIR2)/.configured
167
168 $(GCC_BUILD_DIR2)/.compiled: $(GCC_BUILD_DIR2)/.configured
169 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) all
170 touch $(GCC_BUILD_DIR2)/.compiled
171
172 gcc-install: $(GCC_BUILD_DIR2)/.compiled
173 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) install
174 # Strip the host binaries
175 ifeq ($(GCC_STRIP_HOST_BINARIES),true)
176 -strip --strip-all -R .note -R .comment $(STAGING_DIR)/bin/*
177 endif
178 # Set up the symlinks to enable lying about target name.
179 set -e; \
180 (cd $(STAGING_DIR); \
181 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
182 cd bin; \
183 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
184 ln -sf $${app} \
185 $(GNU_TARGET_NAME)$${app##$(REAL_GNU_TARGET_NAME)}; \
186 done; \
187 );
188 #
189 # Now for the ugly 3.3.x soft float hack...
190 #
191 ifeq ($(BR2_SOFT_FLOAT),y)
192 ifeq ($(findstring 3.3.,$(GCC_VERSION)),3.3.)
193 # Make sure we have a soft float specs file for this arch
194 if [ ! -f ./$(GCC_VERSION)/specs-$(ARCH)-soft-float ] ; then \
195 echo soft float configured but no specs file for this arch ; \
196 /bin/false ; \
197 fi;
198 # Replace specs file with one that defaults to soft float mode.
199 if [ ! -f $(STAGING_DIR)/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs ] ; then \
200 echo staging dir specs file is missing ; \
201 /bin/false ; \
202 fi;
203 cp ./$(GCC_VERSION)/specs-$(ARCH)-soft-float $(STAGING_DIR)/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
204 endif
205 endif
206 # These are in /lib, so...
207 rm -rf $(TARGET_DIR)/usr/lib/libgcc_s.so*
208 -$(STRIP) $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libgcc_s.so.1
209 -cp -a $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libgcc_s* $(TARGET_DIR)/lib/
210
211 gcc: gcc_initial $(LIBFLOAT_TARGET) \
212 gcc-install $(GCC_TARGETS)
213
214 gcc-source: $(DL_DIR)/$(GCC_SOURCE)
215
216 gcc-clean:
217 rm -rf $(GCC_DIR)
218 rm -rf $(GCC_BUILD_DIR2)
219 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc*
220 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
221
222 gcc-toolclean:
223 rm -rf $(GCC_BUILD_DIR2)
224
225 #############################################################
226 #
227 # Next build target gcc compiler
228 #
229 #############################################################
230 GCC_BUILD_DIR3:=$(BUILD_DIR)/gcc-$(GCC_VERSION)-target
231
232 $(GCC_BUILD_DIR3)/.configured: gcc-install
233 mkdir -p $(GCC_BUILD_DIR3)
234 (cd $(GCC_BUILD_DIR3); PATH=$(TARGET_PATH) \
235 $(GCC_DIR)/configure \
236 --prefix=/usr \
237 --build=$(GNU_HOST_NAME) \
238 --host=$(REAL_GNU_TARGET_NAME) \
239 --target=$(REAL_GNU_TARGET_NAME) \
240 --enable-languages=$(TARGET_LANGUAGES) \
241 --enable-shared \
242 --with-gxx-include-dir=/usr/include/c++ \
243 --disable-__cxa_atexit \
244 --enable-target-optspace \
245 --with-gnu-ld \
246 $(DISABLE_NLS) \
247 $(MULTILIB) \
248 $(SOFT_FLOAT_CONFIG_OPTION) \
249 $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
250 $(GCC_USE_SJLJ_EXCEPTIONS) \
251 $(EXTRA_GCC_CONFIG_OPTIONS));
252 touch $(GCC_BUILD_DIR3)/.configured
253
254 $(GCC_BUILD_DIR3)/.compiled: $(GCC_BUILD_DIR3)/.configured
255 PATH=$(TARGET_PATH) \
256 $(MAKE) $(TARGET_GCC_ARGS) -C $(GCC_BUILD_DIR3) all
257 touch $(GCC_BUILD_DIR3)/.compiled
258
259 #
260 # gcc-lib dir changes names to gcc with 3.4.mumble
261 #
262 ifeq ($(findstring 3.4.,$(GCC_VERSION)),3.4.)
263 GCC_LIB_SUBDIR=lib/gcc/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)
264 else
265 GCC_LIB_SUBDIR=lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)
266 endif
267
268 $(TARGET_DIR)/usr/bin/gcc: $(GCC_BUILD_DIR3)/.compiled
269 PATH=$(TARGET_PATH) \
270 $(MAKE) DESTDIR=$(TARGET_DIR) -C $(GCC_BUILD_DIR3) install
271 # Remove broken specs file (cross compile flag is set).
272 rm -f $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR)/specs
273 #
274 # Now for the ugly 3.3.x soft float hack...
275 #
276 ifeq ($(BR2_SOFT_FLOAT),y)
277 ifeq ($(findstring 3.3.,$(GCC_VERSION)),3.3.)
278 # Add a specs file that defaults to soft float mode.
279 cp ./$(GCC_VERSION)/specs-$(ARCH)-soft-float $(TARGET_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
280 # Make sure gcc does not think we are cross compiling
281 $(SED) "s/^1/0/;" $(TARGET_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
282 endif
283 endif
284 #
285 # Ok... that's enough of that.
286 #
287 -(cd $(TARGET_DIR)/bin; find -type f | xargs $(STRIP) > /dev/null 2>&1)
288 -(cd $(TARGET_DIR)/usr/bin; find -type f | xargs $(STRIP) > /dev/null 2>&1)
289 -(cd $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR); $(STRIP) cc1 cc1plus collect2 > /dev/null 2>&1)
290 -(cd $(TARGET_DIR)/usr/lib; $(STRIP) libstdc++.so.*.*.* > /dev/null 2>&1)
291 -(cd $(TARGET_DIR)/lib; $(STRIP) libgcc_s.so.*.*.* > /dev/null 2>&1)
292 #
293 rm -f $(TARGET_DIR)/usr/lib/*.la*
294 #rm -rf $(TARGET_DIR)/share/locale $(TARGET_DIR)/usr/info \
295 # $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/doc
296 # Work around problem of missing syslimits.h
297 @if [ ! -f $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR)/include/syslimits.h ] ; then \
298 echo "warning: working around missing syslimits.h" ; \
299 cp -f $(STAGING_DIR)/$(GCC_LIB_SUBDIR)/include/syslimits.h \
300 $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR)/include/ ; \
301 fi
302 # These are in /lib, so...
303 #rm -rf $(TARGET_DIR)/usr/lib/libgcc_s.so*
304 #touch -c $(TARGET_DIR)/usr/bin/gcc
305
306 gcc_target: uclibc_target binutils_target $(TARGET_DIR)/usr/bin/gcc
307
308 gcc_target-clean:
309 rm -rf $(GCC_BUILD_DIR3)
310 rm -f $(TARGET_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)*
311
312 gcc_target-toolclean:
313 rm -rf $(GCC_BUILD_DIR3)
314
This page took 0.053093 seconds and 5 git commands to generate.