Clean up user library include paths (XCC)
[akaros.git] / tools / compilers / gcc-glibc / Makefile
1 # Number of make jobs to spawn.  Define it in Makelocal
2 MAKE_JOBS ?= $(shell expr `cat /proc/cpuinfo | grep processor | wc -l` - 1)
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_LIBRARY_PATH is not set during the build process
232 unexport LD_LIBRARY_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         cp -r $(AKAROSDIR)/user/parlib/include/* \
476             $(SYSROOT)/usr/include/
477         cp -r $(AKAROSDIR)/user/pthread/*.h \
478             $(SYSROOT)/usr/include/
479
480 #################################
481 ###### Dummy Libs Install #######
482 #################################
483 .$(BINARY_PREFIX)dummy-libs-install:
484         rm -rf $(SYSROOT)/usr/lib/libparlib.a
485         mkdir -p $(SYSROOT)/usr/lib
486         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
487
488 #################################
489 ######### Glibc Stage 1 #########
490 #################################
491 .glibc-akaros-patch:
492         -cd glibc-$(GLIBC_VERSION); \
493         diff -ruB --unidirectional-new-file \
494              ../glibc-$(GLIBC_VERSION) \
495              ../glibc-$(GLIBC_VERSION)-akaros \
496              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
497              > ../.glibc-$(GLIBC_VERSION)-akaros.patch; \
498              patch -p2 < ../.glibc-$(GLIBC_VERSION)-akaros.patch
499
500 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
501 # parlib's pthread.h.
502 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
503         rm -rf glibc-$(GLIBC_VERSION)
504         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
505         rm glibc-$(GLIBC_VERSION)/include/pthread.h
506         $(MAKE) .glibc-akaros-patch
507         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
508
509 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
510         rm -rf $@
511         mkdir -p $@
512
513 .$(BINARY_PREFIX)glibc-stage1-configure: 
514         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
515         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
516         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
517         CXXFLAGS="-fpermissive" \
518         CC=$(ARCH)-ucb-akaros-gcc \
519         AR=$(ARCH)-ucb-akaros-ar \
520         RANLIB=$(ARCH)-ucb-akaros-ranlib \
521         ../glibc-$(GLIBC_VERSION)/configure \
522                 --prefix=/usr \
523                 --host=$(ARCH)-ucb-akaros \
524                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
525                 --without-cvs \
526                 --disable-profile \
527                 --without-gd \
528                 --with-headers=$(SYSROOT)/usr/include \
529                 --disable-debug \
530                 --disable-sanity-checks \
531                 --enable-kernel= \
532                 --with-__thread \
533                 --with-tls \
534                 --without-nptl \
535                 --enable-shared \
536                 --enable-add-ons=no \
537                 --with-pkgversion="akaros-repo" \
538                 --with-elf \
539                 --enable-hacker-mode \
540                 --enable-static-nss \
541                 --enable-obsolete-rpc \
542                 --disable-build-nscd \
543                 --disable-nscd \
544                 $(GLIBC_CONFIGURE_FLAGS);
545         touch $@
546
547 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
548         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
549         make -j $(MAKE_JOBS) \
550                 install_root=$(SYSROOT) \
551                 install-bootstrap-headers=yes \
552                 install-headers; \
553         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
554         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
555         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
556         make -j $(MAKE_JOBS) csu/subdir_lib;
557
558 ####################################
559 ########## Glibc Stage 2  ##########
560 ####################################
561 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
562         rm -rf $@
563         mkdir -p $@
564
565 .$(BINARY_PREFIX)glibc-stage2-configure: 
566         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
567         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
568         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
569         CXXFLAGS="-fpermissive" \
570         CC=x86_64-ucb-akaros-gcc \
571         AR=x86_64-ucb-akaros-ar \
572         RANLIB=x86_64-ucb-akaros-ranlib \
573         ../glibc-$(GLIBC_VERSION)/configure \
574                 --prefix=/usr \
575                 --host=$(ARCH)-ucb-akaros \
576                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
577                 --without-cvs \
578                 --disable-profile \
579                 --without-gd \
580                 --with-headers=$(SYSROOT)/usr/include \
581                 --disable-debug \
582                 --disable-sanity-checks \
583                 --enable-kernel= \
584                 --with-__thread \
585                 --with-tls \
586                 --without-nptl \
587                 --enable-shared \
588                 --enable-add-ons=no \
589                 --with-pkgversion="akaros-repo" \
590                 --with-elf \
591                 --enable-hacker-mode \
592                 --enable-static-nss \
593                 --enable-obsolete-rpc \
594                 --disable-build-nscd \
595                 --disable-nscd \
596                 $(GLIBC_CONFIGURE_FLAGS);
597         touch $@
598
599 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
600         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
601         make -j $(MAKE_JOBS)
602
603 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
604         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
605         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
606
607 ###################################
608 ####### AKAROS Libs Install #######
609 ###################################
610 .$(BINARY_PREFIX)akaros-libs-install:
611         cd $(AKAROSDIR); \
612         make ARCH=$(AKAROS_ARCH_DIR) userclean; \
613         make ARCH=$(AKAROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
614
615 ##################################
616 ########### Gcc Stage 3 ##########
617 ##################################
618 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
619         rm -rf $@
620         mkdir -p $@
621
622 native-gcc-stage3-prep:
623         mkdir -p $(INSTDIR)/usr; \
624
625 native-gcc-stage3-configure: native-gcc-stage3-prep
626         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
627         ../gcc-$(GCC_VERSION)/configure \
628                 --target=$(ARCH)-ucb-akaros \
629                 --host=$(ARCH)-ucb-akaros \
630                 --prefix=$(INSTDIR) \
631                 --with-gmp=$(XCCROOT) \
632                 --with-mpfr=$(XCCROOT) \
633                 --with-mpc=$(XCCROOT) \
634                 --enable-languages=c,c++,fortran \
635                 --with-pkgversion="akaros-repo" \
636                 --disable-__cxa_atexit \
637                 --disable-mudflap \
638                 --enable-libgomp \
639                 --disable-libssp \
640                 --disable-libquadmath \
641                 --disable-libquadmath-support \
642                 --with-ppl=no \
643                 --with-isl=no \
644                 --with-cloog=no \
645                 --with-libelf=no \
646                 --enable-threads=no \
647                 --enable-tls \
648                 --disable-nls \
649                 --disable-multilib \
650                 --enable-c99 \
651                 --enable-long-long \
652                 --enable-shared \
653                 --disable-canonical-prefixes \
654                 --disable-canonical-system-headers \
655                 $(GCC_BUILD_FLAGS);
656
657 cross-gcc-stage3-configure:
658         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
659         CFLAGS="-O2 -g -pipe" \
660         CXXFLAGS="-O2 -g -pipe" \
661         LDFLAGS="-lstdc++ -lm" \
662         ../gcc-$(GCC_VERSION)/configure \
663                 --target=$(ARCH)-ucb-akaros \
664                 --prefix=$(INSTDIR) \
665                 --with-sysroot=$(SYSROOT) \
666                 --enable-languages=c,c++,fortran \
667                 --with-pkgversion="akaros-repo" \
668                 --disable-__cxa_atexit \
669                 --disable-mudflap \
670                 --enable-libgomp \
671                 --disable-libssp \
672                 --disable-libquadmath \
673                 --disable-libquadmath-support \
674                 --with-ppl=no \
675                 --with-isl=no \
676                 --with-cloog=no \
677                 --with-libelf=no \
678                 --enable-threads=no \
679                 --disable-nls \
680                 --disable-multilib \
681                 --with-local-prefix=$(SYSROOT) \
682                 --enable-c99 \
683                 --enable-long-long \
684                 --enable-shared \
685                 --disable-canonical-prefixes \
686                 --disable-canonical-system-headers \
687                 $(GCC_BUILD_FLAGS);
688
689 .$(BINARY_PREFIX)gcc-stage3-configure:
690         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
691         if [ "$(CONFIG)" = "native" ]; then \
692                 $(MAKE) native-gcc-stage3-configure; \
693         else \
694                 $(MAKE) cross-gcc-stage3-configure; \
695         fi
696         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
697         touch $@
698
699 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
700         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
701         make -j $(MAKE_JOBS)
702
703 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
704         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
705         make -j $(MAKE_JOBS) install
706
707 ##################################
708 ######### GMP, MPFR, MPC #########
709 ##################################
710 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
711         rm -rf gmp-$(GMP_VERSION)
712         tar -jxf gmp-$(GMP_VERSION).tar.bz2
713         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
714
715 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
716         rm -rf mpfr-$(MPFR_VERSION)
717         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
718         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
719
720 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
721         rm -rf mpc-$(MPC_VERSION)
722         tar -zxf mpc-$(MPC_VERSION).tar.gz
723         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
724
725 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
726         rm -rf $@
727         mkdir -p $@
728
729 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
730         rm -rf $@
731         mkdir -p $@
732
733 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
734         rm -rf $@
735         mkdir -p $@
736
737 .$(BINARY_PREFIX)gmp-configure:
738         $(MAKE) $(BINARY_PREFIX)gmp-builddir
739         cd $(BINARY_PREFIX)gmp-builddir; \
740         ../gmp-$(GMP_VERSION)/configure \
741             --disable-static \
742             --prefix=$(INSTDIR) \
743             --host=$(ARCH)-ucb-akaros
744         touch $@
745
746 .$(BINARY_PREFIX)mpfr-configure:
747         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
748         cd $(BINARY_PREFIX)mpfr-builddir; \
749         ../mpfr-$(MPFR_VERSION)/configure \
750             --disable-static \
751             --prefix=$(INSTDIR) \
752             --with-gmp=$(INSTDIR) \
753             --host=$(ARCH)-ucb-akaros
754         touch $@
755
756 .$(BINARY_PREFIX)mpc-configure:
757         $(MAKE) $(BINARY_PREFIX)mpc-builddir
758         cd $(BINARY_PREFIX)mpc-builddir; \
759         ../mpc-$(MPC_VERSION)/configure \
760             --disable-static \
761             --prefix=$(INSTDIR) \
762             --with-gmp=$(INSTDIR) \
763             --with-mpfr=$(INSTDIR) \
764             --host=$(ARCH)-ucb-akaros
765         touch $@
766
767 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
768         cd $(BINARY_PREFIX)gmp-builddir; \
769         make -j $(MAKE_JOBS)
770
771 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
772         cd $(BINARY_PREFIX)mpfr-builddir; \
773         make -j $(MAKE_JOBS)
774
775 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
776         cd $(BINARY_PREFIX)mpc-builddir; \
777         make -j $(MAKE_JOBS)
778
779 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
780         cd $(BINARY_PREFIX)gmp-builddir; \
781         make -j $(MAKE_JOBS) install
782
783 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
784         cd $(BINARY_PREFIX)mpfr-builddir; \
785         make -j $(MAKE_JOBS) install
786
787 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
788         cd $(BINARY_PREFIX)mpc-builddir; \
789         make -j $(MAKE_JOBS) install
790
791 endif # BUILD_ERROR
792 endif # AKAROS_COMPILER_REAL_BUILD