Fixes glibc stage 2 pthread errors (XCC)
[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.19
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)/usr/lib/libparlib.a
449         rm -rf $(SYSROOT)/usr/lib/libgcc_eh.a
450         mkdir -p $(SYSROOT)/usr/lib
451         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
452         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/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)-akaros \
462              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
463              | patch -p2 
464
465 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
466 # parlib's pthread.h.
467 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
468         rm -rf glibc-$(GLIBC_VERSION)
469         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
470         rm glibc-$(GLIBC_VERSION)/include/pthread.h
471         $(MAKE) .glibc-akaros-patch
472         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
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 -O2 -pipe" \
482         CXXFLAGS="-fpermissive" \
483         CC=$(ARCH)-ucb-akaros-gcc \
484         AR=$(ARCH)-ucb-akaros-ar \
485         RANLIB=$(ARCH)-ucb-akaros-ranlib \
486         ../glibc-$(GLIBC_VERSION)/configure \
487                 --prefix=/usr \
488                 --host=$(ARCH)-ucb-akaros \
489                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
490                 --without-cvs \
491                 --disable-profile \
492                 --without-gd \
493                 --with-headers=$(SYSROOT)/usr/include \
494                 --disable-debug \
495                 --disable-sanity-checks \
496                 --enable-kernel= \
497                 --with-__thread \
498                 --with-tls \
499                 --without-nptl \
500                 --enable-shared \
501                 --enable-add-ons=no \
502                 --with-pkgversion="akaros-repo" \
503                 --with-elf \
504                 --enable-hacker-mode \
505                 $(GLIBC_CONFIGURE_FLAGS);
506         touch $@
507
508 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
509         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
510         make -j $(MAKE_JOBS) \
511                 install_root=$(SYSROOT) \
512                 install-bootstrap-headers=yes \
513                 install-headers; \
514         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
515         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
516         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
517         make -j $(MAKE_JOBS) csu/subdir_lib;
518
519 ####################################
520 ########## Glibc Stage 2  ##########
521 ####################################
522 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
523         rm -rf $@
524         mkdir -p $@
525
526 .$(BINARY_PREFIX)glibc-stage2-configure: 
527         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
528         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
529         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
530         CXXFLAGS="-fpermissive" \
531         CC=x86_64-ucb-akaros-gcc \
532         AR=x86_64-ucb-akaros-ar \
533         RANLIB=x86_64-ucb-akaros-ranlib \
534         ../glibc-$(GLIBC_VERSION)/configure \
535                 --prefix=/usr \
536                 --host=$(ARCH)-ucb-akaros \
537                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
538                 --without-cvs \
539                 --disable-profile \
540                 --without-gd \
541                 --with-headers=$(SYSROOT)/usr/include \
542                 --disable-debug \
543                 --disable-sanity-checks \
544                 --enable-kernel= \
545                 --with-__thread \
546                 --with-tls \
547                 --without-nptl \
548                 --enable-shared \
549                 --enable-add-ons=no \
550                 --with-pkgversion="akaros-repo" \
551                 --with-elf \
552                 --enable-hacker-mode \
553                 $(GLIBC_CONFIGURE_FLAGS);
554         touch $@
555
556 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
557         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
558         make -j $(MAKE_JOBS)
559
560 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
561         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
562         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
563
564 ###################################
565 ####### AKAROS Libs Install #######
566 ###################################
567 .$(BINARY_PREFIX)akaros-libs-install:
568         cd $(ROSDIR); \
569         make ARCH=$(ROS_ARCH_DIR) userclean; \
570         make ARCH=$(ROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
571
572 ##################################
573 ########### Gcc Stage 3 ##########
574 ##################################
575 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
576         rm -rf $@
577         mkdir -p $@
578
579 native-gcc-stage3-prep:
580         mkdir -p $(INSTDIR)/usr; \
581
582 native-gcc-stage3-configure: native-gcc-stage3-prep
583         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
584         ../gcc-$(GCC_VERSION)/configure \
585                 --target=$(ARCH)-ucb-akaros \
586                 --host=$(ARCH)-ucb-akaros \
587                 --prefix=$(INSTDIR) \
588                 --with-gmp=$(CXXROOT) \
589                 --with-mpfr=$(CXXROOT) \
590                 --with-mpc=$(CXXROOT) \
591                 --enable-languages=c,c++ \
592                 --with-pkgversion="akaros-repo" \
593                 --disable-__cxa_atexit \
594                 --disable-mudflap \
595                 --enable-libgomp \
596                 --disable-libssp \
597                 --disable-libquadmath \
598                 --disable-libquadmath-support \
599                 --with-ppl=no \
600                 --with-isl=no \
601                 --with-cloog=no \
602                 --with-libelf=no \
603                 --enable-threads=no \
604                 --enable-tls \
605                 --disable-nls \
606                 --disable-multilib \
607                 --enable-c99 \
608                 --enable-long-long \
609                 --enable-shared \
610                 $(GCC_BUILD_FLAGS);
611
612 cross-gcc-stage3-configure:
613         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
614         CFLAGS="-O2 -g -pipe" \
615         CXXFLAGS="-O2 -g -pipe" \
616         LDFLAGS="-lstdc++ -lm" \
617         ../gcc-$(GCC_VERSION)/configure \
618                 --target=$(ARCH)-ucb-akaros \
619                 --prefix=$(INSTDIR) \
620                 --with-sysroot=$(SYSROOT) \
621                 --enable-languages=c,c++ \
622                 --with-pkgversion="akaros-repo" \
623                 --disable-__cxa_atexit \
624                 --disable-mudflap \
625                 --enable-libgomp \
626                 --disable-libssp \
627                 --disable-libquadmath \
628                 --disable-libquadmath-support \
629                 --with-ppl=no \
630                 --with-isl=no \
631                 --with-cloog=no \
632                 --with-libelf=no \
633                 --enable-threads=no \
634                 --disable-nls \
635                 --disable-multilib \
636                 --with-local-prefix=$(SYSROOT) \
637                 --enable-c99 \
638                 --enable-long-long \
639                 --enable-shared \
640                 $(GCC_BUILD_FLAGS);
641
642 .$(BINARY_PREFIX)gcc-stage3-configure:
643         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
644         if [ "$(NATIVE_BUILD)" = "true" ]; then \
645                 $(MAKE) native-gcc-stage3-configure; \
646         else \
647                 $(MAKE) cross-gcc-stage3-configure; \
648         fi
649         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
650         touch $@
651
652 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
653         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
654         make -j $(MAKE_JOBS)
655
656 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
657         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
658         make -j $(MAKE_JOBS) install
659
660 ##################################
661 ######### GMP, MPFR, MPC #########
662 ##################################
663 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
664         rm -rf gmp-$(GMP_VERSION)
665         tar -jxf gmp-$(GMP_VERSION).tar.bz2
666         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
667
668 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
669         rm -rf mpfr-$(MPFR_VERSION)
670         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
671         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
672
673 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
674         rm -rf mpc-$(MPC_VERSION)
675         tar -zxf mpc-$(MPC_VERSION).tar.gz
676         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
677
678 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
679         rm -rf $@
680         mkdir -p $@
681
682 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
683         rm -rf $@
684         mkdir -p $@
685
686 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
687         rm -rf $@
688         mkdir -p $@
689
690 .$(BINARY_PREFIX)gmp-configure:
691         $(MAKE) $(BINARY_PREFIX)gmp-builddir
692         cd $(BINARY_PREFIX)gmp-builddir; \
693         ../gmp-$(GMP_VERSION)/configure \
694             --disable-static \
695             --prefix=$(INSTDIR) \
696             --host=$(ARCH)-ucb-akaros
697         touch $@
698
699 .$(BINARY_PREFIX)mpfr-configure:
700         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
701         cd $(BINARY_PREFIX)mpfr-builddir; \
702         ../mpfr-$(MPFR_VERSION)/configure \
703             --disable-static \
704             --prefix=$(INSTDIR) \
705             --with-gmp=$(INSTDIR) \
706             --host=$(ARCH)-ucb-akaros
707         touch $@
708
709 .$(BINARY_PREFIX)mpc-configure:
710         $(MAKE) $(BINARY_PREFIX)mpc-builddir
711         cd $(BINARY_PREFIX)mpc-builddir; \
712         ../mpc-$(MPC_VERSION)/configure \
713             --disable-static \
714             --prefix=$(INSTDIR) \
715             --with-gmp=$(INSTDIR) \
716             --with-mpfr=$(INSTDIR) \
717             --host=$(ARCH)-ucb-akaros
718         touch $@
719
720 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
721         cd $(BINARY_PREFIX)gmp-builddir; \
722         make -j $(MAKE_JOBS)
723
724 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
725         cd $(BINARY_PREFIX)mpfr-builddir; \
726         make -j $(MAKE_JOBS)
727
728 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
729         cd $(BINARY_PREFIX)mpc-builddir; \
730         make -j $(MAKE_JOBS)
731
732 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
733         cd $(BINARY_PREFIX)gmp-builddir; \
734         make -j $(MAKE_JOBS) install
735
736 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
737         cd $(BINARY_PREFIX)mpfr-builddir; \
738         make -j $(MAKE_JOBS) install
739
740 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
741         cd $(BINARY_PREFIX)mpc-builddir; \
742         make -j $(MAKE_JOBS) install
743
744 ##################################
745 ######## Clean it all up! ########
746 ##################################
747 clean:
748         rm -rf binutils-$(BINUTILS_VERSION) 
749         rm -rf gcc-$(GCC_VERSION) 
750         rm -rf glibc-$(GLIBC_VERSION) 
751         rm -rf gmp-$(GMP_VERSION)
752         rm -rf mpfr-$(MPFR_VERSION)
753         rm -rf mpc-$(MPC_VERSION)
754         rm -rf *-builddir
755         rm -rf .*-configure
756         rm -rf *$(BINARY_PREFIX)install.bak
757