Add support to build an ARM toolchain.
[ipfire-2.x.git] / lfs / gcc
1 ###############################################################################
2 #                                                                             #
3 # IPFire.org - A linux based firewall                                         #
4 # Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
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 3 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               #
14 # GNU 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, see <http://www.gnu.org/licenses/>.       #
18 #                                                                             #
19 ###############################################################################
20
21 ###############################################################################
22 # Definitions
23 ###############################################################################
24
25 include Config
26
27 ifeq "$(MACHINE)" "arm"
28         VER = 4.1.2
29 else
30         VER = 4.0.4
31 endif
32
33 THISAPP    = gcc-$(VER)
34 DL_FILE    = $(THISAPP).tar.bz2
35 DL_FROM    = $(URL_IPFIRE)
36 DIR_APP    = $(DIR_SRC)/$(THISAPP)
37 CFLAGS     =
38 CXXFLAGS   =
39 TARGET_PATH = /opt/$(MACHINE)-uClibc/bin:$(PATH)
40
41 # Normal build or /tools build.
42 #
43 ifeq "$(ROOT)" ""
44 ifeq "$(INST)" "1"
45   TARGET = $(DIR_INFO)/$(THISAPP)-install1
46   EXTRA_CONFIG = --prefix=/opt/$(MACHINE)-uClibc \
47                 --build=$(MACHINE)-pc-linux-gnu \
48                 --host=$(MACHINE)-pc-linux-gnu \
49                 --target=$(MACHINE)-linux-uclibc \
50                 --enable-languages=c \
51                 --with-sysroot=$(DIR_SRC)/uClibc_dev \
52                 --disable-__cxa_atexit \
53                 --enable-target-optspace \
54                 --with-gnu-ld \
55                 --disable-shared \
56                 --enable-threads \
57                 --enable-multilib \
58                 --disable-nls
59   EXTRA_MAKE = 
60   EXTRA_INSTALL = 
61 else
62 ifeq "$(INST)" "2"
63   TARGET = $(DIR_INFO)/$(THISAPP)-install2
64   EXTRA_CONFIG = --prefix=/opt/$(MACHINE)-uClibc \
65                 --build=$(MACHINE)-pc-linux-gnu \
66                 --host=$(MACHINE)-pc-linux-gnu \
67                 --target=$(MACHINE)-linux-uclibc \
68                 --enable-languages=c,c++ \
69                 --with-sysroot=$(DIR_SRC)/uClibc_dev \
70                 --disable-__cxa_atexit \
71                 --enable-target-optspace \
72                 --with-gnu-ld \
73                 --enable-shared \
74                 --disable-nls \
75                 --enable-threads \
76                 --enable-multilib
77   EXTRA_MAKE = 
78   EXTRA_INSTALL = 
79 else
80   TARGET = $(DIR_INFO)/$(THISAPP)
81   EXTRA_CONFIG = --prefix=/usr \
82                 --libexecdir=/usr/lib \
83                 --enable-shared \
84                 --enable-threads=posix \
85                 --enable-__cxa_atexit \
86                 --enable-clocale=gnu \
87                 --enable-languages=c,c++ \
88                 --disable-nls
89   EXTRA_MAKE =
90   EXTRA_INSTALL =
91 endif
92 endif
93 else
94 ifeq "$(PASS)" "1"
95   TARGET = $(DIR_INFO)/$(THISAPP)-tools1
96   EXTRA_CONFIG = --prefix=/tools \
97                 --with-local-prefix=/tools \
98                 --disable-nls \
99                 --enable-shared \
100                 --enable-languages=c \
101                 --disable-bootstrap
102   EXTRA_MAKE = 
103   #bootstrap BOOT_LDFLAGS="-static"
104   EXTRA_INSTALL = 
105 else
106   TARGET = $(DIR_INFO)/$(THISAPP)-tools2
107   EXTRA_CONFIG = --prefix=/tools \
108                 --with-local-prefix=/tools \
109                 --enable-clocale=gnu \
110                 --enable-shared \
111                 --enable-threads=posix \
112                 --enable-__cxa_atexit \
113                 --enable-languages=c,c++ \
114                 --disable-libstdcxx-pch
115   EXTRA_MAKE = 
116   EXTRA_INSTALL = 
117 endif
118 endif
119
120 ifeq "$(MACHINE)" "arm"
121         EXTRA_CONFIG += \
122                 --build=$(BUILDTARGET) \
123                 --host=$(BUILDTARGET) \
124                 --target=$(BUILDTARGET) \
125                 --with-float=soft \
126                 --disable-libmudflap \
127                 --disable-libssp \
128                 --disable-libgomp \
129                 --enable-threads=posix \
130                 --enable-long-long \
131                 --enable-c99 \
132                 --enable-__cxa_atexit \
133                 --disable-multilib
134 endif
135
136 export XCFLAGS = $(CFLAGS)
137 export TCFLAGS = $(CFLAGS)
138
139 ###############################################################################
140 # Top-level Rules
141 ###############################################################################
142 objects = $(DL_FILE)
143
144 $(DL_FILE) = $(DL_FROM)/$(DL_FILE)
145
146 ifeq "$(MACHINE)" "arm"
147         $(DL_FILE)_MD5 = a4a3eb15c96030906d8494959eeda23c
148 else
149         $(DL_FILE)_MD5 = 8970debbc55bea85ee80961d733080f0
150 endif
151
152 install : $(TARGET)
153
154 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
155
156 download :$(patsubst %,$(DIR_DL)/%,$(objects))
157
158 md5 : $(subst %,%_MD5,$(objects))
159
160 ###############################################################################
161 # Downloading, checking, md5sum
162 ###############################################################################
163
164 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
165         @$(CHECK)
166
167 $(patsubst %,$(DIR_DL)/%,$(objects)) :
168         @$(LOAD)
169
170 $(subst %,%_MD5,$(objects)) :
171         @$(MD5)
172
173 ###############################################################################
174 # Installation Details
175 ###############################################################################
176
177 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
178         @$(PREBUILD)
179         @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && tar jxf $(DIR_DL)/$(DL_FILE)
180         @mkdir $(DIR_SRC)/gcc-build
181
182         cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/gcc-4.1.2-gcc_eh.patch
183         cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/gcc-4.1.2-arm-linux-soft-float.patch
184
185 ifeq "$(ROOT)" ""
186 ifeq "$(INST)" "1"
187         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc-uclibc-conf.patch
188         cd $(DIR_SRC)/gcc-build && $(DIR_APP)/configure $(EXTRA_CONFIG)
189         cd $(DIR_SRC)/gcc-build && PATH=$(TARGET_PATH) make $(MAKETUNING) all-gcc
190         cd $(DIR_SRC)/gcc-build && PATH=$(TARGET_PATH) make install-gcc
191         cd /opt/$(MACHINE)-uClibc/bin && for i in `ls -w1 $(MACHINE)-linux-uclibc-*`; do \
192                 ln -svf $$i $(MACHINE)-linux-`echo $$i | cut -c 19-`; \
193         done
194         ln -svf $(MACHINE)-linux-uclibc /opt/$(MACHINE)-uClibc/$(MACHINE)-linux
195         ln -svf gcc /opt/$(MACHINE)-uClibc/$(MACHINE)-linux-uclibc/bin/cc
196 else
197 ifeq "$(INST)" "2"
198         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc-uclibc-conf.patch
199         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc-uclibc-locale.patch
200         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc-libstdc++-pic.patch
201         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/gcc-sdk-libstdc++-includes.patch
202         ln -snf ../include /opt/$(MACHINE)-uClibc/$(MACHINE)-linux-uclibc/sys-include
203         cd $(DIR_SRC)/gcc-build && $(DIR_APP)/configure $(EXTRA_CONFIG)
204         cd $(DIR_SRC)/gcc-build && PATH=$(TARGET_PATH) make $(MAKETUNING) $(EXTRA_MAKE)
205         cd $(DIR_SRC)/gcc-build && PATH=$(TARGET_PATH) make install $(EXTRA_INSTALL)
206         cp -f /opt/$(MACHINE)-uClibc/lib/libgcc_s.so /lib
207         cd /lib && ln -sf libgcc_s.so libgcc_s.so.1
208 else
209         cd $(DIR_APP) && sed -i 's/install_to_$$(INSTALL_DEST) //' libiberty/Makefile.in
210         cd $(DIR_APP) && sed -i 's/^XCFLAGS =$$/& -fomit-frame-pointer/' gcc/Makefile.in
211         cd $(DIR_APP) && sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
212         cd $(DIR_APP) && sed -i 's/@have_mktemp_command@/yes/' gcc/gccbug.in
213
214         cd $(DIR_SRC)/gcc-build && $(DIR_APP)/configure $(EXTRA_CONFIG)
215         cd $(DIR_SRC)/gcc-build && make $(MAKETUNING) $(EXTRA_MAKE)
216         cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
217         ln -sfv ../usr/bin/cpp /lib
218         ln -sfv gcc /usr/bin/cc
219 endif
220 endif
221 else
222 ifeq "$(PASS)" "1"
223         cd $(DIR_SRC)/gcc-build && $(DIR_APP)/configure $(EXTRA_CONFIG)
224         cd $(DIR_SRC)/gcc-build && make $(MAKETUNING) $(EXTRA_MAKE)
225         cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
226         ln -sfv gcc /tools/bin/cc
227         ln -sf ccache $(ROOT)/usr/local/bin/$(BUILDTARGET)-gcc
228         ln -sf ccache $(ROOT)/usr/local/bin/$(BUILDTARGET)-g++
229         ln -sf ccache $(ROOT)/usr/local/bin/$(BUILDTARGET)-cc
230 else
231         cd $(DIR_APP) && cp -v gcc/Makefile.in{,.orig}
232         cd $(DIR_APP) && sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
233         cd $(DIR_APP) && cp -v gcc/Makefile.in{,.tmp}
234         cd $(DIR_APP) && sed 's/^XCFLAGS =$\/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \
235                                 > gcc/Makefile.in
236         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/$(THISAPP)-specs-1.patch
237         cd $(DIR_SRC)/gcc-build && $(DIR_APP)/configure $(EXTRA_CONFIG)
238         cd $(DIR_SRC)/gcc-build && make $(MAKETUNING) $(EXTRA_MAKE)
239         cd $(DIR_SRC)/gcc-build && make $(EXTRA_INSTALL) install
240 endif
241 endif
242         @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build
243         @$(POSTBUILD)