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
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)
27 GCC_OFFICIAL_VER
:=$(GCC_VERSION
)-$(GCC_SNAP_DATE
)
28 GCC_SITE
:=ftp
://sources.redhat.com
/pub
/gcc
/snapshots
/$(GCC_OFFICIAL_VER
)
31 GCC_SOURCE
:=gcc-
$(GCC_OFFICIAL_VER
).
tar.bz2
32 GCC_DIR
:=$(TOOL_BUILD_DIR
)/gcc-
$(GCC_OFFICIAL_VER
)
34 GCC_STRIP_HOST_BINARIES
:=true
36 #############################################################
38 # Setup some initial stuff
40 #############################################################
44 ifeq ($(INSTALL_LIBSTDCPP
),true
)
45 TARGET_LANGUAGES
:=c
,c
++
50 #############################################################
52 # build the first pass gcc compiler
54 #############################################################
55 GCC_BUILD_DIR1
:=$(TOOL_BUILD_DIR
)/gcc-
$(GCC_VERSION
)-initial
57 $(DL_DIR
)/$(GCC_SOURCE
):
59 # $(WGET) -P $(DL_DIR) $(GCC_SITE)/$(GCC_SOURCE)
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
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
74 ifneq ($(wildcard toolchain
/gcc
/$(GCC_OFFICIAL_VER
)),)
75 $(SOURCE_DIR
)/patch-kernel.sh
$(GCC_DIR
) $(SOURCE_DIR
) gcc
/$(GCC_OFFICIAL_VER
)\
*.patch
77 $(SOURCE_DIR
)/patch-kernel.sh
$(GCC_DIR
) $(SOURCE_DIR
) gcc
/$(GCC_VERSION
)\
*.patch
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
90 ifeq ("$(strip $(ARCH))","armeb")
91 $(SOURCE_DIR
)/patch-kernel.sh
$(GCC_DIR
) toolchain
/gcc
/$(GCC_VERSION
) arm-softfloat.patch.conditional
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
98 touch
$(GCC_DIR
)/.patched
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...
104 $(GCC_BUILD_DIR1
)/.configured
: $(GCC_DIR
)/.patched
105 mkdir
-p
$(GCC_BUILD_DIR1
)
106 (cd
$(GCC_BUILD_DIR1
); PATH
=$(TARGET_PATH
) \
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 \
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
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
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
136 gcc_initial
: uclibc-configured binutils
$(STAGING_DIR
)/bin
/$(REAL_GNU_TARGET_NAME
)-gcc
139 rm -rf
$(GCC_BUILD_DIR1
)
141 gcc_initial-dirclean
:
142 rm -rf
$(GCC_BUILD_DIR1
) $(GCC_DIR
)
144 #############################################################
146 # second pass compiler build. Build the compiler targeting
147 # the newly built shared uClibc library.
149 #############################################################
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
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
) \
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 \
173 $(GCC_SHARED_LIBGCC
) \
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
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
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" ; \
193 mv
"$(STAGING_DIR)/lib64/"* "$(STAGING_DIR)/lib/" ; \
194 rmdir
"$(STAGING_DIR)/lib64" ; \
196 # Strip the host binaries
197 ifeq ($(GCC_STRIP_HOST_BINARIES
),true
)
198 -strip --strip-all
-R .note
-R .comment
$(STAGING_DIR
)/bin
/*
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 ; \
205 if
[ ! -e
$(STAGING_DIR
)/$(REAL_GNU_TARGET_NAME
)/bin
/cc ] ; then \
206 ln
-snf gcc
$(STAGING_DIR
)/$(REAL_GNU_TARGET_NAME
)/bin
/cc ; \
208 # Set up the symlinks to enable lying about target name.
210 (cd
$(STAGING_DIR
); \
211 ln
-snf
$(REAL_GNU_TARGET_NAME
) $(GNU_TARGET_NAME
); \
213 for app in
$(REAL_GNU_TARGET_NAME
)-* ; do \
215 $(GNU_TARGET_NAME
)$${app
##$(REAL_GNU_TARGET_NAME)}; \
219 # Now for the ugly 3.3.x soft float hack...
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
; \
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
; \
233 cp toolchain
/gcc
/$(GCC_VERSION
)/specs-
$(ARCH
)-soft-float
$(STAGING_DIR
)/lib
/gcc-lib
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)/specs
237 # Ok... that's enough of that.
239 touch
$(GCC_BUILD_DIR2
)/.installed
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
/
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
/
256 touch
-c
$(TARGET_DIR
)/lib
/libgcc_s.so
.1
258 gcc
: uclibc-configured binutils gcc_initial
$(LIBFLOAT_TARGET
) uclibc \
259 $(GCC_BUILD_DIR2
)/.installed
$(GCC_TARGETS
)
261 gcc-source
: $(DL_DIR
)/$(GCC_SOURCE
)
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; \
270 gcc-dirclean
: gcc_initial-dirclean
271 rm -rf
$(GCC_BUILD_DIR2
)
273 #############################################################
275 # Next build target gcc compiler
277 #############################################################
278 GCC_BUILD_DIR3
:=$(BUILD_DIR
)/gcc-
$(GCC_VERSION
)-target
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 \
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 \
293 $(GCC_SHARED_LIBGCC
) \
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
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
309 # gcc-lib dir changes names to gcc with 3.4.mumble
311 ifeq ($(findstring 3.4.
,$(GCC_VERSION
)),3.4.
)
312 GCC_LIB_SUBDIR
=lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
314 GCC_LIB_SUBDIR
=lib
/gcc-lib
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
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
)
320 ifeq ($(findstring 4.1.
,$(GCC_VERSION
)),4.1.
)
321 GCC_LIB_SUBDIR
=lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
323 ifeq ($(findstring 4.2.
,$(GCC_VERSION
)),4.2.
)
324 GCC_LIB_SUBDIR
=lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
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
333 # Now for the ugly 3.3.x soft float hack...
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
344 # Ok... that's enough of that.
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)
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/ ; \
361 # Make sure we have 'cc'.
362 if
[ ! -e
$(TARGET_DIR
)/usr
/bin
/cc ] ; then \
363 ln
-snf gcc
$(TARGET_DIR
)/usr
/bin
/cc ; \
365 # These are in /lib, so...
366 #rm -rf $(TARGET_DIR)/usr/lib/libgcc_s*.so*
367 #touch -c $(TARGET_DIR)/usr/bin/gcc
369 gcc_target
: uclibc_target binutils_target
$(TARGET_DIR
)/usr
/bin
/gcc
372 rm -rf
$(GCC_BUILD_DIR3
)
373 rm -f
$(TARGET_DIR
)/usr
/bin
/$(REAL_GNU_TARGET_NAME
)*
376 rm -rf
$(GCC_BUILD_DIR3
)