e37f20503fe95ebe5278791de2845e452ac0d9bc
[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 RISCV_INSTDIR
8 ifndef I686_INSTDIR
9 ifndef X86_64_INSTDIR
10 ifndef X86_64_NATIVE_INSTDIR
11 busted: 
12         @echo "You need to setup either a RISCV_INSTDIR, an I686_INSTDIR, or an X86_64_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
13 riscv: busted
14 i686: busted
15 x86_64: busted
16 x86_64-native: busted
17 endif
18 endif 
19 endif 
20 endif 
21
22 # Check to make sure that we have gawk installed on our system and not some
23 # other version of awk
24 AWK := $(shell awk -W version 2>&1 | head -n 1 | awk '{print $$1}')
25 ifneq ($(AWK),GNU)
26 $(error You need to have 'gawk' installed on your system!)
27 endif
28
29 # Check to make sure that we have the GMP, MPFR, and MPC libraries installed
30 GMP_OK := $(shell echo "int main() {return 0;}" | gcc -x c - -lgmp -lmpfr -lmpc -o /dev/null > /dev/null && echo OK)
31 ifneq ($(GMP_OK),OK)
32 $(error You need to have the libraries GMP, MPFR, and MPC installed on your system!)
33 endif
34
35 BINUTILS_VERSION := 2.24
36 GCC_VERSION := 4.9.2
37 GLIBC_VERSION := 2.14.1
38 GMP_VERSION := 5.1.3
39 MPFR_VERSION := 3.1.2
40 MPC_VERSION := 1.0.2
41
42 BUILDDIR ?= $(shell pwd)/
43 ROSDIR ?= $(BUILDDIR)/../../../
44 DESTDIR ?= /
45
46 # Configuration parameters for make-riscv
47 RISCV_ARCH := riscv
48 RISCV_BINARY_PREFIX := $(RISCV_ARCH)-ucb-akaros-
49 RISCV_SYSROOT := $(RISCV_INSTDIR)/$(RISCV_ARCH)-ucb-akaros/sysroot
50 RISCV_GLIBC_CONFIGURE_FLAGS := 
51 RISCV_GCC_BUILD_FLAGS := 
52 RISCV_CFLAGS :=
53
54 # Configuration parameters for x86
55 I686_ARCH := i686
56 I686_BINARY_PREFIX := $(I686_ARCH)-ucb-akaros-
57 I686_SYSROOT := $(I686_INSTDIR)/$(I686_ARCH)-ucb-akaros/sysroot
58 I686_GLIBC_CONFIGURE_FLAGS := 
59 I686_GCC_BUILD_FLAGS := 
60 I686_CFLAGS := -march=i486
61
62 # Configuration parameters for x86_64
63 X86_64_ARCH := x86_64
64 X86_64_BINARY_PREFIX := $(X86_64_ARCH)-ucb-akaros-
65 X86_64_SYSROOT := $(X86_64_INSTDIR)/$(X86_64_ARCH)-ucb-akaros/sysroot
66 X86_64_GLIBC_CONFIGURE_FLAGS := "--disable-multi-arch"
67 X86_64_GCC_BUILD_FLAGS := CFLAGS="-fPIC"
68 X86_64_CFLAGS :=
69
70 # Configuration parameters for x86_64-native
71 X86_64_NATIVE_ARCH := x86_64
72 X86_64_NATIVE_BINARY_PREFIX := 
73 X86_64_NATIVE_SYSROOT := $(X86_64_NATIVE_INSTDIR)
74 X86_64_NATIVE_GCC_BUILD_FLAGS := CFLAGS="-fPIC"
75 X86_64_NATIVE_CFLAGS :=
76
77 #If actually building the cross compiler, make sure that the akaros tree is
78 #properly configured for the architecture we are creating the cross compiler
79 #for.
80 ifneq (,$(filter riscv,$(MAKECMDGOALS)))
81 ifeq (,$(shell grep "CONFIG_RISCV=y" $(ROSDIR)/.config))
82 error: 
83         @echo "Akaros tree not configured for riscv"
84         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
85         @echo "e.g. cd \$$ROSDIR"
86         @echo "     make ARCH=riscv defconfig"
87         @false
88 riscv: error
89 endif
90 endif
91 ifneq (,$(filter i686,$(MAKECMDGOALS)))
92 ifeq (,$(shell grep "CONFIG_X86_32=y" $(ROSDIR)/.config))
93 error: 
94         @echo "Akaros tree not configured for i686"
95         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
96         @echo "e.g. cd \$$ROSDIR"
97         @echo "     make ARCH=x86 defconfig"
98         @false
99 i686: error
100 endif
101 endif
102 ifneq (,$(filter x86_64,$(MAKECMDGOALS)))
103 ifeq (,$(shell grep "CONFIG_X86_64=y" $(ROSDIR)/.config))
104 error: 
105         @echo "Akaros tree not configured for x86_64"
106         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
107         @echo "e.g. cd \$$ROSDIR"
108         @echo "     make ARCH=x86 defconfig"
109         @echo "     make ARCH=x86 menuconfig -> Set 64 bit option"
110         @false
111 x86_64: error
112 endif
113 endif
114 ifneq (,$(filter x86_64-native,$(MAKECMDGOALS)))
115 ifeq (,$(shell which x86_64-ucb-akaros-gcc))
116 error: 
117         @echo "No x86_64 Akaros cross-compiler installed in path"
118         @echo "Make sure you have built and installed the x86_64 cross-compiler using 'make x86_64'
119         @echo "before trying to build the crossed-native compiler.
120         @false
121 x86_64: error
122 endif
123 endif
124
125 all:
126         @echo "You need to run one of the following commands, "
127         @echo "depending on which version of the cross compiler you are trying to generate:"
128         @echo "  make riscv"
129         @echo "  make i686"
130         @echo "  make x86_64"
131         @echo "  make x86-64-native"
132         @echo "  make riscv-revert"
133         @echo "  make i686-revert"
134         @echo "  make x86_64-revert"
135         @echo "  make x86_64-native-revert"
136         @echo "  make riscv-uninstall"
137         @echo "  make i686-uninstall"
138         @echo "  make x86_64-uninstall"
139         @echo "  make x86_64-native-uninstall"
140         @echo "  make clean"
141
142 riscv:
143         export LD_LIBRARY_PATH=; \
144         export DESTDIR=$(DESTDIR);\
145         export INSTDIR=$(RISCV_INSTDIR);\
146         export SYSROOT=$(RISCV_SYSROOT);\
147         export PATH=$(DESTDIR)$(RISCV_INSTDIR)/bin:$(PATH);\
148         export ARCH=$(RISCV_ARCH);\
149         export ARCH_CFLAGS=$(RISCV_CFLAGS);\
150         export ROS_ARCH_DIR=$(RISCV_ARCH);\
151         export BINARY_PREFIX=$(RISCV_BINARY_PREFIX);\
152         export GLIBC_CONFIGURE_FLAGS=$(RISCV_GLIBC_CONFIGURE_FLAGS);\
153         export GCC_BUILD_FLAGS=$(RISCV_GCC_BUILD_FLAGS);\
154         $(MAKE) make-all
155
156 i686:
157         export LD_LIBRARY_PATH=; \
158         export DESTDIR=$(DESTDIR);\
159         export INSTDIR=$(I686_INSTDIR);\
160         export SYSROOT=$(I686_SYSROOT);\
161         export PATH=$(DESTDIR)$(I686_INSTDIR)/bin:$(PATH);\
162         export ARCH=$(I686_ARCH);\
163         export ARCH_CFLAGS=$(I686_CFLAGS);\
164         export ROS_ARCH_DIR=x86;\
165         export BINARY_PREFIX=$(I686_BINARY_PREFIX);\
166         export GLIBC_CONFIGURE_FLAGS=$(I686_GLIBC_CONFIGURE_FLAGS);\
167         export GCC_BUILD_FLAGS=$(I686_GCC_BUILD_FLAGS);\
168         $(MAKE) make-all
169
170 x86_64:
171         export LD_LIBRARY_PATH=; \
172         export DESTDIR=$(DESTDIR);\
173         export INSTDIR=$(X86_64_INSTDIR);\
174         export SYSROOT=$(X86_64_SYSROOT);\
175         export PATH=$(DESTDIR)$(X86_64_INSTDIR)/bin:$(PATH);\
176         export ARCH=$(X86_64_ARCH);\
177         export ARCH_CFLAGS=$(X86_64_CFLAGS);\
178         export ROS_ARCH_DIR=x86;\
179         export BINARY_PREFIX=$(X86_64_BINARY_PREFIX);\
180         export GLIBC_CONFIGURE_FLAGS=$(X86_64_GLIBC_CONFIGURE_FLAGS);\
181         export GCC_BUILD_FLAGS=$(X86_64_GCC_BUILD_FLAGS);\
182         $(MAKE) make-all
183
184 x86_64-native:
185         export NATIVE_BUILD=true; \
186         export LD_LIBRARY_PATH=; \
187         export DESTDIR=$(DESTDIR);\
188         export INSTDIR=$(X86_64_NATIVE_INSTDIR);\
189         export SYSROOT=$(X86_64_NATIVE_SYSROOT);\
190         export ARCH=$(X86_64_NATIVE_ARCH);\
191         export BINARY_PREFIX=$(X86_64_NATIVE_BINARY_PREFIX);\
192         export GCC_BUILD_FLAGS=$(X86_64_NATIVE_GCC_BUILD_FLAGS);\
193         export CXXROOT=$(shell dirname $(shell which $(X86_64_NATIVE_ARCH)-ucb-akaros-gcc))/..; \
194         $(MAKE) make-native-all
195
196 make-all: 
197         $(MAKE) .$(BINARY_PREFIX)binutils-install
198         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
199         $(MAKE) .$(BINARY_PREFIX)akaros-headers-install
200         $(MAKE) .$(BINARY_PREFIX)dummy-libs-install
201         $(MAKE) .$(BINARY_PREFIX)glibc-stage1-install
202         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-install
203         $(MAKE) .$(BINARY_PREFIX)glibc-stage2-install
204         $(MAKE) .$(BINARY_PREFIX)akaros-libs-install
205         $(MAKE) .$(BINARY_PREFIX)gcc-stage3-install
206         $(MAKE) .$(BINARY_PREFIX)gmp-install
207         $(MAKE) .$(BINARY_PREFIX)mpfr-install
208         $(MAKE) .$(BINARY_PREFIX)mpc-install
209
210 make-native-all:
211         $(MAKE) .$(BINARY_PREFIX)binutils-install
212         $(MAKE) .$(BINARY_PREFIX)gcc-stage3-install
213
214 riscv-uninstall:
215         -rm -rf $(RISCV_INSTDIR)
216
217 i686-uninstall:
218         -rm -rf $(I686_INSTDIR)
219
220 x86_64-uninstall:
221         -rm -rf $(X86_64_INSTDIR)
222
223 x86_64-native-uninstall:
224         -rm -rf $(X86_64_NATIVE_INSTDIR)
225
226 riscv-revert:
227         rm -rf $(RISCV_INSTDIR)
228         cp -r $(RISCV_BINARY_PREFIX)install.bak $(RISCV_INSTDIR)
229
230 i686-revert: 
231         rm -rf $(I686_INSTDIR)
232         cp -r $(I686_BINARY_PREFIX)install.bak $(I686_INSTDIR)
233
234 x86_64-revert: 
235         rm -rf $(X86_64_INSTDIR)
236         cp -r $(X86_64_BINARY_PREFIX)install.bak $(X86_64_INSTDIR)
237
238 x86_64-native-revert: 
239         rm -rf $(X86_64_NATIVE_INSTDIR)
240         cp -r $(X86_64_NATIVE_BINARY_PREFIX)install.bak $(X86_64_NATIVE_INSTDIR)
241
242 %.tar.bz2:
243         wget http://akaros.cs.berkeley.edu/xcc/$@
244
245 %.tar.gz:
246         wget http://akaros.cs.berkeley.edu/xcc/$@
247
248 #################################
249 ########### BINUTILS ############
250 #################################
251 binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
252         rm -rf binutils-$(BINUTILS_VERSION);
253         tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
254         patch -p0 < binutils-$(BINUTILS_VERSION)-akaros.patch
255         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
256
257 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
258         rm -rf $@
259         mkdir -p $@
260
261 native-binutils-configure:
262         cd $(BINARY_PREFIX)binutils-builddir; \
263         CFLAGS="-O2 -g -pipe" \
264         CXXFLAGS="-O2 -g -pipe" \
265         LDFLAGS="" \
266         ../binutils-$(BINUTILS_VERSION)/configure \
267                 --target=$(ARCH)-ucb-akaros \
268                 --host=$(ARCH)-ucb-akaros \
269                 --prefix=$(INSTDIR) \
270                 --disable-werror \
271                 --enable-ld=yes \
272                 --enable-gold=no \
273                 --with-pkgversion="akaros-repo" \
274                 --disable-multilib \
275                 --disable-nls
276
277 cross-binutils-configure:
278         cd $(BINARY_PREFIX)binutils-builddir; \
279         CFLAGS="-O2 -g -pipe" \
280         CXXFLAGS="-O2 -g -pipe" \
281         LDFLAGS="" \
282         ../binutils-$(BINUTILS_VERSION)/configure \
283                 --target=$(ARCH)-ucb-akaros \
284                 --prefix=$(INSTDIR) \
285                 --disable-werror \
286                 --enable-ld=yes \
287                 --enable-gold=no \
288                 --with-pkgversion="akaros-repo" \
289                 --disable-multilib \
290                 --disable-nls \
291                 --with-sysroot=$(SYSROOT)
292
293 .$(BINARY_PREFIX)binutils-configure: 
294         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
295         if [ "$(NATIVE_BUILD)" = "true" ]; then \
296                 $(MAKE) native-binutils-configure; \
297         else \
298                 $(MAKE) cross-binutils-configure; \
299         fi
300         echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
301         touch $@
302
303 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
304         cd $(BINARY_PREFIX)binutils-builddir; \
305         make -j $(MAKE_JOBS)
306
307 .$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
308         cd $(BINARY_PREFIX)binutils-builddir; \
309         make -j $(MAKE_JOBS) install
310
311 binutils-clean:
312         cd $(BINARY_PREFIX)binutils-builddir; \
313         make clean
314
315 #################################
316 ########## GCC Stage 1 ##########
317 #################################
318 .gcc-akaros-patch:
319         -cd gcc-$(GCC_VERSION); \
320         diff -ruB --unidirectional-new-file \
321              ../gcc-$(GCC_VERSION) \
322              ../gcc-$(GCC_VERSION)-akaros \
323              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
324              | patch -p2 
325
326 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
327         rm -rf gcc-$(GCC_VERSION)
328         tar -jxf gcc-$(GCC_VERSION).tar.bz2
329         $(MAKE) .gcc-akaros-patch
330         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
331
332 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
333         rm -rf $@
334         mkdir -p $@
335
336 .$(BINARY_PREFIX)gcc-stage1-configure: 
337         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
338         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
339         CFLAGS="-O2 -g -pipe" \
340         CXXFLAGS="-O2 -g -pipe" \
341         LDFLAGS="-lstdc++ -lm" \
342         ../gcc-$(GCC_VERSION)/configure \
343                 --target=$(ARCH)-ucb-akaros \
344                 --prefix=$(INSTDIR) \
345                 --with-local-prefix=$(SYSROOT) \
346                 --disable-mudflap \
347                 --with-sysroot=$(SYSROOT) \
348                 --with-newlib \
349                 --enable-threads=no \
350                 --enable-tls \
351                 --disable-shared \
352                 --with-pkgversion="akaros-repo" \
353                 --disable-__cxa_atexit \
354                 --with-ppl=no \
355                 --with-isl=no \
356                 --with-cloog=no \
357                 --with-libelf=no \
358                 --disable-lto \
359                 --disable-libgomp \
360                 --disable-mudflap \
361                 --disable-nls \
362                 --disable-multilib \
363                 --enable-languages=c \
364                 $(GCC_BUILD_FLAGS);
365         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
366         touch $@
367
368 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
369         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
370         make -j $(MAKE_JOBS) all-gcc;
371
372 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
373         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
374         make -j $(MAKE_JOBS) install-gcc;
375
376 #################################
377 ########## GCC Stage 2 ##########
378 #################################
379 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
380         rm -rf $@
381         mkdir -p $@
382
383 .$(BINARY_PREFIX)gcc-stage2-configure: 
384         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
385         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
386         CFLAGS="-O2 -g -pipe" \
387         CXXFLAGS="-O2 -g -pipe" \
388         LDFLAGS="-lstdc++ -lm" \
389         ../gcc-$(GCC_VERSION)/configure \
390                 --target=$(ARCH)-ucb-akaros \
391                 --prefix=$(INSTDIR) \
392                 --with-local-prefix=$(SYSROOT) \
393                 --disable-mudflap \
394                 --with-sysroot=$(SYSROOT) \
395                 --with-newlib \
396                 --enable-threads=no \
397                 --enable-tls \
398                 --disable-shared \
399                 --with-pkgversion="akaros-repo" \
400                 --disable-__cxa_atexit \
401                 --with-ppl=no \
402                 --with-sil=no \
403                 --with-cloog=no \
404                 --with-libelf=no \
405                 --disable-lto \
406                 --disable-libgomp \
407                 --disable-libmudflap \
408                 --disable-nls \
409                 --enable-languages=c \
410                 --disable-multilib \
411                 $(GCC_BUILD_FLAGS);
412         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
413         touch $@
414
415 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
416         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
417         make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
418                              all-gcc \
419                              all-target-libgcc;
420
421 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
422         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
423         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
424
425 ####################################
426 ######### AKAROS Headers ###########
427 ####################################
428 .$(BINARY_PREFIX)akaros-headers-install: $(ROSDIR)
429         rm -rf $(SYSROOT)/usr/include/*
430         mkdir -p $(SYSROOT)/usr/include
431         cp -r $(ROSDIR)/kern/include/ros \
432             $(SYSROOT)/usr/include/
433         rm -f $(SYSROOT)/usr/include/ros/arch
434         mkdir $(SYSROOT)/usr/include/ros/arch
435         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/ros/* \
436             $(SYSROOT)/usr/include/ros/arch/
437         cp -r $(ROSDIR)/user/parlib/include/* \
438             $(SYSROOT)/usr/include/
439         cp -r $(ROSDIR)/user/pthread/*.h \
440             $(SYSROOT)/usr/include/
441         rm -rf $(SYSROOT)/usr/include/arch
442         ln -s $(ROS_ARCH_DIR) $(SYSROOT)/usr/include/arch
443
444 #################################
445 ###### Dummy Libs Install #######
446 #################################
447 .$(BINARY_PREFIX)dummy-libs-install:
448         rm -rf $(SYSROOT)/lib/libparlib.a
449         rm -rf $(SYSROOT)/lib/libgcc_eh.a
450         mkdir -p $(SYSROOT)/lib
451         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/lib/libparlib.a
452         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/lib/libgcc_eh.a
453
454 #################################
455 ######### Glibc Stage 1 #########
456 #################################
457 .glibc-akaros-patch:
458         -cd glibc-$(GLIBC_VERSION); \
459         diff -ruB --unidirectional-new-file \
460              ../glibc-$(GLIBC_VERSION) \
461              ../glibc-$(GLIBC_VERSION)-ros \
462              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
463              | patch -p2 
464
465 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
466         rm -rf glibc-$(GLIBC_VERSION)
467         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
468         $(MAKE) .glibc-akaros-patch
469         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
470         rm glibc-$(GLIBC_VERSION)/sysdeps/riscv/elf/start.S
471         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
472         rm glibc-$(GLIBC_VERSION)/sysdeps/x86_64/elf/start.S
473
474 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
475         rm -rf $@
476         mkdir -p $@
477
478 .$(BINARY_PREFIX)glibc-stage1-configure: 
479         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
480         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
481         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -fpermissive -O2 -pipe" \
482         CC=$(ARCH)-ucb-akaros-gcc \
483         AR=$(ARCH)-ucb-akaros-ar \
484         RANLIB=$(ARCH)-ucb-akaros-ranlib \
485         ../glibc-$(GLIBC_VERSION)/configure \
486                 --prefix=/usr \
487                 --host=$(ARCH)-ucb-akaros \
488                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
489                 --without-cvs \
490                 --disable-profile \
491                 --without-gd \
492                 --with-headers=$(SYSROOT)/usr/include \
493                 --disable-debug \
494                 --disable-sanity-checks \
495                 --enable-kernel= \
496                 --with-__thread \
497                 --with-tls \
498                 --without-nptl \
499                 --enable-shared \
500                 --enable-add-ons=no \
501                 --with-pkgversion="akaros-repo" \
502                 --with-elf \
503                 --enable-hacker-mode \
504                 $(GLIBC_CONFIGURE_FLAGS);
505         touch $@
506
507 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
508         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
509         make -j $(MAKE_JOBS) \
510                 install_root=$(SYSROOT) \
511                 install-bootstrap-headers=yes \
512                 install-headers; \
513         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
514         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
515         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
516         make -j $(MAKE_JOBS) csu/subdir_lib;
517
518 ####################################
519 ########## Glibc Stage 2  ##########
520 ####################################
521 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
522         rm -rf $@
523         mkdir -p $@
524
525 .$(BINARY_PREFIX)glibc-stage2-configure: 
526         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
527         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
528         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -fpermissive -O2 -pipe" \
529         CC=x86_64-ucb-akaros-gcc \
530         AR=x86_64-ucb-akaros-ar \
531         RANLIB=x86_64-ucb-akaros-ranlib \
532         ../glibc-$(GLIBC_VERSION)/configure \
533                 --prefix=/usr \
534                 --host=$(ARCH)-ucb-akaros \
535                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
536                 --without-cvs \
537                 --disable-profile \
538                 --without-gd \
539                 --with-headers=$(SYSROOT)/usr/include \
540                 --disable-debug \
541                 --disable-sanity-checks \
542                 --enable-kernel= \
543                 --with-__thread \
544                 --with-tls \
545                 --without-nptl \
546                 --enable-shared \
547                 --enable-add-ons=no \
548                 --with-pkgversion="akaros-repo" \
549                 --with-elf \
550                 --enable-hacker-mode \
551                 $(GLIBC_CONFIGURE_FLAGS);
552         touch $@
553
554 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
555         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
556         make -j $(MAKE_JOBS)
557
558 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
559         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
560         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
561
562 ###################################
563 ####### AKAROS Libs Install #######
564 ###################################
565 .$(BINARY_PREFIX)akaros-libs-install:
566         cd $(ROSDIR); \
567         make ARCH=$(ROS_ARCH_DIR) userclean; \
568         make ARCH=$(ROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
569
570 ##################################
571 ########### Gcc Stage 3 ##########
572 ##################################
573 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
574         rm -rf $@
575         mkdir -p $@
576
577 native-gcc-stage3-prep:
578         mkdir -p $(INSTDIR)/usr; \
579
580 native-gcc-stage3-configure: native-gcc-stage3-prep
581         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
582         ../gcc-$(GCC_VERSION)/configure \
583                 --target=$(ARCH)-ucb-akaros \
584                 --host=$(ARCH)-ucb-akaros \
585                 --prefix=$(INSTDIR) \
586                 --with-gmp=$(CXXROOT) \
587                 --with-mpfr=$(CXXROOT) \
588                 --with-mpc=$(CXXROOT) \
589                 --enable-languages=c,c++ \
590                 --with-pkgversion="akaros-repo" \
591                 --disable-__cxa_atexit \
592                 --disable-mudflap \
593                 --enable-libgomp \
594                 --disable-libssp \
595                 --disable-libquadmath \
596                 --disable-libquadmath-support \
597                 --with-ppl=no \
598                 --with-isl=no \
599                 --with-cloog=no \
600                 --with-libelf=no \
601                 --enable-threads=no \
602                 --enable-tls \
603                 --disable-nls \
604                 --disable-multilib \
605                 --enable-c99 \
606                 --enable-long-long \
607                 --enable-shared \
608                 $(GCC_BUILD_FLAGS);
609
610 cross-gcc-stage3-configure:
611         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
612         CFLAGS="-O2 -g -pipe" \
613         CXXFLAGS="-O2 -g -pipe" \
614         LDFLAGS="-lstdc++ -lm" \
615         ../gcc-$(GCC_VERSION)/configure \
616                 --target=$(ARCH)-ucb-akaros \
617                 --prefix=$(INSTDIR) \
618                 --with-sysroot=$(SYSROOT) \
619                 --enable-languages=c,c++ \
620                 --with-pkgversion="akaros-repo" \
621                 --disable-__cxa_atexit \
622                 --disable-mudflap \
623                 --enable-libgomp \
624                 --disable-libssp \
625                 --disable-libquadmath \
626                 --disable-libquadmath-support \
627                 --with-ppl=no \
628                 --with-isl=no \
629                 --with-cloog=no \
630                 --with-libelf=no \
631                 --enable-threads=no \
632                 --disable-nls \
633                 --disable-multilib \
634                 --with-local-prefix=$(SYSROOT) \
635                 --enable-c99 \
636                 --enable-long-long \
637                 --enable-shared \
638                 $(GCC_BUILD_FLAGS);
639
640 .$(BINARY_PREFIX)gcc-stage3-configure:
641         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
642         if [ "$(NATIVE_BUILD)" = "true" ]; then \
643                 $(MAKE) native-gcc-stage3-configure; \
644         else \
645                 $(MAKE) cross-gcc-stage3-configure; \
646         fi
647         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
648         touch $@
649
650 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
651         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
652         make -j $(MAKE_JOBS)
653
654 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
655         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
656         make -j $(MAKE_JOBS) install
657
658 ##################################
659 ######### GMP, MPFR, MPC #########
660 ##################################
661 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
662         rm -rf gmp-$(GMP_VERSION)
663         tar -jxf gmp-$(GMP_VERSION).tar.bz2
664         patch -p0 < gmp-$(GMP_VERSION)-ros.patch
665
666 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
667         rm -rf mpfr-$(MPFR_VERSION)
668         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
669         patch -p0 < mpfr-$(MPFR_VERSION)-ros.patch
670
671 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
672         rm -rf mpc-$(MPC_VERSION)
673         tar -zxf mpc-$(MPC_VERSION).tar.gz
674         patch -p0 < mpc-$(MPC_VERSION)-ros.patch
675
676 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
677         rm -rf $@
678         mkdir -p $@
679
680 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
681         rm -rf $@
682         mkdir -p $@
683
684 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
685         rm -rf $@
686         mkdir -p $@
687
688 .$(BINARY_PREFIX)gmp-configure:
689         $(MAKE) $(BINARY_PREFIX)gmp-builddir
690         cd $(BINARY_PREFIX)gmp-builddir; \
691         ../gmp-$(GMP_VERSION)/configure \
692             --disable-static \
693             --prefix=$(INSTDIR) \
694             --host=$(ARCH)-ucb-akaros
695         touch $@
696
697 .$(BINARY_PREFIX)mpfr-configure:
698         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
699         cd $(BINARY_PREFIX)mpfr-builddir; \
700         ../mpfr-$(MPFR_VERSION)/configure \
701             --disable-static \
702             --prefix=$(INSTDIR) \
703             --with-gmp=$(INSTDIR) \
704             --host=$(ARCH)-ucb-akaros
705         touch $@
706
707 .$(BINARY_PREFIX)mpc-configure:
708         $(MAKE) $(BINARY_PREFIX)mpc-builddir
709         cd $(BINARY_PREFIX)mpc-builddir; \
710         ../mpc-$(MPC_VERSION)/configure \
711             --disable-static \
712             --prefix=$(INSTDIR) \
713             --with-gmp=$(INSTDIR) \
714             --with-mpfr=$(INSTDIR) \
715             --host=$(ARCH)-ucb-akaros
716         touch $@
717
718 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
719         cd $(BINARY_PREFIX)gmp-builddir; \
720         make -j $(MAKE_JOBS)
721
722 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
723         cd $(BINARY_PREFIX)mpfr-builddir; \
724         make -j $(MAKE_JOBS)
725
726 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
727         cd $(BINARY_PREFIX)mpc-builddir; \
728         make -j $(MAKE_JOBS)
729
730 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
731         cd $(BINARY_PREFIX)gmp-builddir; \
732         make -j $(MAKE_JOBS) install
733
734 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
735         cd $(BINARY_PREFIX)mpfr-builddir; \
736         make -j $(MAKE_JOBS) install
737
738 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
739         cd $(BINARY_PREFIX)mpc-builddir; \
740         make -j $(MAKE_JOBS) install
741
742 ##################################
743 ######## Clean it all up! ########
744 ##################################
745 clean:
746         rm -rf binutils-$(BINUTILS_VERSION) 
747         rm -rf gcc-$(GCC_VERSION) 
748         rm -rf glibc-$(GLIBC_VERSION) 
749         rm -rf gmp-$(GMP_VERSION)
750         rm -rf mpfr-$(MPFR_VERSION)
751         rm -rf mpc-$(MPC_VERSION)
752         rm -rf *-builddir
753         rm -rf .*-configure
754         rm -rf *$(BINARY_PREFIX)install.bak
755