Made glibc compile and run x86
[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=$(X86_ARCH);\
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         
128         cd gcc-$(GCC_VERSION); \
129         tar -zxf ../mpfr-2.3.2.tar.gz; \
130         mv mpfr* mpfr
131         
132         cd gcc-$(GCC_VERSION); \
133         tar -zxf ../gmp-4.2.4.tar.gz; \
134         mv gmp* gmp
135
136 glibc-$(GLIBC_VERSION): 
137         rm -rf glibc-$(GLIBC_VERSION)
138         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
139         rm glibc-$(GLIBC_VERSION)/sysdeps/sparc/sparc32/elf/start.S
140         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
141         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/____longjmp_chk.S
142         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/init-first.c
143         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/sysdep.h
144         $(MAKE) .glibc-patch
145
146 .glibc-patch: glibc-$(GLIBC_VERSION)
147         -cd glibc-$(GLIBC_VERSION); \
148         diff -ruB --unidirectional-new-file \
149              ../glibc-$(GLIBC_VERSION) \
150              ../glibc-$(GLIBC_VERSION)-ros \
151              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
152              | patch -p2 
153
154 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
155         rm -rf $@
156         cp -R binutils-$(BINUTILS_VERSION) $@
157
158 $(BINARY_PREFIX)glibc-headers-builddir: glibc-$(GLIBC_VERSION)
159         rm -rf $@
160         mkdir -p $@
161
162 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
163         rm -rf $@
164         mkdir -p $@
165         
166 $(BINARY_PREFIX)glibc-builddir: glibc-$(GLIBC_VERSION)
167         rm -rf $@
168         mkdir -p $@
169
170 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
171         rm -rf $@
172         mkdir -p $@
173         
174 .$(BINARY_PREFIX)binutils-configure: 
175         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
176         cd $(BINARY_PREFIX)binutils-builddir; \
177         ./configure --enable-shared \
178                     --disable-multilib \
179                     --disable-nls \
180                     --target=$(ARCH)-ros \
181                     --prefix=$(INSTDIR) \
182                     --includedir=$(INSTDIR)/include \
183                     --disable-werror;
184         touch $@
185
186 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
187         cd $(BINARY_PREFIX)binutils-builddir; \
188         make -j
189
190 .$(BINARY_PREFIX)binutils-install:
191         cd $(BINARY_PREFIX)binutils-builddir; \
192         make -j install
193
194 .$(BINARY_PREFIX)glibc-headers-configure:
195         $(MAKE) $(BINARY_PREFIX)glibc-headers-builddir
196         cd $(BINARY_PREFIX)glibc-headers-builddir; \
197         ../glibc-$(GLIBC_VERSION)/configure \
198                   --host=$(ARCH)-ros \
199                   --enable-hacker-mode \
200                   --enable-shared \
201                   --disable-nls \
202                   --with-elf \
203                   --with-tls \
204                   --with-__thread \
205                   --prefix=$(INSTDIR)/$(ARCH)-ros \
206                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
207                   libc_cv_forced_unwind=yes \
208                   libc_cv_c_cleanup=yes;
209         touch $@
210
211 .$(BINARY_PREFIX)glibc-headers-install: .$(BINARY_PREFIX)glibc-headers-configure
212         cd $(BINARY_PREFIX)glibc-headers-builddir; \
213         make -j install-headers; \
214         mkdir -p $(INSTDIR)/$(ARCH)-ros/include/gnu; \
215         echo > $(INSTDIR)/$(ARCH)-ros/include/gnu/stubs.h; \
216         cp bits/stdio_lim.h $(INSTDIR)/$(ARCH)-ros/include/bits/
217
218 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
219         mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include/arch
220         cp -r $(ROSDIR)/kern/include/ros \
221            $(INSTDIR)/$(ARCH)-ros/sys-include/
222         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/* \
223            $(INSTDIR)/$(ARCH)-ros/sys-include/arch/
224
225 .$(BINARY_PREFIX)gcc-stage1-configure: 
226         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
227         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
228         ../gcc-$(GCC_VERSION)/configure \
229                 --enable-languages=c \
230                 --enable-shared \
231                 --disable-checking \
232                 --disable-werror \
233                 --disable-multilib \
234                 --disable-libmudflap \
235                 --disable-libssp \
236                 --disable-libgomp \
237                 --disable-nls \
238                 --program-prefix=$(BINARY_PREFIX) \
239                 --target=$(ARCH)-ros \
240                 --prefix=$(INSTDIR) \
241                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
242                 $(GCC_BUILD_FLAGS);
243         touch $@
244
245 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
246         # Put the - in front of make because it actually fails and
247         # we don't want the whole make process to fail.
248         # It appears to still work though since this is just stage 1 of compiling
249         # Should really look into fixing this though...
250         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
251         make -j inhibit_libc=true cross-compiling=yes
252
253 .$(BINARY_PREFIX)gcc-stage1-install: 
254         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
255         make -j install
256         #-ln -vs libgcc.a `$(BINARY_PREFIX)gcc -print-libgcc-file-name | \
257         #                 sed 's/libgcc/&_eh/'`
258
259 .$(BINARY_PREFIX)glibc-configure: 
260         $(MAKE) $(BINARY_PREFIX)glibc-builddir
261         cd $(BINARY_PREFIX)glibc-builddir; \
262         ../glibc-$(GLIBC_VERSION)/configure \
263                   --host=$(ARCH)-ros \
264                   --enable-hacker-mode \
265                   --enable-shared \
266                   --with-elf \
267                   --with-tls \
268                   --disable-nls \
269                   --with-__thread \
270                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
271                   --prefix=$(INSTDIR)/$(ARCH)-ros \
272                   libc_cv_forced_unwind=yes \
273                   libc_cv_c_cleanup=yes \
274                   CFLAGS="$(ARCH_CFLAGS) -fpermissive -O2 -pipe";
275         touch $@
276
277 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
278         cd $(BINARY_PREFIX)glibc-builddir; \
279         make -j
280
281 .$(BINARY_PREFIX)glibc-install: 
282         cd $(BINARY_PREFIX)glibc-builddir; \
283         make -j install
284
285 .$(BINARY_PREFIX)gcc-stage2-configure:
286         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
287         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
288         ../gcc-$(GCC_VERSION)/configure \
289                   --enable-shared \
290                   --disable-multilib \
291                   --disable-nls \
292                   --program-prefix=$(BINARY_PREFIX) \
293                   --target=$(ARCH)-ros \
294                   --prefix=$(INSTDIR) \
295                   --enable-languages=c,c++ \
296                   $(GCC_BUILD_FLAGS) \
297                   --with-tls \
298                   --with-__thread \
299                   --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
300                   --disable-werror;
301         touch $@
302
303 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
304         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
305         make -j
306
307 .$(BINARY_PREFIX)gcc-stage2-install:
308         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
309         make -j install
310
311 patches:
312         mv gcc-$(GCC_VERSION)/gmp .
313         mv gcc-$(GCC_VERSION)/mpfr .
314         rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache
315         mv gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new
316         tar -zxf gcc-$(GCC_VERSION).tar.gz
317         -diff -ruN gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new \
318               > gcc-$(GCC_VERSION)-ros.patch
319         rm -rf gcc-$(GCC_VERSION)
320         mv gcc-$(GCC_VERSION).new gcc-$(GCC_VERSION)
321         mv gmp gcc-$(GCC_VERSION)
322         mv mpfr gcc-$(GCC_VERSION)
323         
324         mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
325         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
326         -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
327               > binutils-$(BINUTILS_VERSION)-ros.patch
328         rm -rf binutils-$(BINUTILS_VERSION)
329         mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
330