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