add patch from #196
[openwrt.git] / openwrt / toolchain / gcc / Makefile
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 # Copyright (C) 2005 Felix Fietkau <openwrt@nbd.name>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 include $(TOPDIR)/rules.mk
22
23 GCC_VERSION:=$(strip $(GCC_VERSION))
24
25 #GCC_SITE:=ftp://ftp.gnu.org/gnu/gcc/releases/gcc-$(GCC_VERSION)
26 GCC_SITE:=ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-$(GCC_VERSION) \
27 http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-$(GCC_VERSION)
28
29 GCC_SOURCE:=gcc-$(GCC_VERSION).tar.bz2
30 GCC_DIR:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)
31 GCC_CAT:=bzcat
32 GCC_STRIP_HOST_BINARIES:=true
33
34 #############################################################
35 #
36 # Setup some initial stuff
37 #
38 #############################################################
39
40 ifeq ($(BR2_INSTALL_LIBGCJ),y)
41 TARGET_LANGUAGES:=c,c++,java
42 else
43 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
44 TARGET_LANGUAGES:=c,c++
45 else
46 TARGET_LANGUAGES:=c
47 endif
48 endif
49
50 #############################################################
51 #
52 # build the first pass gcc compiler
53 #
54 #############################################################
55
56 GCC_BUILD_DIR1:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-initial
57
58 $(DL_DIR)/$(GCC_SOURCE):
59 mkdir -p $(DL_DIR)
60 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(GCC_SOURCE) x $(GCC_SITE)
61
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) $(TAR_OPTIONS) -
65 touch $(GCC_DIR)/.unpacked
66
67 $(GCC_DIR)/.patched: $(GCC_DIR)/.unpacked
68 # Apply any files named gcc-*.patch from the source directory to gcc
69 $(SCRIPT_DIR)/patch-kernel.sh $(GCC_DIR) ./$(GCC_VERSION) \*.patch
70 # Note: The soft float situation has improved considerably with gcc 3.4.x.
71 # We can dispense with the custom spec files, as well as libfloat for the arm case.
72 # However, we still need a patch for arm. There's a similar patch for gcc 3.3.x
73 # which needs to be integrated so we can kill of libfloat for good.
74 ifeq ($(BR2_SOFT_FLOAT),y)
75 ifeq ("$(strip $(ARCH))","arm")
76 $(SCRIPT_DIR)/patch-kernel.sh $(GCC_DIR) ./$(GCC_VERSION) arm-softfloat.patch.conditional
77 endif
78 ifeq ("$(strip $(ARCH))","armeb")
79 $(SCRIPT_DIR)/patch-kernel.sh $(GCC_DIR) ./$(GCC_VERSION) arm-softfloat.patch.conditional
80 endif
81 endif
82 $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(GCC_DIR)/gcc/version.c
83 $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:https://dev.openwrt.org/>\2,' $(GCC_DIR)/gcc/version.c
84 touch $(GCC_DIR)/.patched
85
86 # The --without-headers option stopped working with gcc 3.0 and has never been
87 # # fixed, so we need to actually have working C library header files prior to
88 # # the step or libgcc will not build...
89
90 $(GCC_BUILD_DIR1)/.configured: $(GCC_DIR)/.patched
91 mkdir -p $(GCC_BUILD_DIR1)
92 (cd $(GCC_BUILD_DIR1); rm -f config.cache; PATH=$(TARGET_PATH) \
93 $(GCC_DIR)/configure \
94 --prefix=$(STAGING_DIR) \
95 --build=$(GNU_HOST_NAME) \
96 --host=$(GNU_HOST_NAME) \
97 --target=$(REAL_GNU_TARGET_NAME) \
98 --enable-languages=c \
99 --disable-shared \
100 --with-sysroot=$(TOOL_BUILD_DIR)/uClibc_dev/ \
101 --disable-__cxa_atexit \
102 --enable-target-optspace \
103 --with-gnu-ld \
104 $(DISABLE_NLS) \
105 $(MULTILIB) \
106 $(SOFT_FLOAT_CONFIG_OPTION) \
107 $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
108 $(EXTRA_GCC_CONFIG_OPTIONS));
109 touch $(GCC_BUILD_DIR1)/.configured
110
111 $(GCC_BUILD_DIR1)/.compiled: $(GCC_BUILD_DIR1)/.configured
112 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) all-gcc
113 touch $(GCC_BUILD_DIR1)/.compiled
114
115 $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc: $(GCC_BUILD_DIR1)/.compiled
116 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) install-gcc
117
118 #############################################################
119 #
120 # second pass compiler build. Build the compiler targeting
121 # the newly built shared uClibc library.
122 #
123 #############################################################
124 #
125 # Sigh... I had to rework things because using --with-gxx-include-dir
126 # causes issues with include dir search order for g++. This seems to
127 # have something to do with "path translations" and possibly doesn't
128 # affect gcc-target. However, I haven't tested gcc-target yet so no
129 # guarantees. mjn3
130
131 GCC_BUILD_DIR2:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-final
132 $(GCC_BUILD_DIR2)/.configured: $(GCC_DIR)/.patched $(STAGING_DIR)/lib/libc.a
133 mkdir -p $(GCC_BUILD_DIR2)
134 # Important! Required for limits.h to be fixed.
135 rm -rf $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
136 ln -sf ../include $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
137 rm -rf $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib
138 ln -sf ../lib $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib
139 (cd $(GCC_BUILD_DIR2); rm -f config.cache; PATH=$(TARGET_PATH) \
140 $(GCC_DIR)/configure \
141 --prefix=$(STAGING_DIR) \
142 --build=$(GNU_HOST_NAME) \
143 --host=$(GNU_HOST_NAME) \
144 --target=$(REAL_GNU_TARGET_NAME) \
145 --enable-languages=$(TARGET_LANGUAGES) \
146 --enable-shared \
147 --disable-__cxa_atexit \
148 --enable-target-optspace \
149 --with-gnu-ld \
150 $(DISABLE_NLS) \
151 $(MULTILIB) \
152 $(SOFT_FLOAT_CONFIG_OPTION) \
153 $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
154 $(GCC_USE_SJLJ_EXCEPTIONS) \
155 $(EXTRA_GCC_CONFIG_OPTIONS));
156 touch $(GCC_BUILD_DIR2)/.configured
157
158 $(GCC_BUILD_DIR2)/.compiled: $(GCC_BUILD_DIR2)/.configured
159 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) all
160 touch $(GCC_BUILD_DIR2)/.compiled
161
162 gcc-install: $(GCC_BUILD_DIR2)/.compiled
163 PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) install
164 echo $(GCC_VERSION) > $(STAGING_DIR)/gcc_version
165 # Set up the symlinks to enable lying about target name.
166 set -e; \
167 (cd $(STAGING_DIR); \
168 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
169 cd bin; \
170 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
171 ln -sf $${app} \
172 $(GNU_TARGET_NAME)$${app##$(REAL_GNU_TARGET_NAME)}; \
173 done; \
174 );
175 #
176 # Now for the ugly 3.3.x soft float hack...
177 #
178 ifeq ($(BR2_SOFT_FLOAT),y)
179 ifeq ($(findstring 3.3.,$(GCC_VERSION)),3.3.)
180 # Make sure we have a soft float specs file for this arch
181 if [ ! -f ./$(GCC_VERSION)/specs-$(ARCH)-soft-float ] ; then \
182 echo soft float configured but no specs file for this arch ; \
183 /bin/false ; \
184 fi;
185 # Replace specs file with one that defaults to soft float mode.
186 if [ ! -f $(STAGING_DIR)/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs ] ; then \
187 echo staging dir specs file is missing ; \
188 /bin/false ; \
189 fi;
190 $(CP) ./$(GCC_VERSION)/specs-$(ARCH)-soft-float $(STAGING_DIR)/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
191 endif
192 endif
193 # We do another ugly hack here because the standard behaviour is
194 # to include a reference to libgcc.so.1 in all binaries. For flash space
195 # saving, we change the specs file to link in a static libgcc here.
196 if [ -f $(STAGING_DIR)/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs ] ; then \
197 patch -d $(STAGING_DIR)/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/ -p0 < ./$(GCC_VERSION)/static-libgcc.patch.conditional ; \
198 fi;
199
200 source: $(DL_DIR)/$(GCC_SOURCE)
201 prepare: $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc
202 compile: gcc-install
203 install:
204 clean: gcc-clean
205 rm -rf $(GCC_DIR)
206 rm -rf $(GCC_BUILD_DIR1)
207 rm -rf $(GCC_BUILD_DIR2)
208 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc*
209 rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
This page took 0.047049 seconds and 5 git commands to generate.