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