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