1 # Makefile for to build a gcc/uClibc toolchain
3 # Copyright (C) 2002-2003 Erik Andersen <andersen@uclibc.org>
4 # Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
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.
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.
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
20 ifneq ($(findstring 2.95,$(GCC_VERSION)),2.95)
21 GCC_VERSION:=$(strip $(GCC_VERSION))
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)
28 #GCC_VERSION:=3.3-20031013
29 #GCC_SITE:=http://gcc.get-software.com/snapshots/$(GCC_VERSION)
31 GCC_SOURCE:=gcc-$(GCC_VERSION).tar.bz2
32 GCC_DIR:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)
34 GCC_STRIP_HOST_BINARIES:=true
36 #############################################################
38 # Setup some initial stuff
40 #############################################################
42 ifeq ($(BR2_INSTALL_LIBGCJ),y)
43 TARGET_LANGUAGES:=c,c++,java
45 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
46 TARGET_LANGUAGES:=c,c++
52 #############################################################
54 # build the first pass gcc compiler
56 #############################################################
57 GCC_BUILD_DIR1:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-initial
59 $(DL_DIR)/$(GCC_SOURCE):
61 $(WGET) -P $(DL_DIR) $(GCC_SITE)/$(GCC_SOURCE)
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
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
80 ifeq ("$(strip $(ARCH))","armeb")
81 toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc/$(GCC_VERSION) arm-softfloat.patch.conditional
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
88 touch $(GCC_DIR)/.patched
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...
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 \
104 --with-sysroot=$(TOOL_BUILD_DIR)/uClibc_dev/ \
105 --disable-__cxa_atexit \
106 --enable-target-optspace \
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
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
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
124 gcc_initial: uclibc-configured binutils $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc
127 rm -rf $(GCC_BUILD_DIR1)
128 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)*
130 gcc_initial-toolclean:
131 rm -rf $(GCC_BUILD_DIR1)
133 #############################################################
135 # second pass compiler build. Build the compiler targeting
136 # the newly built shared uClibc library.
138 #############################################################
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
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) \
159 --disable-__cxa_atexit \
160 --enable-target-optspace \
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
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
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/*
180 # Set up the symlinks to enable lying about target name.
182 (cd $(STAGING_DIR); \
183 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
185 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
187 $(GNU_TARGET_NAME)$${app##$(REAL_GNU_TARGET_NAME)}; \
191 # Now for the ugly 3.3.x soft float hack...
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 ; \
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 ; \
205 cp toolchain/gcc/$(GCC_VERSION)/specs-$(ARCH)-soft-float $(STAGING_DIR)/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
209 # Ok... that's enough of that.
211 touch $(GCC_BUILD_DIR2)/.installed
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/
219 gcc: uclibc-configured binutils gcc_initial $(LIBFLOAT_TARGET) uclibc \
220 $(TARGET_DIR)/lib/libgcc_s.so.1 $(GCC_BUILD_DIR2)/.installed $(GCC_TARGETS)
222 gcc-source: $(DL_DIR)/$(GCC_SOURCE)
225 rm -rf $(GCC_BUILD_DIR2)
226 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)*
229 rm -rf $(GCC_BUILD_DIR2)
231 #############################################################
233 # Next build target gcc compiler
235 #############################################################
236 GCC_BUILD_DIR3:=$(BUILD_DIR)/gcc-$(GCC_VERSION)-target
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 \
243 --build=$(GNU_HOST_NAME) \
244 --host=$(REAL_GNU_TARGET_NAME) \
245 --target=$(REAL_GNU_TARGET_NAME) \
246 --enable-languages=$(TARGET_LANGUAGES) \
248 --with-gxx-include-dir=/usr/include/c++ \
249 --disable-__cxa_atexit \
250 --enable-target-optspace \
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
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
266 # gcc-lib dir changes names to gcc with 3.4.mumble
268 ifeq ($(findstring 3.4.,$(GCC_VERSION)),3.4.)
269 GCC_LIB_SUBDIR=lib/gcc/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)
271 GCC_LIB_SUBDIR=lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)
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
280 # Now for the ugly 3.3.x soft float hack...
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
291 # Ok... that's enough of that.
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)
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/ ; \
308 # These are in /lib, so...
309 #rm -rf $(TARGET_DIR)/usr/lib/libgcc_s.so*
310 #touch -c $(TARGET_DIR)/usr/bin/gcc
312 gcc_target: uclibc_target binutils_target $(TARGET_DIR)/usr/bin/gcc
315 rm -rf $(GCC_BUILD_DIR3)
316 rm -f $(TARGET_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)*
318 gcc_target-toolclean:
319 rm -rf $(GCC_BUILD_DIR3)