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 ifeq ($(findstring 2.95,$(GCC_VERSION)),2.95)
21 GCC_VERSION:=$(strip $(GCC_VERSION))
23 GCC_SITE:=http://www.uclibc.org/downloads/toolchain
24 GCC_SOURCE:=gcc-20011006.tar.bz2
25 GCC_DIR:=$(TOOL_BUILD_DIR)/gcc-20011006
28 STLPORT_SITE=http://www.stlport.org/archive
29 STLPORT_SOURCE=STLport-4.5.3.tar.gz
30 STLPORT_DIR=$(TOOL_BUILD_DIR)/STLport-4.5.3
31 GCC_STRIP_HOST_BINARIES:=true
33 #############################################################
35 # Setup some initial stuff
37 #############################################################
39 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
40 TARGET_LANGUAGES:=c,c++
41 STLPORT_TARGET=stlport
47 #############################################################
49 # build the first pass gcc compiler
51 #############################################################
52 GCC_BUILD_DIR1:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-initial
54 $(DL_DIR)/$(GCC_SOURCE):
56 $(WGET) -P $(DL_DIR) $(GCC_SITE)/$(GCC_SOURCE)
58 $(GCC_DIR)/.unpacked: $(DL_DIR)/$(GCC_SOURCE)
59 mkdir -p $(TOOL_BUILD_DIR)
60 $(GCC_CAT) $(DL_DIR)/$(GCC_SOURCE) | tar -C $(TOOL_BUILD_DIR) $(TAR_OPTIONS) -
61 touch $(GCC_DIR)/.unpacked
63 $(GCC_DIR)/.patched: $(GCC_DIR)/.unpacked
64 # Apply any files named gcc-*.patch from the source directory to gcc
65 toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc/$(GCC_VERSION) \*.patch\*
67 # We do not wish to build the libstdc++ library provided with gcc,
68 # since it doesn't seem to work at all with uClibc plus gcc 2.95...
70 mv $(GCC_DIR)/libstdc++ $(GCC_DIR)/libstdc++.orig
71 mv $(GCC_DIR)/libio $(GCC_DIR)/libio.orig
73 touch $(GCC_DIR)/.patched
75 # The --without-headers option stopped working with gcc 3.0 and has never been
76 # # fixed, so we need to actually have working C library header files prior to
77 # # the step or libgcc will not build...
78 $(GCC_BUILD_DIR1)/.configured: $(GCC_DIR)/.patched
79 mkdir -p $(GCC_BUILD_DIR1)
80 -mkdir -p $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/include
81 # Important! Required for limits.h to be fixed.
82 ln -sf include $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
83 (cd $(GCC_BUILD_DIR1); PATH=$(TARGET_PATH) \
84 $(GCC_DIR)/configure \
85 --prefix=$(STAGING_DIR) \
86 --build=$(GNU_HOST_NAME) \
87 --host=$(GNU_HOST_NAME) \
88 --target=$(REAL_GNU_TARGET_NAME) \
89 --enable-languages=c \
91 --includedir=$(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/include \
92 --with-headers=$(TOOL_BUILD_DIR)/uClibc_dev/usr/include \
93 --disable-__cxa_atexit \
94 --enable-target-optspace \
98 $(SOFT_FLOAT_CONFIG_OPTION) \
99 $(EXTRA_GCC_CONFIG_OPTIONS));
100 touch $(GCC_BUILD_DIR1)/.configured
102 $(GCC_BUILD_DIR1)/.compiled: $(GCC_BUILD_DIR1)/.configured
103 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) all-gcc
104 touch $(GCC_BUILD_DIR1)/.compiled
106 $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc: $(GCC_BUILD_DIR1)/.compiled
107 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) install-gcc
108 #rm -f $(STAGING_DIR)/bin/gccbug $(STAGING_DIR)/bin/gcov
109 #rm -rf $(STAGING_DIR)/info $(STAGING_DIR)/man $(STAGING_DIR)/share/doc $(STAGING_DIR)/share/locale
111 gcc_initial: uclibc-configured binutils $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc
114 rm -rf $(GCC_BUILD_DIR1)
115 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)*
117 gcc_initial-dirclean:
118 rm -rf $(GCC_BUILD_DIR1)
120 #############################################################
122 # STLport -- an alternative C++ library
124 #############################################################
125 STLPORT_PATCH=toolchain/gcc/2.95/STLport-4.5.3.patch
127 $(DL_DIR)/$(STLPORT_SOURCE):
128 $(WGET) -P $(DL_DIR) $(STLPORT_SITE)/$(STLPORT_SOURCE)
130 $(STLPORT_DIR)/Makefile: $(DL_DIR)/$(STLPORT_SOURCE) $(STLPORT_PATCH)
131 zcat $(DL_DIR)/$(STLPORT_SOURCE) | tar -C $(TOOL_BUILD_DIR) $(TAR_OPTIONS) -
132 cat $(STLPORT_PATCH) | patch -d $(STLPORT_DIR) -p1
134 $(STLPORT_DIR)/lib/libstdc++.a: $(STLPORT_DIR)/Makefile
135 $(MAKE) ARCH=$(OPTIMIZE_FOR_CPU) PREFIX=$(STAGING_DIR)/$(REAL_GNU_TARGET_NAME) -C $(STLPORT_DIR)
137 $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libstdc++.a: $(STLPORT_DIR)/lib/libstdc++.a
138 $(MAKE) ARCH=$(OPTIMIZE_FOR_CPU) PREFIX=$(STAGING_DIR)/$(REAL_GNU_TARGET_NAME) -C $(STLPORT_DIR) install
140 stlport: $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libstdc++.a
142 stlport-source: $(DL_DIR)/$(STLPORT_SOURCE)
145 rm -f $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libstdc++*
146 rm -f $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/include/c++*
147 -$(MAKE) -C $(STLPORT_DIR) clean
150 rm -f $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libstdc++*
151 rm -f $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/include/g++-v3*
152 rm -rf $(STLPORT_DIR)
154 #############################################################
156 # second pass compiler build. Build the compiler targeting
157 # the newly built shared uClibc library.
159 #############################################################
160 GCC_BUILD_DIR2:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-final
162 $(GCC_BUILD_DIR2)/.configured: $(GCC_DIR)/.patched $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libc.a
163 mkdir -p $(GCC_BUILD_DIR2)
164 (cd $(GCC_BUILD_DIR2); PATH=$(TARGET_PATH) \
165 $(GCC_DIR)/configure \
166 --prefix=$(STAGING_DIR) \
167 --build=$(GNU_HOST_NAME) \
168 --host=$(GNU_HOST_NAME) \
169 --target=$(REAL_GNU_TARGET_NAME) \
170 --enable-languages=$(TARGET_LANGUAGES) \
172 --with-gxx-include-dir=$(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/include/c++ \
173 --disable-__cxa_atexit \
174 --enable-target-optspace \
178 $(SOFT_FLOAT_CONFIG_OPTION) \
179 $(EXTRA_GCC_CONFIG_OPTIONS));
180 touch $(GCC_BUILD_DIR2)/.configured
182 $(GCC_BUILD_DIR2)/.compiled: $(GCC_BUILD_DIR2)/.configured
183 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) all
184 touch $(GCC_BUILD_DIR2)/.compiled
186 $(GCC_BUILD_DIR2)/.installed: $(GCC_BUILD_DIR2)/.compiled
187 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) install
188 # Strip the host binaries
189 ifeq ($(GCC_STRIP_HOST_BINARIES),true)
190 -strip --strip-all -R .note -R .comment $(STAGING_DIR)/bin/*
192 # Set up the symlinks to enable lying about target name.
194 (cd $(STAGING_DIR); \
195 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
197 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
199 $(GNU_TARGET_NAME)$${app##$(REAL_GNU_TARGET_NAME)}; \
202 touch $(GCC_BUILD_DIR2)/.installed
204 gcc: uclibc-configured binutils gcc_initial $(LIBFLOAT_TARGET) uclibc \
205 $(GCC_BUILD_DIR2)/.installed $(GCC_TARGETS) $(STLPORT_TARGET)
207 gcc-source: $(DL_DIR)/$(GCC_SOURCE)
210 rm -rf $(GCC_BUILD_DIR2)
211 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)*
214 rm -rf $(GCC_BUILD_DIR2)
216 #############################################################
218 # Next build target gcc compiler
220 #############################################################
221 GCC_BUILD_DIR3:=$(BUILD_DIR)/gcc-$(GCC_VERSION)-target
223 $(GCC_BUILD_DIR3)/.configured: $(GCC_BUILD_DIR2)/.installed
224 mkdir -p $(GCC_BUILD_DIR3)
225 (cd $(GCC_BUILD_DIR3); PATH=$(TARGET_PATH) \
226 $(GCC_DIR)/configure \
228 --build=$(GNU_HOST_NAME) \
229 --host=$(REAL_GNU_TARGET_NAME) \
230 --target=$(REAL_GNU_TARGET_NAME) \
231 --enable-languages=$(TARGET_LANGUAGES) \
233 --with-gxx-include-dir=/usr/include/c++ \
234 --disable-__cxa_atexit \
235 --enable-target-optspace \
239 $(SOFT_FLOAT_CONFIG_OPTION) \
240 $(EXTRA_GCC_CONFIG_OPTIONS));
241 touch $(GCC_BUILD_DIR3)/.configured
243 $(GCC_BUILD_DIR3)/.compiled: $(GCC_BUILD_DIR3)/.configured
244 PATH=$(TARGET_PATH) \
245 $(MAKE) $(TARGET_GCC_ARGS) -C $(GCC_BUILD_DIR3) all
246 touch $(GCC_BUILD_DIR3)/.compiled
248 $(TARGET_DIR)/usr/bin/gcc: $(GCC_BUILD_DIR3)/.compiled
249 PATH=$(TARGET_PATH) \
250 $(MAKE) DESTDIR=$(TARGET_DIR) -C $(GCC_BUILD_DIR3) install
251 # Remove broken specs file (cross compile flag is set).
252 rm -f $(TARGET_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
253 -(cd $(TARGET_DIR)/bin; find -type f | xargs $(STRIP) > /dev/null 2>&1)
254 -(cd $(TARGET_DIR)/usr/bin; find -type f | xargs $(STRIP) > /dev/null 2>&1)
255 -(cd $(TARGET_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION); $(STRIP) cc1 cc1plus collect2 > /dev/null 2>&1)
256 -(cd $(TARGET_DIR)/usr/lib; $(STRIP) libstdc++.so.*.*.* > /dev/null 2>&1)
257 -(cd $(TARGET_DIR)/lib; $(STRIP) libgcc_s.so.*.*.* > /dev/null 2>&1)
259 rm -f $(TARGET_DIR)/usr/lib/*.la*
260 #rm -rf $(TARGET_DIR)/share/locale $(TARGET_DIR)/usr/info \
261 # $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/doc
262 # Work around problem of missing syslimits.h
263 cp -f $(STAGING_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/include/syslimits.h $(TARGET_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/include/
264 # These are in /lib, so...
265 #rm -rf $(TARGET_DIR)/usr/lib/libgcc_s.so*
266 #touch -c $(TARGET_DIR)/usr/bin/gcc
268 gcc_target: uclibc_target binutils_target $(TARGET_DIR)/usr/bin/gcc
271 rm -rf $(GCC_BUILD_DIR3)
272 rm -f $(TARGET_DIR)/bin/$(REAL_GNU_TARGET_NAME)*
275 rm -rf $(GCC_BUILD_DIR3)