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