61d327fa222f7edf49d882aad0e8c2637c5d42b7
[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              | patch -p2 
279
280 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
281         rm -rf gcc-$(GCC_VERSION)
282         tar -jxf gcc-$(GCC_VERSION).tar.bz2
283         $(MAKE) .gcc-akaros-patch
284         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
285
286 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
287         rm -rf $@
288         mkdir -p $@
289
290 .$(BINARY_PREFIX)gcc-stage1-configure: 
291         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
292         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
293         CFLAGS="-O2 -g -pipe" \
294         CXXFLAGS="-O2 -g -pipe" \
295         LDFLAGS="-lstdc++ -lm" \
296         ../gcc-$(GCC_VERSION)/configure \
297                 --target=$(ARCH)-ucb-akaros \
298                 --prefix=$(INSTDIR) \
299                 --with-local-prefix=$(SYSROOT) \
300                 --disable-mudflap \
301                 --with-sysroot=$(SYSROOT) \
302                 --with-newlib \
303                 --enable-threads=no \
304                 --enable-tls \
305                 --disable-shared \
306                 --with-pkgversion="akaros-repo" \
307                 --disable-__cxa_atexit \
308                 --with-ppl=no \
309                 --with-isl=no \
310                 --with-cloog=no \
311                 --with-libelf=no \
312                 --disable-lto \
313                 --disable-libgomp \
314                 --disable-mudflap \
315                 --disable-nls \
316                 --disable-multilib \
317                 --enable-languages=c \
318                 $(GCC_BUILD_FLAGS);
319         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
320         touch $@
321
322 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
323         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
324         make -j $(MAKE_JOBS) all-gcc;
325
326 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
327         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
328         make -j $(MAKE_JOBS) install-gcc;
329
330 #################################
331 ########## GCC Stage 2 ##########
332 #################################
333 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
334         rm -rf $@
335         mkdir -p $@
336
337 .$(BINARY_PREFIX)gcc-stage2-configure: 
338         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
339         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
340         CFLAGS="-O2 -g -pipe" \
341         CXXFLAGS="-O2 -g -pipe" \
342         LDFLAGS="-lstdc++ -lm" \
343         ../gcc-$(GCC_VERSION)/configure \
344                 --target=$(ARCH)-ucb-akaros \
345                 --prefix=$(INSTDIR) \
346                 --with-local-prefix=$(SYSROOT) \
347                 --disable-mudflap \
348                 --with-sysroot=$(SYSROOT) \
349                 --with-newlib \
350                 --enable-threads=no \
351                 --enable-tls \
352                 --disable-shared \
353                 --with-pkgversion="akaros-repo" \
354                 --disable-__cxa_atexit \
355                 --with-ppl=no \
356                 --with-sil=no \
357                 --with-cloog=no \
358                 --with-libelf=no \
359                 --disable-lto \
360                 --disable-libgomp \
361                 --disable-libmudflap \
362                 --disable-nls \
363                 --enable-languages=c \
364                 --disable-multilib \
365                 $(GCC_BUILD_FLAGS);
366         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
367         touch $@
368
369 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
370         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
371         make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
372                              all-gcc \
373                              all-target-libgcc;
374
375 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
376         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
377         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
378
379 ####################################
380 ######### AKAROS Headers ###########
381 ####################################
382 .$(BINARY_PREFIX)akaros-headers-install: $(ROSDIR)
383         rm -rf $(SYSROOT)/usr/include/*
384         mkdir -p $(SYSROOT)/usr/include
385         cp -r $(ROSDIR)/kern/include/ros \
386             $(SYSROOT)/usr/include/
387         rm -f $(SYSROOT)/usr/include/ros/arch
388         mkdir $(SYSROOT)/usr/include/ros/arch
389         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/ros/* \
390             $(SYSROOT)/usr/include/ros/arch/
391         cp -r $(ROSDIR)/user/parlib/include/* \
392             $(SYSROOT)/usr/include/
393         cp -r $(ROSDIR)/user/pthread/*.h \
394             $(SYSROOT)/usr/include/
395         rm -rf $(SYSROOT)/usr/include/arch
396         ln -s $(ROS_ARCH_DIR) $(SYSROOT)/usr/include/arch
397
398 #################################
399 ###### Dummy Libs Install #######
400 #################################
401 .$(BINARY_PREFIX)dummy-libs-install:
402         rm -rf $(SYSROOT)/usr/lib/libparlib.a
403         rm -rf $(SYSROOT)/usr/lib/libgcc_eh.a
404         mkdir -p $(SYSROOT)/usr/lib
405         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
406         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libgcc_eh.a
407
408 #################################
409 ######### Glibc Stage 1 #########
410 #################################
411 .glibc-akaros-patch:
412         -cd glibc-$(GLIBC_VERSION); \
413         diff -ruB --unidirectional-new-file \
414              ../glibc-$(GLIBC_VERSION) \
415              ../glibc-$(GLIBC_VERSION)-akaros \
416              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
417              | patch -p2 
418
419 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
420 # parlib's pthread.h.
421 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
422         rm -rf glibc-$(GLIBC_VERSION)
423         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
424         rm glibc-$(GLIBC_VERSION)/include/pthread.h
425         $(MAKE) .glibc-akaros-patch
426         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
427
428 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
429         rm -rf $@
430         mkdir -p $@
431
432 .$(BINARY_PREFIX)glibc-stage1-configure: 
433         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
434         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
435         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
436         CXXFLAGS="-fpermissive" \
437         CC=$(ARCH)-ucb-akaros-gcc \
438         AR=$(ARCH)-ucb-akaros-ar \
439         RANLIB=$(ARCH)-ucb-akaros-ranlib \
440         ../glibc-$(GLIBC_VERSION)/configure \
441                 --prefix=/usr \
442                 --host=$(ARCH)-ucb-akaros \
443                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
444                 --without-cvs \
445                 --disable-profile \
446                 --without-gd \
447                 --with-headers=$(SYSROOT)/usr/include \
448                 --disable-debug \
449                 --disable-sanity-checks \
450                 --enable-kernel= \
451                 --with-__thread \
452                 --with-tls \
453                 --without-nptl \
454                 --enable-shared \
455                 --enable-add-ons=no \
456                 --with-pkgversion="akaros-repo" \
457                 --with-elf \
458                 --enable-hacker-mode \
459                 $(GLIBC_CONFIGURE_FLAGS);
460         touch $@
461
462 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
463         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
464         make -j $(MAKE_JOBS) \
465                 install_root=$(SYSROOT) \
466                 install-bootstrap-headers=yes \
467                 install-headers; \
468         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
469         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
470         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
471         make -j $(MAKE_JOBS) csu/subdir_lib;
472
473 ####################################
474 ########## Glibc Stage 2  ##########
475 ####################################
476 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
477         rm -rf $@
478         mkdir -p $@
479
480 .$(BINARY_PREFIX)glibc-stage2-configure: 
481         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
482         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
483         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
484         CXXFLAGS="-fpermissive" \
485         CC=x86_64-ucb-akaros-gcc \
486         AR=x86_64-ucb-akaros-ar \
487         RANLIB=x86_64-ucb-akaros-ranlib \
488         ../glibc-$(GLIBC_VERSION)/configure \
489                 --prefix=/usr \
490                 --host=$(ARCH)-ucb-akaros \
491                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
492                 --without-cvs \
493                 --disable-profile \
494                 --without-gd \
495                 --with-headers=$(SYSROOT)/usr/include \
496                 --disable-debug \
497                 --disable-sanity-checks \
498                 --enable-kernel= \
499                 --with-__thread \
500                 --with-tls \
501                 --without-nptl \
502                 --enable-shared \
503                 --enable-add-ons=no \
504                 --with-pkgversion="akaros-repo" \
505                 --with-elf \
506                 --enable-hacker-mode \
507                 $(GLIBC_CONFIGURE_FLAGS);
508         touch $@
509
510 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
511         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
512         make -j $(MAKE_JOBS)
513
514 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
515         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
516         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
517
518 ###################################
519 ####### AKAROS Libs Install #######
520 ###################################
521 .$(BINARY_PREFIX)akaros-libs-install:
522         cd $(ROSDIR); \
523         make ARCH=$(ROS_ARCH_DIR) userclean; \
524         make ARCH=$(ROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
525
526 ##################################
527 ########### Gcc Stage 3 ##########
528 ##################################
529 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
530         rm -rf $@
531         mkdir -p $@
532
533 native-gcc-stage3-prep:
534         mkdir -p $(INSTDIR)/usr; \
535
536 native-gcc-stage3-configure: native-gcc-stage3-prep
537         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
538         ../gcc-$(GCC_VERSION)/configure \
539                 --target=$(ARCH)-ucb-akaros \
540                 --host=$(ARCH)-ucb-akaros \
541                 --prefix=$(INSTDIR) \
542                 --with-gmp=$(CXXROOT) \
543                 --with-mpfr=$(CXXROOT) \
544                 --with-mpc=$(CXXROOT) \
545                 --enable-languages=c,c++ \
546                 --with-pkgversion="akaros-repo" \
547                 --disable-__cxa_atexit \
548                 --disable-mudflap \
549                 --enable-libgomp \
550                 --disable-libssp \
551                 --disable-libquadmath \
552                 --disable-libquadmath-support \
553                 --with-ppl=no \
554                 --with-isl=no \
555                 --with-cloog=no \
556                 --with-libelf=no \
557                 --enable-threads=no \
558                 --enable-tls \
559                 --disable-nls \
560                 --disable-multilib \
561                 --enable-c99 \
562                 --enable-long-long \
563                 --enable-shared \
564                 $(GCC_BUILD_FLAGS);
565
566 cross-gcc-stage3-configure:
567         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
568         CFLAGS="-O2 -g -pipe" \
569         CXXFLAGS="-O2 -g -pipe" \
570         LDFLAGS="-lstdc++ -lm" \
571         ../gcc-$(GCC_VERSION)/configure \
572                 --target=$(ARCH)-ucb-akaros \
573                 --prefix=$(INSTDIR) \
574                 --with-sysroot=$(SYSROOT) \
575                 --enable-languages=c,c++ \
576                 --with-pkgversion="akaros-repo" \
577                 --disable-__cxa_atexit \
578                 --disable-mudflap \
579                 --enable-libgomp \
580                 --disable-libssp \
581                 --disable-libquadmath \
582                 --disable-libquadmath-support \
583                 --with-ppl=no \
584                 --with-isl=no \
585                 --with-cloog=no \
586                 --with-libelf=no \
587                 --enable-threads=no \
588                 --disable-nls \
589                 --disable-multilib \
590                 --with-local-prefix=$(SYSROOT) \
591                 --enable-c99 \
592                 --enable-long-long \
593                 --enable-shared \
594                 $(GCC_BUILD_FLAGS);
595
596 .$(BINARY_PREFIX)gcc-stage3-configure:
597         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
598         if [ "$(NATIVE_BUILD)" = "true" ]; then \
599                 $(MAKE) native-gcc-stage3-configure; \
600         else \
601                 $(MAKE) cross-gcc-stage3-configure; \
602         fi
603         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
604         touch $@
605
606 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
607         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
608         make -j $(MAKE_JOBS)
609
610 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
611         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
612         make -j $(MAKE_JOBS) install
613
614 ##################################
615 ######### GMP, MPFR, MPC #########
616 ##################################
617 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
618         rm -rf gmp-$(GMP_VERSION)
619         tar -jxf gmp-$(GMP_VERSION).tar.bz2
620         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
621
622 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
623         rm -rf mpfr-$(MPFR_VERSION)
624         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
625         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
626
627 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
628         rm -rf mpc-$(MPC_VERSION)
629         tar -zxf mpc-$(MPC_VERSION).tar.gz
630         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
631
632 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
633         rm -rf $@
634         mkdir -p $@
635
636 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
637         rm -rf $@
638         mkdir -p $@
639
640 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
641         rm -rf $@
642         mkdir -p $@
643
644 .$(BINARY_PREFIX)gmp-configure:
645         $(MAKE) $(BINARY_PREFIX)gmp-builddir
646         cd $(BINARY_PREFIX)gmp-builddir; \
647         ../gmp-$(GMP_VERSION)/configure \
648             --disable-static \
649             --prefix=$(INSTDIR) \
650             --host=$(ARCH)-ucb-akaros
651         touch $@
652
653 .$(BINARY_PREFIX)mpfr-configure:
654         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
655         cd $(BINARY_PREFIX)mpfr-builddir; \
656         ../mpfr-$(MPFR_VERSION)/configure \
657             --disable-static \
658             --prefix=$(INSTDIR) \
659             --with-gmp=$(INSTDIR) \
660             --host=$(ARCH)-ucb-akaros
661         touch $@
662
663 .$(BINARY_PREFIX)mpc-configure:
664         $(MAKE) $(BINARY_PREFIX)mpc-builddir
665         cd $(BINARY_PREFIX)mpc-builddir; \
666         ../mpc-$(MPC_VERSION)/configure \
667             --disable-static \
668             --prefix=$(INSTDIR) \
669             --with-gmp=$(INSTDIR) \
670             --with-mpfr=$(INSTDIR) \
671             --host=$(ARCH)-ucb-akaros
672         touch $@
673
674 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
675         cd $(BINARY_PREFIX)gmp-builddir; \
676         make -j $(MAKE_JOBS)
677
678 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
679         cd $(BINARY_PREFIX)mpfr-builddir; \
680         make -j $(MAKE_JOBS)
681
682 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
683         cd $(BINARY_PREFIX)mpc-builddir; \
684         make -j $(MAKE_JOBS)
685
686 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
687         cd $(BINARY_PREFIX)gmp-builddir; \
688         make -j $(MAKE_JOBS) install
689
690 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
691         cd $(BINARY_PREFIX)mpfr-builddir; \
692         make -j $(MAKE_JOBS) install
693
694 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
695         cd $(BINARY_PREFIX)mpc-builddir; \
696         make -j $(MAKE_JOBS) install
697
698 ##################################
699 ######## Clean it all up! ########
700 ##################################
701 clean:
702         rm -rf binutils-$(BINUTILS_VERSION) 
703         rm -rf gcc-$(GCC_VERSION) 
704         rm -rf glibc-$(GLIBC_VERSION) 
705         rm -rf gmp-$(GMP_VERSION)
706         rm -rf mpfr-$(MPFR_VERSION)
707         rm -rf mpc-$(MPC_VERSION)
708         rm -rf *-builddir
709         rm -rf .*-configure
710         rm -rf *$(BINARY_PREFIX)install.bak
711