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 ($(GCC_SNAP_DATE
),)
21 GCC_OFFICIAL_VER
:=$(GCC_VERSION
)
22 GCC_SITE
:=http
://ftp.gnu.org
/gnu
/gcc
/gcc-
$(GCC_VERSION
)
23 #GCC_SITE:=ftp://ftp.ibiblio.org/pub/mirrors/gnu/ftp/gnu/gcc/gcc-$(GCC_OFFICIAL_VER)
25 GCC_OFFICIAL_VER
:=$(GCC_VERSION
)-$(GCC_SNAP_DATE
)
26 GCC_SITE
:=ftp
://sources.redhat.com
/pub
/gcc
/snapshots
/$(GCC_OFFICIAL_VER
)
29 GCC_SOURCE
:=gcc-
$(GCC_OFFICIAL_VER
).
tar.bz2
30 GCC_DIR
:=$(TOOL_BUILD_DIR
)/gcc-
$(GCC_OFFICIAL_VER
)
32 GCC_STRIP_HOST_BINARIES
:=false
34 #############################################################
36 # Setup some initial stuff
38 #############################################################
42 ifeq ($(BR2_INSTALL_LIBSTDCPP
),y
)
43 TARGET_LANGUAGES
:=$(TARGET_LANGUAGES
),c
++
46 ifeq ($(BR2_INSTALL_LIBGCJ
),y
)
47 TARGET_LANGUAGES
:=$(TARGET_LANGUAGES
),java
50 ifeq ($(BR2_INSTALL_OBJC
),y
)
51 TARGET_LANGUAGES
:=$(TARGET_LANGUAGES
),objc
54 ifeq ($(BR2_INSTALL_FORTRAN
),y
)
55 TARGET_LANGUAGES
:=$(TARGET_LANGUAGES
),fortran
58 #############################################################
60 # build the first pass gcc compiler
62 #############################################################
63 GCC_BUILD_DIR1
:=$(TOOL_BUILD_DIR
)/gcc-
$(GCC_VERSION
)-initial
65 $(DL_DIR
)/$(GCC_SOURCE
):
67 $(WGET
) -P
$(DL_DIR
) $(GCC_SITE
)/$(GCC_SOURCE
)
69 gcc-unpacked
: $(GCC_DIR
)/.unpacked
70 $(GCC_DIR
)/.unpacked
: $(DL_DIR
)/$(GCC_SOURCE
)
71 mkdir
-p
$(TOOL_BUILD_DIR
)
72 $(GCC_CAT
) $(DL_DIR
)/$(GCC_SOURCE
) |
tar -C
$(TOOL_BUILD_DIR
) $(TAR_OPTIONS
) -
73 $(CONFIG_UPDATE
) $(GCC_DIR
)
74 touch
$(GCC_DIR
)/.unpacked
76 gcc-patched
: $(GCC_DIR
)/.patched
77 $(GCC_DIR
)/.patched
: $(GCC_DIR
)/.unpacked
78 # Apply any files named gcc-*.patch from the source directory to gcc
79 ifeq ($(GCC_SNAP_DATE
),)
80 toolchain
/patch-kernel.sh
$(GCC_DIR
) toolchain
/gcc
/$(GCC_VERSION
) \
*.patch
82 ifneq ($(wildcard toolchain
/gcc
/$(GCC_OFFICIAL_VER
)),)
83 toolchain
/patch-kernel.sh
$(GCC_DIR
) toolchain
/gcc
/$(GCC_OFFICIAL_VER
) \
*.patch
85 toolchain
/patch-kernel.sh
$(GCC_DIR
) toolchain
/gcc
/$(GCC_VERSION
) \
*.patch
89 # Note: The soft float situation has improved considerably with gcc 3.4.x.
90 # We can dispense with the custom spec files, as well as libfloat for the arm case.
91 # However, we still need a patch for arm. There's a similar patch for gcc 3.3.x
92 # which needs to be integrated so we can kill of libfloat for good, except for
93 # anyone (?) who might still be using gcc 2.95. mjn3
94 ifeq ($(BR2_SOFT_FLOAT
),y
)
95 ifeq ("$(strip $(ARCH))","arm")
96 toolchain
/patch-kernel.sh
$(GCC_DIR
) toolchain
/gcc
/$(GCC_VERSION
) arm-softfloat.patch.conditional
98 ifeq ("$(strip $(ARCH))","armeb")
99 toolchain
/patch-kernel.sh
$(GCC_DIR
) toolchain
/gcc
/$(GCC_VERSION
) arm-softfloat.patch.conditional
101 # Not yet updated to 3.4.1.
102 #ifeq ("$(strip $(ARCH))","i386")
103 #toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc i386-gcc-soft-float.patch
106 touch
$(GCC_DIR
)/.patched
108 # The --without-headers option stopped working with gcc 3.0 and has never been
109 # fixed, so we need to actually have working C library header files prior to
110 # the step or libgcc will not build...
112 $(GCC_BUILD_DIR1
)/.configured
: $(GCC_DIR
)/.patched
113 mkdir
-p
$(GCC_BUILD_DIR1
)
114 (cd
$(GCC_BUILD_DIR1
); PATH
=$(TARGET_PATH
) \
116 $(GCC_DIR
)/configure \
117 --prefix=$(STAGING_DIR
) \
118 --build
=$(GNU_HOST_NAME
) \
119 --host
=$(GNU_HOST_NAME
) \
120 --target
=$(REAL_GNU_TARGET_NAME
) \
121 --enable-languages
=c \
123 --with-sysroot
=$(TOOL_BUILD_DIR
)/uClibc_dev
/ \
124 --disable-__cxa_atexit \
125 --enable-target-optspace \
130 $(SOFT_FLOAT_CONFIG_OPTION
) \
131 $(GCC_WITH_CPU
) $(GCC_WITH_ARCH
) $(GCC_WITH_TUNE
) \
132 $(EXTRA_GCC_CONFIG_OPTIONS
));
133 touch
$(GCC_BUILD_DIR1
)/.configured
135 $(GCC_BUILD_DIR1
)/.compiled
: $(GCC_BUILD_DIR1
)/.configured
136 PATH
=$(TARGET_PATH
) $(MAKE
) -C
$(GCC_BUILD_DIR1
) all-gcc
137 touch
$(GCC_BUILD_DIR1
)/.compiled
139 $(STAGING_DIR
)/bin
/$(REAL_GNU_TARGET_NAME
)-gcc
: $(GCC_BUILD_DIR1
)/.compiled
140 PATH
=$(TARGET_PATH
) $(MAKE
) -C
$(GCC_BUILD_DIR1
) install-gcc
141 #rm -f $(STAGING_DIR)/bin/gccbug $(STAGING_DIR)/bin/gcov
142 #rm -rf $(STAGING_DIR)/info $(STAGING_DIR)/man $(STAGING_DIR)/share/doc $(STAGING_DIR)/share/locale
144 gcc_initial
: uclibc-configured binutils
$(STAGING_DIR
)/bin
/$(REAL_GNU_TARGET_NAME
)-gcc
147 rm -rf
$(GCC_BUILD_DIR1
)
149 gcc_initial-dirclean
:
150 rm -rf
$(GCC_BUILD_DIR1
) $(GCC_DIR
)
152 #############################################################
154 # second pass compiler build. Build the compiler targeting
155 # the newly built shared uClibc library.
157 #############################################################
159 # Sigh... I had to rework things because using --with-gxx-include-dir
160 # causes issues with include dir search order for g++. This seems to
161 # have something to do with "path translations" and possibly doesn't
162 # affect gcc-target. However, I haven't tested gcc-target yet so no
165 GCC_BUILD_DIR2
:=$(TOOL_BUILD_DIR
)/gcc-
$(GCC_VERSION
)-final
166 $(GCC_BUILD_DIR2
)/.configured
: $(GCC_DIR
)/.patched
$(STAGING_DIR
)/lib
/libc.a
167 mkdir
-p
$(GCC_BUILD_DIR2
)
168 # Important! Required for limits.h to be fixed.
169 ln
-snf ..
/include $(STAGING_DIR
)/$(REAL_GNU_TARGET_NAME
)/sys-include
170 (cd
$(GCC_BUILD_DIR2
); PATH
=$(TARGET_PATH
) \
172 $(GCC_DIR
)/configure \
173 --prefix=$(STAGING_DIR
) \
174 --build
=$(GNU_HOST_NAME
) \
175 --host
=$(GNU_HOST_NAME
) \
176 --target
=$(REAL_GNU_TARGET_NAME
) \
177 --enable-languages
=$(TARGET_LANGUAGES
) \
179 --disable-__cxa_atexit \
180 --enable-target-optspace \
185 $(SOFT_FLOAT_CONFIG_OPTION
) \
186 $(GCC_WITH_CPU
) $(GCC_WITH_ARCH
) $(GCC_WITH_TUNE
) \
187 $(GCC_USE_SJLJ_EXCEPTIONS
) \
188 $(EXTRA_GCC_CONFIG_OPTIONS
));
189 touch
$(GCC_BUILD_DIR2
)/.configured
191 $(GCC_BUILD_DIR2
)/.compiled
: $(GCC_BUILD_DIR2
)/.configured
192 PATH
=$(TARGET_PATH
) $(MAKE
) -C
$(GCC_BUILD_DIR2
) all
193 touch
$(GCC_BUILD_DIR2
)/.compiled
195 $(GCC_BUILD_DIR2
)/.installed
: $(GCC_BUILD_DIR2
)/.compiled
196 PATH
=$(TARGET_PATH
) $(MAKE
) -C
$(GCC_BUILD_DIR2
) install
197 if
[ -d
"$(STAGING_DIR)/lib64" ] ; then \
198 if
[ ! -e
"$(STAGING_DIR)/lib" ] ; then \
199 mkdir
"$(STAGING_DIR)/lib" ; \
201 mv
"$(STAGING_DIR)/lib64/"* "$(STAGING_DIR)/lib/" ; \
202 rmdir
"$(STAGING_DIR)/lib64" ; \
204 # Strip the host binaries
205 ifeq ($(GCC_STRIP_HOST_BINARIES
),true
)
206 -strip --strip-all
-R .note
-R .comment
$(STAGING_DIR
)/bin
/*
208 # Make sure we have 'cc'.
209 if
[ ! -e
$(STAGING_DIR
)/bin
/$(REAL_GNU_TARGET_NAME
)-cc ] ; then \
210 ln
-snf
$(REAL_GNU_TARGET_NAME
)-gcc \
211 $(STAGING_DIR
)/bin
/$(REAL_GNU_TARGET_NAME
)-cc ; \
213 if
[ ! -e
$(STAGING_DIR
)/$(REAL_GNU_TARGET_NAME
)/bin
/cc ] ; then \
214 ln
-snf gcc
$(STAGING_DIR
)/$(REAL_GNU_TARGET_NAME
)/bin
/cc ; \
216 # Set up the symlinks to enable lying about target name.
218 (cd
$(STAGING_DIR
); \
219 ln
-snf
$(REAL_GNU_TARGET_NAME
) $(GNU_TARGET_NAME
); \
221 for app in
$(REAL_GNU_TARGET_NAME
)-* ; do \
223 $(GNU_TARGET_NAME
)$${app
##$(REAL_GNU_TARGET_NAME)}; \
227 # Now for the ugly 3.3.x soft float hack...
229 ifeq ($(BR2_SOFT_FLOAT
),y
)
230 ifeq ($(findstring 3.3.
,$(GCC_VERSION
)),3.3.
)
231 # Make sure we have a soft float specs file for this arch
232 if
[ ! -f toolchain
/gcc
/$(GCC_VERSION
)/specs-
$(ARCH
)-soft-float
] ; then \
233 echo soft float configured but no specs file for this arch
; \
236 # Replace specs file with one that defaults to soft float mode.
237 if
[ ! -f
$(STAGING_DIR
)/lib
/gcc-lib
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)/specs
] ; then \
238 echo staging
dir specs file is missing
; \
241 cp toolchain
/gcc
/$(GCC_VERSION
)/specs-
$(ARCH
)-soft-float
$(STAGING_DIR
)/lib
/gcc-lib
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)/specs
245 # Ok... that's enough of that.
247 touch
$(GCC_BUILD_DIR2
)/.installed
249 $(TARGET_DIR
)/lib
/libgcc_s.so
.1: $(GCC_BUILD_DIR2
)/.installed
250 # These are in /lib, so...
251 rm -rf
$(TARGET_DIR
)/usr
/lib
/libgcc_s
*.so
*
252 -cp
-a
$(STAGING_DIR
)/$(REAL_GNU_TARGET_NAME
)/lib
/libgcc_s
* $(TARGET_DIR
)/lib
/
253 ifeq ($(BR2_INSTALL_LIBSTDCPP
),y
)
254 -cp
-a
$(STAGING_DIR
)/lib
/libstdc
++.so
* $(TARGET_DIR
)/lib
/
256 ifeq ($(BR2_INSTALL_LIBGCJ
),y
)
257 -cp
-a
$(STAGING_DIR
)/lib
/libgcj.so
* $(TARGET_DIR
)/lib
/
258 -cp
-a
$(STAGING_DIR
)/lib
/lib-org-w3c-dom.so
* $(TARGET_DIR
)/lib
/
259 -cp
-a
$(STAGING_DIR
)/lib
/lib-org-xml-sax.so
* $(TARGET_DIR
)/lib
/
260 -mkdir
-p
$(TARGET_DIR
)/usr
/lib
/security
261 -cp
-a
$(STAGING_DIR
)/usr
/lib
/security
/libgcj.security
$(TARGET_DIR
)/usr
/lib
/security
/
262 -cp
-a
$(STAGING_DIR
)/usr
/lib
/security
/classpath.security
$(TARGET_DIR
)/usr
/lib
/security
/
264 touch
-c
$(TARGET_DIR
)/lib
/libgcc_s.so
.1
266 gcc
: uclibc-configured binutils gcc_initial
$(LIBFLOAT_TARGET
) uclibc \
267 $(TARGET_DIR
)/lib
/libgcc_s.so
.1 $(GCC_BUILD_DIR2
)/.installed
$(GCC_TARGETS
)
269 gcc-source
: $(DL_DIR
)/$(GCC_SOURCE
)
272 rm -rf
$(GCC_BUILD_DIR2
)
273 for prog in
cpp gcc gcc-
[0-9]* protoize unprotoize gcov gccbug
cc; do \
274 rm -f
$(STAGING_DIR
)/bin
/$(REAL_GNU_TARGET_NAME
)-$$prog \
275 rm -f
$(STAGING_DIR
)/bin
/$(GNU_TARGET_NAME
)-$$prog; \
278 gcc-dirclean
: gcc_initial-dirclean
279 rm -rf
$(GCC_BUILD_DIR2
)
281 #############################################################
283 # Next build target gcc compiler
285 #############################################################
286 GCC_BUILD_DIR3
:=$(BUILD_DIR
)/gcc-
$(GCC_VERSION
)-target
288 $(GCC_BUILD_DIR3
)/.configured
: $(GCC_BUILD_DIR2
)/.installed
289 mkdir
-p
$(GCC_BUILD_DIR3
)
290 (cd
$(GCC_BUILD_DIR3
); PATH
=$(TARGET_PATH
) \
291 $(GCC_DIR
)/configure \
293 --build
=$(GNU_HOST_NAME
) \
294 --host
=$(REAL_GNU_TARGET_NAME
) \
295 --target
=$(REAL_GNU_TARGET_NAME
) \
296 --enable-languages
=$(TARGET_LANGUAGES
) \
298 --with-gxx-include-dir
=/usr
/include/c
++ \
299 --disable-__cxa_atexit \
300 --enable-target-optspace \
305 $(SOFT_FLOAT_CONFIG_OPTION
) \
306 $(GCC_WITH_CPU
) $(GCC_WITH_ARCH
) $(GCC_WITH_TUNE
) \
307 $(GCC_USE_SJLJ_EXCEPTIONS
) \
308 $(EXTRA_GCC_CONFIG_OPTIONS
));
309 touch
$(GCC_BUILD_DIR3
)/.configured
311 $(GCC_BUILD_DIR3
)/.compiled
: $(GCC_BUILD_DIR3
)/.configured
312 PATH
=$(TARGET_PATH
) \
313 $(MAKE
) $(TARGET_GCC_ARGS
) -C
$(GCC_BUILD_DIR3
) all
314 touch
$(GCC_BUILD_DIR3
)/.compiled
317 # gcc-lib dir changes names to gcc with 3.4.mumble
319 ifeq ($(findstring 3.4.
,$(GCC_VERSION
)),3.4.
)
320 GCC_LIB_SUBDIR
=lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
322 GCC_LIB_SUBDIR
=lib
/gcc-lib
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
324 # sigh... we need to find a better way
325 ifeq ($(findstring 4.0.
,$(GCC_VERSION
)),4.0.
)
326 GCC_LIB_SUBDIR
=lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
328 ifeq ($(findstring 4.1.
,$(GCC_VERSION
)),4.1.
)
329 GCC_LIB_SUBDIR
=lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
331 ifeq ($(findstring 4.2.
,$(GCC_VERSION
)),4.2.
)
332 GCC_LIB_SUBDIR
=lib
/gcc
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)
335 $(TARGET_DIR
)/usr
/bin
/gcc
: $(GCC_BUILD_DIR3
)/.compiled
336 PATH
=$(TARGET_PATH
) \
337 $(MAKE
) DESTDIR
=$(TARGET_DIR
) -C
$(GCC_BUILD_DIR3
) install
338 # Remove broken specs file (cross compile flag is set).
339 rm -f
$(TARGET_DIR
)/usr
/$(GCC_LIB_SUBDIR
)/specs
341 # Now for the ugly 3.3.x soft float hack...
343 ifeq ($(BR2_SOFT_FLOAT
),y
)
344 ifeq ($(findstring 3.3.
,$(GCC_VERSION
)),3.3.
)
345 # Add a specs file that defaults to soft float mode.
346 cp toolchain
/gcc
/$(GCC_VERSION
)/specs-
$(ARCH
)-soft-float
$(TARGET_DIR
)/usr
/lib
/gcc-lib
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)/specs
347 # Make sure gcc does not think we are cross compiling
348 $(SED
) "s/^1/0/;" $(TARGET_DIR
)/usr
/lib
/gcc-lib
/$(REAL_GNU_TARGET_NAME
)/$(GCC_VERSION
)/specs
352 # Ok... that's enough of that.
354 -(cd
$(TARGET_DIR
)/bin
; find
-type f | xargs
$(STRIP
) > /dev
/null
2>&1)
355 -(cd
$(TARGET_DIR
)/usr
/bin
; find
-type f | xargs
$(STRIP
) > /dev
/null
2>&1)
356 -(cd
$(TARGET_DIR
)/usr
/$(GCC_LIB_SUBDIR
); $(STRIP
) cc1 cc1plus collect2
> /dev
/null
2>&1)
357 -(cd
$(TARGET_DIR
)/usr
/lib
; $(STRIP
) libstdc
++.so.
*.
*.
* > /dev
/null
2>&1)
358 -(cd
$(TARGET_DIR
)/lib
; $(STRIP
) libgcc_s
*.so.
*.
*.
* > /dev
/null
2>&1)
360 rm -f
$(TARGET_DIR
)/usr
/lib
/*.la
*
361 #rm -rf $(TARGET_DIR)/share/locale $(TARGET_DIR)/usr/info \
362 # $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/doc
363 # Work around problem of missing syslimits.h
364 if
[ ! -f
$(TARGET_DIR
)/usr
/$(GCC_LIB_SUBDIR
)/include/syslimits.h
] ; then \
365 echo
"warning: working around missing syslimits.h" ; \
366 cp
-f
$(STAGING_DIR
)/$(GCC_LIB_SUBDIR
)/include/syslimits.h \
367 $(TARGET_DIR
)/usr
/$(GCC_LIB_SUBDIR
)/include/ ; \
369 # Make sure we have 'cc'.
370 if
[ ! -e
$(TARGET_DIR
)/usr
/bin
/cc ] ; then \
371 ln
-snf gcc
$(TARGET_DIR
)/usr
/bin
/cc ; \
373 # These are in /lib, so...
374 #rm -rf $(TARGET_DIR)/usr/lib/libgcc_s*.so*
375 #touch -c $(TARGET_DIR)/usr/bin/gcc
377 gcc_target
: uclibc_target binutils_target
$(TARGET_DIR
)/usr
/bin
/gcc
380 rm -rf
$(GCC_BUILD_DIR3
)
381 rm -f
$(TARGET_DIR
)/usr
/bin
/$(REAL_GNU_TARGET_NAME
)*
384 rm -rf
$(GCC_BUILD_DIR3
)