User can set how long sys_block() sleeps
[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/parlib/include/* \
234            $(INSTDIR)/$(ARCH)-ros/sys-include/
235         cp -r $(ROSDIR)/user/pthread/*.h \
236            $(INSTDIR)/$(ARCH)-ros/sys-include/
237         rm -rf $(INSTDIR)/$(ARCH)-ros/sys-include/arch
238         ln -s $(ARCH) $(INSTDIR)/$(ARCH)-ros/sys-include/arch 
239
240 .$(BINARY_PREFIX)gcc-stage1-configure: 
241         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
242         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
243         ../gcc-$(GCC_VERSION)/configure \
244                 --enable-languages=c \
245                 --enable-shared \
246                 --disable-checking \
247                 --disable-werror \
248                 --disable-multilib \
249                 --disable-libmudflap \
250                 --disable-libssp \
251                 --disable-libgomp \
252                 --disable-nls \
253                 --program-prefix=$(BINARY_PREFIX) \
254                 --target=$(ARCH)-ros \
255                 --prefix=$(INSTDIR) \
256                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
257                 $(GCC_BUILD_FLAGS);
258         touch $@
259
260 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
261         # Put the - in front of make because it actually fails and
262         # we don't want the whole make process to fail.
263         # It appears to still work though since this is just stage 1 of compiling
264         # Should really look into fixing this though...
265         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
266         make -j $(MAKE_JOBS) inhibit_libc=true cross-compiling=yes
267
268 .$(BINARY_PREFIX)gcc-stage1-install: 
269         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
270         make -j $(MAKE_JOBS) install
271         #-ln -vs libgcc.a `$(BINARY_PREFIX)gcc -print-libgcc-file-name | \
272         #                 sed 's/libgcc/&_eh/'`
273
274 .$(BINARY_PREFIX)glibc-configure: 
275         $(MAKE) $(BINARY_PREFIX)glibc-builddir
276         cd $(BINARY_PREFIX)glibc-builddir; \
277         ../glibc-$(GLIBC_VERSION)/configure \
278                   --host=$(ARCH)-ros \
279                   --enable-hacker-mode \
280                   --enable-shared \
281                   --with-elf \
282                   --with-tls \
283                   --disable-nls \
284                   --with-__thread \
285                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
286                   --prefix=$(INSTDIR)/$(ARCH)-ros \
287                   libc_cv_forced_unwind=yes \
288                   libc_cv_c_cleanup=yes \
289                   CFLAGS="$(ARCH_CFLAGS) -g -fpermissive -O2 -pipe";
290         touch $@
291
292 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
293         cd $(BINARY_PREFIX)glibc-builddir; \
294         make -j $(MAKE_JOBS)
295
296 .$(BINARY_PREFIX)glibc-install: 
297         cd $(BINARY_PREFIX)glibc-builddir; \
298         make -j $(MAKE_JOBS) install
299
300 .$(BINARY_PREFIX)gcc-stage2-configure:
301         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
302         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
303         ../gcc-$(GCC_VERSION)/configure \
304                   --enable-shared \
305                   --disable-multilib \
306                   --disable-nls \
307                   --program-prefix=$(BINARY_PREFIX) \
308                   --target=$(ARCH)-ros \
309                   --prefix=$(INSTDIR) \
310                   --enable-languages=c,c++ \
311                   $(GCC_BUILD_FLAGS) \
312                   --with-tls \
313                   --with-__thread \
314                   --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
315                   --disable-werror;
316         touch $@
317
318 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
319         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
320         make -j $(MAKE_JOBS)
321
322 .$(BINARY_PREFIX)gcc-stage2-install:
323         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
324         make -j $(MAKE_JOBS) install
325
326 patches:
327         mv gcc-$(GCC_VERSION)/gmp .
328         mv gcc-$(GCC_VERSION)/mpfr .
329         rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache
330         mv gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new
331         tar -zxf gcc-$(GCC_VERSION).tar.gz
332         -diff -ruN gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new \
333               > gcc-$(GCC_VERSION)-ros.patch
334         rm -rf gcc-$(GCC_VERSION)
335         mv gcc-$(GCC_VERSION).new gcc-$(GCC_VERSION)
336         mv gmp gcc-$(GCC_VERSION)
337         mv mpfr gcc-$(GCC_VERSION)
338         
339         mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
340         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
341         -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
342               > binutils-$(BINUTILS_VERSION)-ros.patch
343         rm -rf binutils-$(BINUTILS_VERSION)
344         mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
345