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