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