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