Backport XCC makefile to match crosstools build
[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.21.1
36 GCC_VERSION := 4.6.1
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)-ros.patch
255         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
256         patch -p0 < binutils-$(BINUTILS_VERSION)-objdump.patch
257
258 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
259         rm -rf $@
260         mkdir -p $@
261
262 native-binutils-configure:
263         cd $(BINARY_PREFIX)binutils-builddir; \
264         CFLAGS="-O2 -g -pipe" \
265         CXXFLAGS="-O2 -g -pipe" \
266         LDFLAGS="" \
267         ../binutils-$(BINUTILS_VERSION)/configure \
268                 --target=$(ARCH)-ucb-akaros \
269                 --host=$(ARCH)-ucb-akaros \
270                 --prefix=$(INSTDIR) \
271                 --disable-werror \
272                 --enable-ld=yes \
273                 --enable-gold=no \
274                 --with-pkgversion="akaros-repo" \
275                 --disable-multilib \
276                 --disable-nls
277
278 cross-binutils-configure:
279         cd $(BINARY_PREFIX)binutils-builddir; \
280         CFLAGS="-O2 -g -pipe" \
281         CXXFLAGS="-O2 -g -pipe" \
282         LDFLAGS="" \
283         ../binutils-$(BINUTILS_VERSION)/configure \
284                 --target=$(ARCH)-ucb-akaros \
285                 --prefix=$(INSTDIR) \
286                 --disable-werror \
287                 --enable-ld=yes \
288                 --enable-gold=no \
289                 --with-pkgversion="akaros-repo" \
290                 --disable-multilib \
291                 --disable-nls \
292                 --with-sysroot=$(SYSROOT)
293
294 .$(BINARY_PREFIX)binutils-configure: 
295         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
296         if [ "$(NATIVE_BUILD)" = "true" ]; then \
297                 $(MAKE) native-binutils-configure; \
298         else \
299                 $(MAKE) cross-binutils-configure; \
300         fi
301         echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
302         touch $@
303
304 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
305         cd $(BINARY_PREFIX)binutils-builddir; \
306         make -j $(MAKE_JOBS)
307
308 .$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
309         cd $(BINARY_PREFIX)binutils-builddir; \
310         make -j $(MAKE_JOBS) install
311
312 binutils-clean:
313         cd $(BINARY_PREFIX)binutils-builddir; \
314         make clean
315
316 #################################
317 ########## GCC Stage 1 ##########
318 #################################
319 .gcc-akaros-patch:
320         -cd gcc-$(GCC_VERSION); \
321         diff -ruB --unidirectional-new-file \
322              ../gcc-$(GCC_VERSION) \
323              ../gcc-$(GCC_VERSION)-ros \
324              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
325              | patch -p2 
326
327 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
328         rm -rf gcc-$(GCC_VERSION)
329         tar -jxf gcc-$(GCC_VERSION).tar.bz2
330         $(MAKE) .gcc-akaros-patch
331         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
332
333 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
334         rm -rf $@
335         mkdir -p $@
336
337 .$(BINARY_PREFIX)gcc-stage1-configure: 
338         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
339         cd $(BINARY_PREFIX)gcc-stage1-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                 --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                 --disable-shared \
398                 --with-pkgversion="akaros-repo" \
399                 --disable-__cxa_atexit \
400                 --with-ppl=no \
401                 --with-sil=no \
402                 --with-cloog=no \
403                 --with-libelf=no \
404                 --disable-lto \
405                 --disable-libgomp \
406                 --disable-libmudflap \
407                 --disable-nls \
408                 --enable-languages=c \
409                 --disable-multilib \
410                 $(GCC_BUILD_FLAGS);
411         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
412         touch $@
413
414 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
415         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
416         make -j $(MAKE_JOBS) all-gcc all-target-libgcc;
417
418 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
419         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
420         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
421
422 ####################################
423 ######### AKAROS Headers ###########
424 ####################################
425 .$(BINARY_PREFIX)akaros-headers-install: $(ROSDIR)
426         rm -rf $(SYSROOT)/usr/include/*
427         mkdir -p $(SYSROOT)/usr/include
428         cp -r $(ROSDIR)/kern/include/ros \
429             $(SYSROOT)/usr/include/
430         rm -f $(SYSROOT)/usr/include/ros/arch
431         mkdir $(SYSROOT)/usr/include/ros/arch
432         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/ros/* \
433             $(SYSROOT)/usr/include/ros/arch/
434         cp -r $(ROSDIR)/user/parlib/include/* \
435             $(SYSROOT)/usr/include/
436         cp -r $(ROSDIR)/user/pthread/*.h \
437             $(SYSROOT)/usr/include/
438         rm -rf $(SYSROOT)/usr/include/arch
439         ln -s $(ROS_ARCH_DIR) $(SYSROOT)/usr/include/arch
440
441 #################################
442 ###### Dummy Libs Install #######
443 #################################
444 .$(BINARY_PREFIX)dummy-libs-install:
445         rm -rf $(SYSROOT)/lib/libparlib.a
446         rm -rf $(SYSROOT)/lib/libgcc_eh.a
447         mkdir -p $(SYSROOT)/lib
448         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/lib/libparlib.a
449         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/lib/libgcc_eh.a
450
451 #################################
452 ######### Glibc Stage 1 #########
453 #################################
454 .glibc-akaros-patch:
455         -cd glibc-$(GLIBC_VERSION); \
456         diff -ruB --unidirectional-new-file \
457              ../glibc-$(GLIBC_VERSION) \
458              ../glibc-$(GLIBC_VERSION)-ros \
459              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
460              | patch -p2 
461
462 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
463         rm -rf glibc-$(GLIBC_VERSION)
464         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
465         $(MAKE) .glibc-akaros-patch
466         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
467         rm glibc-$(GLIBC_VERSION)/sysdeps/riscv/elf/start.S
468         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
469         rm glibc-$(GLIBC_VERSION)/sysdeps/x86_64/elf/start.S
470
471 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
472         rm -rf $@
473         mkdir -p $@
474
475 .$(BINARY_PREFIX)glibc-stage1-configure: 
476         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
477         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
478         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -fpermissive -O2 -pipe" \
479         CC=$(ARCH)-ucb-akaros-gcc \
480         AR=$(ARCH)-ucb-akaros-ar \
481         RANLIB=$(ARCH)-ucb-akaros-ranlib \
482         ../glibc-$(GLIBC_VERSION)/configure \
483                 --prefix=/usr \
484                 --host=$(ARCH)-ucb-akaros \
485                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
486                 --without-cvs \
487                 --disable-profile \
488                 --without-gd \
489                 --with-headers=$(SYSROOT)/usr/include \
490                 --disable-debug \
491                 --disable-sanity-checks \
492                 --enable-kernel= \
493                 --with-__thread \
494                 --with-tls \
495                 --without-nptl \
496                 --enable-shared \
497                 --enable-add-ons=no \
498                 --with-pkgversion="akaros-repo" \
499                 --with-elf \
500                 --enable-hacker-mode \
501                 $(GLIBC_CONFIGURE_FLAGS);
502         touch $@
503
504 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
505         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
506         make -j $(MAKE_JOBS) \
507                 install_root=$(SYSROOT) \
508                 install-bootstrap-headers=yes \
509                 install-headers; \
510         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
511         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
512         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
513         make -j $(MAKE_JOBS) csu/subdir_lib;
514
515 ####################################
516 ########## Glibc Stage 2  ##########
517 ####################################
518 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
519         rm -rf $@
520         mkdir -p $@
521
522 .$(BINARY_PREFIX)glibc-stage2-configure: 
523         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
524         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
525         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -fpermissive -O2 -pipe" \
526         CC=x86_64-ucb-akaros-gcc \
527         AR=x86_64-ucb-akaros-ar \
528         RANLIB=x86_64-ucb-akaros-ranlib \
529         ../glibc-$(GLIBC_VERSION)/configure \
530                 --prefix=/usr \
531                 --host=$(ARCH)-ucb-akaros \
532                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
533                 --without-cvs \
534                 --disable-profile \
535                 --without-gd \
536                 --with-headers=$(SYSROOT)/usr/include \
537                 --disable-debug \
538                 --disable-sanity-checks \
539                 --enable-kernel= \
540                 --with-__thread \
541                 --with-tls \
542                 --without-nptl \
543                 --enable-shared \
544                 --enable-add-ons=no \
545                 --with-pkgversion="akaros-repo" \
546                 --with-elf \
547                 --enable-hacker-mode \
548                 $(GLIBC_CONFIGURE_FLAGS);
549         touch $@
550
551 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
552         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
553         make -j $(MAKE_JOBS)
554
555 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
556         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
557         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
558
559 ###################################
560 ####### AKAROS Libs Install #######
561 ###################################
562 .$(BINARY_PREFIX)akaros-libs-install:
563         cd $(ROSDIR); \
564         make ARCH=$(ROS_ARCH_DIR) userclean; \
565         make ARCH=$(ROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
566
567 ##################################
568 ########### Gcc Stage 3 ##########
569 ##################################
570 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
571         rm -rf $@
572         mkdir -p $@
573
574 native-gcc-stage3-prep:
575         mkdir -p $(INSTDIR)/usr; \
576
577 native-gcc-stage3-configure: native-gcc-stage3-prep
578         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
579         ../gcc-$(GCC_VERSION)/configure \
580                 --target=$(ARCH)-ucb-akaros \
581                 --host=$(ARCH)-ucb-akaros \
582                 --prefix=$(INSTDIR) \
583                 --with-gmp=$(CXXROOT) \
584                 --with-mpfr=$(CXXROOT) \
585                 --with-mpc=$(CXXROOT) \
586                 --enable-languages=c,c++ \
587                 --with-pkgversion="akaros-repo" \
588                 --disable-__cxa_atexit \
589                 --disable-mudflap \
590                 --enable-libgomp \
591                 --disable-libssp \
592                 --disable-libquadmath \
593                 --disable-libquadmath-support \
594                 --with-ppl=no \
595                 --with-isl=no \
596                 --with-cloog=no \
597                 --with-libelf=no \
598                 --enable-threads=no \
599                 --disable-nls \
600                 --disable-multilib \
601                 --enable-c99 \
602                 --enable-long-long \
603                 --enable-shared \
604                 $(GCC_BUILD_FLAGS);
605
606 cross-gcc-stage3-configure:
607         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
608         CFLAGS="-O2 -g -pipe" \
609         CXXFLAGS="-O2 -g -pipe" \
610         LDFLAGS="-lstdc++ -lm" \
611         ../gcc-$(GCC_VERSION)/configure \
612                 --target=$(ARCH)-ucb-akaros \
613                 --prefix=$(INSTDIR) \
614                 --with-sysroot=$(SYSROOT) \
615                 --enable-languages=c,c++ \
616                 --with-pkgversion="akaros-repo" \
617                 --disable-__cxa_atexit \
618                 --disable-mudflap \
619                 --enable-libgomp \
620                 --disable-libssp \
621                 --disable-libquadmath \
622                 --disable-libquadmath-support \
623                 --with-ppl=no \
624                 --with-isl=no \
625                 --with-cloog=no \
626                 --with-libelf=no \
627                 --enable-threads=no \
628                 --disable-nls \
629                 --disable-multilib \
630                 --with-local-prefix=$(SYSROOT) \
631                 --enable-c99 \
632                 --enable-long-long \
633                 --enable-shared \
634                 $(GCC_BUILD_FLAGS);
635
636 .$(BINARY_PREFIX)gcc-stage3-configure:
637         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
638         if [ "$(NATIVE_BUILD)" = "true" ]; then \
639                 $(MAKE) native-gcc-stage3-configure; \
640         else \
641                 $(MAKE) cross-gcc-stage3-configure; \
642         fi
643         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
644         touch $@
645
646 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
647         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
648         make -j $(MAKE_JOBS)
649
650 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
651         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
652         make -j $(MAKE_JOBS) install
653
654 ##################################
655 ######### GMP, MPFR, MPC #########
656 ##################################
657 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
658         rm -rf gmp-$(GMP_VERSION)
659         tar -jxf gmp-$(GMP_VERSION).tar.bz2
660         patch -p0 < gmp-$(GMP_VERSION)-ros.patch
661
662 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
663         rm -rf mpfr-$(MPFR_VERSION)
664         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
665         patch -p0 < mpfr-$(MPFR_VERSION)-ros.patch
666
667 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
668         rm -rf mpc-$(MPC_VERSION)
669         tar -zxf mpc-$(MPC_VERSION).tar.gz
670         patch -p0 < mpc-$(MPC_VERSION)-ros.patch
671
672 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
673         rm -rf $@
674         mkdir -p $@
675
676 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
677         rm -rf $@
678         mkdir -p $@
679
680 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
681         rm -rf $@
682         mkdir -p $@
683
684 .$(BINARY_PREFIX)gmp-configure:
685         $(MAKE) $(BINARY_PREFIX)gmp-builddir
686         cd $(BINARY_PREFIX)gmp-builddir; \
687         ../gmp-$(GMP_VERSION)/configure \
688             --disable-static \
689             --prefix=$(INSTDIR) \
690             --host=$(ARCH)-ucb-akaros
691         touch $@
692
693 .$(BINARY_PREFIX)mpfr-configure:
694         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
695         cd $(BINARY_PREFIX)mpfr-builddir; \
696         ../mpfr-$(MPFR_VERSION)/configure \
697             --disable-static \
698             --prefix=$(INSTDIR) \
699             --with-gmp=$(INSTDIR) \
700             --host=$(ARCH)-ucb-akaros
701         touch $@
702
703 .$(BINARY_PREFIX)mpc-configure:
704         $(MAKE) $(BINARY_PREFIX)mpc-builddir
705         cd $(BINARY_PREFIX)mpc-builddir; \
706         ../mpc-$(MPC_VERSION)/configure \
707             --disable-static \
708             --prefix=$(INSTDIR) \
709             --with-gmp=$(INSTDIR) \
710             --with-mpfr=$(INSTDIR) \
711             --host=$(ARCH)-ucb-akaros
712         touch $@
713
714 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
715         cd $(BINARY_PREFIX)gmp-builddir; \
716         make -j $(MAKE_JOBS)
717
718 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
719         cd $(BINARY_PREFIX)mpfr-builddir; \
720         make -j $(MAKE_JOBS)
721
722 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
723         cd $(BINARY_PREFIX)mpc-builddir; \
724         make -j $(MAKE_JOBS)
725
726 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
727         cd $(BINARY_PREFIX)gmp-builddir; \
728         make -j $(MAKE_JOBS) install
729
730 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
731         cd $(BINARY_PREFIX)mpfr-builddir; \
732         make -j $(MAKE_JOBS) install
733
734 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
735         cd $(BINARY_PREFIX)mpc-builddir; \
736         make -j $(MAKE_JOBS) install
737
738 ##################################
739 ######## Clean it all up! ########
740 ##################################
741 clean:
742         rm -rf binutils-$(BINUTILS_VERSION) 
743         rm -rf gcc-$(GCC_VERSION) 
744         rm -rf glibc-$(GLIBC_VERSION) 
745         rm -rf gmp-$(GMP_VERSION)
746         rm -rf mpfr-$(MPFR_VERSION)
747         rm -rf mpc-$(MPC_VERSION)
748         rm -rf *-builddir
749         rm -rf .*-configure
750         rm -rf *$(BINARY_PREFIX)install.bak
751