gcc-glibc compiles on both SPARC and i386
[akaros.git] / tools / compilers / gcc-glibc / Makefile
1 # Defines where to install the toolchain
2 -include Makelocal
3
4 ifndef RAMP_INSTDIR
5 ifndef X86_INSTDIR
6 busted: 
7         @echo "You need to setup either a RAMP_INSTDIR or X86_INSTDIR to point to where you want the tools installed. The best way to do this is to create a 'Makelocal' file in the current directory and put it in there."
8 endif
9 endif 
10
11 BINUTILS_VERSION := 2.18
12 GCC_VERSION := 4.3.2
13 GLIBC_VERSION := 2.11.1
14
15 BUILDDIR ?= $(shell pwd)/
16 ROSDIR ?= $(BUILDDIR)/../../../
17 DESTDIR ?= /
18
19 # Configuration parameters for make-ramp
20 RAMP_ARCH := sparc
21 RAMP_BINARY_PREFIX := $(RAMP_ARCH)-ros-
22 RAMP_GCC_BUILD_FLAGS := --with-cpu=v8
23 RAMP_CFLAGS :=
24
25 # Configuration parameters for x86
26 X86_ARCH := i686
27 X86_BINARY_PREFIX := $(X86_ARCH)-ros-
28 X86_GCC_BUILD_FLAGS := 
29 X86_CFLAGS := -march=i486
30
31 all:
32         @echo "You need to run one of the following commands, "
33         @echo "depending on which version of the cross compiler you are trying to generate:"
34         @echo "  make ramp"
35         @echo "  make x86"
36         @echo "  make ramp-revert"
37         @echo "  make x86-revert"
38         @echo "  make ramp-uninstall"
39         @echo "  make x86-uninstall"
40         @echo "  make clean"
41
42 ramp:
43         export LD_LIBRARY_PATH=; \
44         export DESTDIR=$(DESTDIR);\
45         export INSTDIR=$(RAMP_INSTDIR);\
46         export PATH=$(DESTDIR)$(RAMP_INSTDIR)/bin:$(PATH);\
47         export ARCH=$(RAMP_ARCH);\
48         export ARCH_CFLAGS=$(RAMP_CFLAGS);\
49         export ROS_ARCH_DIR=$(RAMP_ARCH);\
50         export BINARY_PREFIX=$(RAMP_BINARY_PREFIX);\
51         export GCC_BUILD_FLAGS=$(RAMP_GCC_BUILD_FLAGS);\
52         $(MAKE) make-all
53
54 x86:
55         $(MAKE) .glibc-patch
56         export LD_LIBRARY_PATH=; \
57         export DESTDIR=$(DESTDIR);\
58         export INSTDIR=$(X86_INSTDIR);\
59         export PATH=$(DESTDIR)$(X86_INSTDIR)/bin:$(PATH);\
60         export ARCH=$(X86_ARCH);\
61         export ARCH_CFLAGS=$(X86_CFLAGS);\
62         export ROS_ARCH_DIR=i386;\
63         export BINARY_PREFIX=$(X86_BINARY_PREFIX);\
64         export GCC_BUILD_FLAGS=$(X86_GCC_BUILD_FLAGS);\
65         $(MAKE) make-all
66
67 make-all:
68         $(MAKE) .glibc-patch
69         $(MAKE) .$(BINARY_PREFIX)binutils-make
70         $(MAKE) .$(BINARY_PREFIX)binutils-install
71         $(MAKE) .$(BINARY_PREFIX)ros-headers-install
72         $(MAKE) .$(BINARY_PREFIX)glibc-headers-install
73         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-make
74         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
75         $(MAKE) .$(BINARY_PREFIX)glibc-make
76         $(MAKE) .$(BINARY_PREFIX)glibc-install
77         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-make
78         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-install
79         mkdir -p $(ROSDIR)/fs/$(ARCH)/lib
80         cp -r $(INSTDIR)/$(ARCH)-ros/lib/* $(ROSDIR)/fs/$(ARCH)/lib
81
82 ramp-uninstall:
83         -rm -rf $(RAMP_INSTDIR)
84
85 x86-uninstall:
86         -rm -rf $(X86_INSTDIR)
87
88 ramp-revert: 
89         rm -rf $(RAMP_INSTDIR)
90         cp -r $(RAMP_BINARY_PREFIX)install.bak $(RAMP_INSTDIR)
91
92 x86-revert: 
93         rm -rf $(X86_INSTDIR)
94         cp -r $(X86_BINARY_PREFIX)install.bak $(X86_INSTDIR)
95
96 clean:
97         rm -rf binutils-$(BINUTILS_VERSION) 
98         rm -rf gcc-$(GCC_VERSION) 
99         rm -rf glibc-$(GLIBC_VERSION) 
100         rm -rf *-builddir
101         rm -rf .*-ros-*-configure
102         rm -rf *$(BINARY_PREFIX)install.bak
103
104 binutils-clean:
105         cd $(BINARY_PREFIX)binutils-builddir; \
106         make clean
107
108 gcc-clean:
109         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
110         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
111         make clean
112
113 glibc-clean:
114         cd $(BINARY_PREFIX)glibc-headers-builddir; \
115         cd $(BINARY_PREFIX)glibc-builddir; \
116         make clean
117
118 binutils-$(BINUTILS_VERSION):
119         rm -rf binutils-$(BINUTILS_VERSION);
120         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
121         patch -p0 < binutils-$(BINUTILS_VERSION)-ros.patch
122
123 gcc-$(GCC_VERSION):
124         rm -rf gcc-$(GCC_VERSION)
125         tar -zxf gcc-$(GCC_VERSION).tar.gz
126         patch -p0 < gcc-$(GCC_VERSION)-ros.patch
127         cd gcc-$(GCC_VERSION)/libstdc++-v3; \
128         autoconf
129         
130         cd gcc-$(GCC_VERSION); \
131         tar -zxf ../mpfr-2.3.2.tar.gz; \
132         mv mpfr* mpfr
133         
134         cd gcc-$(GCC_VERSION); \
135         tar -zxf ../gmp-4.2.4.tar.gz; \
136         mv gmp* gmp
137
138 glibc-$(GLIBC_VERSION): 
139         rm -rf glibc-$(GLIBC_VERSION)
140         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
141         rm glibc-$(GLIBC_VERSION)/sysdeps/sparc/sparc32/elf/start.S
142         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
143         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/____longjmp_chk.S
144         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/init-first.c
145         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/sysdep.h
146         $(MAKE) .glibc-patch
147
148 .glibc-patch: glibc-$(GLIBC_VERSION)
149         cd glibc-$(GLIBC_VERSION); \
150         diff -ruB --unidirectional-new-file \
151              ../glibc-$(GLIBC_VERSION) \
152              ../glibc-$(GLIBC_VERSION)-ros \
153              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
154              | patch -p2 
155
156 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
157         rm -rf $@
158         cp -R binutils-$(BINUTILS_VERSION) $@
159
160 $(BINARY_PREFIX)glibc-headers-builddir: glibc-$(GLIBC_VERSION)
161         rm -rf $@
162         mkdir -p $@
163
164 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
165         rm -rf $@
166         mkdir -p $@
167         
168 $(BINARY_PREFIX)glibc-builddir: glibc-$(GLIBC_VERSION)
169         rm -rf $@
170         mkdir -p $@
171
172 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
173         rm -rf $@
174         mkdir -p $@
175         
176 .$(BINARY_PREFIX)binutils-configure: 
177         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
178         cd $(BINARY_PREFIX)binutils-builddir; \
179         ./configure --enable-shared \
180                     --disable-multilib \
181                     --disable-nls \
182                     --target=$(ARCH)-ros \
183                     --prefix=$(INSTDIR) \
184                     --includedir=$(INSTDIR)/include \
185                     --disable-werror;
186         touch $@
187
188 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
189         cd $(BINARY_PREFIX)binutils-builddir; \
190         make -j
191
192 .$(BINARY_PREFIX)binutils-install:
193         cd $(BINARY_PREFIX)binutils-builddir; \
194         make -j install
195
196 .$(BINARY_PREFIX)glibc-headers-configure:
197         $(MAKE) $(BINARY_PREFIX)glibc-headers-builddir
198         cd $(BINARY_PREFIX)glibc-headers-builddir; \
199         ../glibc-$(GLIBC_VERSION)/configure \
200                   --host=$(ARCH)-ros \
201                   --enable-hacker-mode \
202                   --enable-shared \
203                   --disable-nls \
204                   --with-elf \
205                   --with-tls \
206                   --with-__thread \
207                   --prefix=$(INSTDIR)/$(ARCH)-ros \
208                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
209                   libc_cv_forced_unwind=yes \
210                   libc_cv_c_cleanup=yes;
211         touch $@
212
213 .$(BINARY_PREFIX)glibc-headers-install: .$(BINARY_PREFIX)glibc-headers-configure
214         cd $(BINARY_PREFIX)glibc-headers-builddir; \
215         make -j install-headers; \
216         mkdir -p $(INSTDIR)/$(ARCH)-ros/include/gnu; \
217         echo > $(INSTDIR)/$(ARCH)-ros/include/gnu/stubs.h; \
218         cp bits/stdio_lim.h $(INSTDIR)/$(ARCH)-ros/include/bits/
219
220 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
221         mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include/arch
222         cp -r $(ROSDIR)/kern/include/ros \
223            $(INSTDIR)/$(ARCH)-ros/sys-include/
224         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/* \
225            $(INSTDIR)/$(ARCH)-ros/sys-include/arch/
226
227 .$(BINARY_PREFIX)gcc-stage1-configure: 
228         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
229         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
230         ../gcc-$(GCC_VERSION)/configure \
231                 --enable-languages=c \
232                 --enable-shared \
233                 --disable-checking \
234                 --disable-werror \
235                 --disable-multilib \
236                 --disable-libmudflap \
237                 --disable-libssp \
238                 --disable-libgomp \
239                 --disable-nls \
240                 --program-prefix=$(BINARY_PREFIX) \
241                 --target=$(ARCH)-ros \
242                 --prefix=$(INSTDIR) \
243                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
244                 $(GCC_BUILD_FLAGS);
245         touch $@
246
247 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
248         # Put the - in front of make because it actually fails and
249         # we don't want the whole make process to fail.
250         # It appears to still work though since this is just stage 1 of compiling
251         # Should really look into fixing this though...
252         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
253         make -j inhibit_libc=true cross-compiling=yes
254
255 .$(BINARY_PREFIX)gcc-stage1-install: 
256         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
257         make -j install
258         #-ln -vs libgcc.a `$(BINARY_PREFIX)gcc -print-libgcc-file-name | \
259         #                 sed 's/libgcc/&_eh/'`
260
261 .$(BINARY_PREFIX)glibc-configure: 
262         $(MAKE) $(BINARY_PREFIX)glibc-builddir
263         cd $(BINARY_PREFIX)glibc-builddir; \
264         ../glibc-$(GLIBC_VERSION)/configure \
265                   --host=$(ARCH)-ros \
266                   --enable-hacker-mode \
267                   --enable-shared \
268                   --with-elf \
269                   --with-tls \
270                   --disable-nls \
271                   --with-__thread \
272                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
273                   --prefix=$(INSTDIR)/$(ARCH)-ros \
274                   libc_cv_forced_unwind=yes \
275                   libc_cv_c_cleanup=yes \
276                   CFLAGS="$(ARCH_CFLAGS) -O2 -pipe";
277         touch $@
278
279 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
280         cd $(BINARY_PREFIX)glibc-builddir; \
281         make -j
282
283 .$(BINARY_PREFIX)glibc-install: 
284         cd $(BINARY_PREFIX)glibc-builddir; \
285         make -j install
286
287 .$(BINARY_PREFIX)gcc-stage2-configure:
288         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
289         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
290         ../gcc-$(GCC_VERSION)/configure \
291                   --enable-shared \
292                   --disable-multilib \
293                   --disable-nls \
294                   --program-prefix=$(BINARY_PREFIX) \
295                   --target=$(ARCH)-ros \
296                   --prefix=$(INSTDIR) \
297                   --enable-languages=c,c++ \
298                   $(GCC_BUILD_FLAGS) \
299                   --with-tls \
300                   --with-__thread \
301                   --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
302                   --disable-werror;
303         touch $@
304
305 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
306         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
307         make -j
308
309 .$(BINARY_PREFIX)gcc-stage2-install:
310         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
311         make -j install
312
313 patches:
314         mv gcc-$(GCC_VERSION)/gmp .
315         mv gcc-$(GCC_VERSION)/mpfr .
316         rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache
317         mv gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new
318         tar -zxf gcc-$(GCC_VERSION).tar.gz
319         -diff -ruN gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new \
320               > gcc-$(GCC_VERSION)-ros.patch
321         rm -rf gcc-$(GCC_VERSION)
322         mv gcc-$(GCC_VERSION).new gcc-$(GCC_VERSION)
323         mv gmp gcc-$(GCC_VERSION)
324         mv mpfr gcc-$(GCC_VERSION)
325         
326         mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
327         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
328         -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
329               > binutils-$(BINUTILS_VERSION)-ros.patch
330         rm -rf binutils-$(BINUTILS_VERSION)
331         mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
332