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