Use patches for existing toolchain files (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-directory-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-directory.patch; \
352              patch -p2 < ../.gcc-$(GCC_VERSION)-akaros-directory.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-directory-patch
361         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-r233572.patch
362         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
363         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-existing.patch
364         (cd gcc-$(GCC_VERSION) && \
365          ln -s ../gmp-$(GMP_VERSION) gmp && \
366          ln -s ../mpfr-$(MPFR_VERSION) mpfr && \
367          ln -s ../mpc-$(MPC_VERSION) mpc)
368
369 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
370         rm -rf $@
371         mkdir -p $@
372
373 .$(BINARY_PREFIX)gcc-stage1-configure: 
374         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
375         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
376         CFLAGS="-O2 -g -pipe" \
377         CXXFLAGS="-O2 -g -pipe" \
378         LDFLAGS="-lstdc++ -lm" \
379         ../gcc-$(GCC_VERSION)/configure \
380                 --target=$(ARCH)-ucb-akaros \
381                 --prefix=$(INSTDIR) \
382                 --with-local-prefix=$(SYSROOT) \
383                 --disable-mudflap \
384                 --with-sysroot=$(SYSROOT) \
385                 --with-newlib \
386                 --enable-threads=no \
387                 --enable-tls \
388                 --disable-shared \
389                 --with-pkgversion="akaros-repo" \
390                 --disable-__cxa_atexit \
391                 --with-ppl=no \
392                 --with-isl=no \
393                 --with-cloog=no \
394                 --with-libelf=no \
395                 --disable-lto \
396                 --disable-libgomp \
397                 --disable-mudflap \
398                 --disable-nls \
399                 --disable-multilib \
400                 --enable-languages=c \
401                 --enable-linker-build-id \
402                 $(GCC_BUILD_FLAGS);
403         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
404         touch $@
405
406 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
407         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
408         make -j $(MAKE_JOBS) all-gcc;
409
410 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
411         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
412         make -j $(MAKE_JOBS) install-gcc;
413
414 #################################
415 ########## GCC Stage 2 ##########
416 #################################
417 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
418         rm -rf $@
419         mkdir -p $@
420
421 .$(BINARY_PREFIX)gcc-stage2-configure: 
422         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
423         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
424         CFLAGS="-O2 -g -pipe" \
425         CXXFLAGS="-O2 -g -pipe" \
426         LDFLAGS="-lstdc++ -lm" \
427         ../gcc-$(GCC_VERSION)/configure \
428                 --target=$(ARCH)-ucb-akaros \
429                 --prefix=$(INSTDIR) \
430                 --with-local-prefix=$(SYSROOT) \
431                 --disable-mudflap \
432                 --with-sysroot=$(SYSROOT) \
433                 --with-newlib \
434                 --enable-threads=no \
435                 --enable-tls \
436                 --disable-shared \
437                 --with-pkgversion="akaros-repo" \
438                 --disable-__cxa_atexit \
439                 --with-ppl=no \
440                 --with-sil=no \
441                 --with-cloog=no \
442                 --with-libelf=no \
443                 --disable-lto \
444                 --disable-libgomp \
445                 --disable-libmudflap \
446                 --disable-nls \
447                 --enable-languages=c,c++,fortran \
448                 --disable-multilib \
449                 --enable-linker-build-id \
450                 $(GCC_BUILD_FLAGS);
451         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
452         touch $@
453
454 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
455         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
456         make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
457                              all-gcc \
458                              all-target-libgcc;
459
460 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
461         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
462         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
463
464 #################################
465 ############ Headers ############
466 #################################
467 .$(BINARY_PREFIX)headers-clean:
468         rm -rf $(SYSROOT)/usr/include/*
469
470 .$(BINARY_PREFIX)akaros-headers-install: $(AKAROSDIR)
471         mkdir -p $(SYSROOT)/usr/include
472         rm -rf $(SYSROOT)/usr/include/ros
473         cp -r $(AKAROSDIR)/kern/include/ros \
474             $(SYSROOT)/usr/include/
475         rm -rf $(SYSROOT)/usr/include/ros/arch
476         mkdir -p $(SYSROOT)/usr/include/ros/arch
477         cp -r $(AKAROSDIR)/kern/arch/$(AKAROS_ARCH_DIR)/ros/* \
478             $(SYSROOT)/usr/include/ros/arch/
479         cp -r $(AKAROSDIR)/user/parlib/include/* \
480             $(SYSROOT)/usr/include/
481         cp -r $(AKAROSDIR)/user/pthread/*.h \
482             $(SYSROOT)/usr/include/
483
484 #################################
485 ###### Dummy Libs Install #######
486 #################################
487 .$(BINARY_PREFIX)dummy-libs-install:
488         rm -rf $(SYSROOT)/usr/lib/libparlib.a
489         mkdir -p $(SYSROOT)/usr/lib
490         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
491
492 #################################
493 ######### Glibc Stage 1 #########
494 #################################
495 .glibc-akaros-directory-patch:
496         -cd glibc-$(GLIBC_VERSION); \
497         diff -ruB --unidirectional-new-file \
498              ../glibc-$(GLIBC_VERSION) \
499              ../glibc-$(GLIBC_VERSION)-akaros \
500              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
501              > ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch; \
502              patch -p2 < ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch
503
504 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
505 # parlib's pthread.h.
506 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
507         rm -rf glibc-$(GLIBC_VERSION)
508         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
509         rm glibc-$(GLIBC_VERSION)/include/pthread.h
510         $(MAKE) .glibc-akaros-directory-patch
511         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
512         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-existing.patch
513
514 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
515         rm -rf $@
516         mkdir -p $@
517
518 .$(BINARY_PREFIX)glibc-stage1-configure: 
519         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
520         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
521         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
522         CXXFLAGS="-fpermissive" \
523         CC=$(ARCH)-ucb-akaros-gcc \
524         AR=$(ARCH)-ucb-akaros-ar \
525         RANLIB=$(ARCH)-ucb-akaros-ranlib \
526         ../glibc-$(GLIBC_VERSION)/configure \
527                 --prefix=/usr \
528                 --host=$(ARCH)-ucb-akaros \
529                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
530                 --without-cvs \
531                 --disable-profile \
532                 --without-gd \
533                 --with-headers=$(SYSROOT)/usr/include \
534                 --disable-debug \
535                 --disable-sanity-checks \
536                 --enable-kernel= \
537                 --with-__thread \
538                 --with-tls \
539                 --without-nptl \
540                 --enable-shared \
541                 --enable-add-ons=no \
542                 --with-pkgversion="akaros-repo" \
543                 --with-elf \
544                 --enable-hacker-mode \
545                 --enable-static-nss \
546                 --enable-obsolete-rpc \
547                 --disable-build-nscd \
548                 --disable-nscd \
549                 $(GLIBC_CONFIGURE_FLAGS);
550         touch $@
551
552 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
553         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
554         make -j $(MAKE_JOBS) \
555                 install_root=$(SYSROOT) \
556                 install-bootstrap-headers=yes \
557                 install-headers; \
558         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
559         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
560         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
561         make -j $(MAKE_JOBS) csu/subdir_lib;
562
563 ####################################
564 ########## Glibc Stage 2  ##########
565 ####################################
566 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
567         rm -rf $@
568         mkdir -p $@
569
570 .$(BINARY_PREFIX)glibc-stage2-configure: 
571         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
572         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
573         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
574         CXXFLAGS="-fpermissive" \
575         CC=x86_64-ucb-akaros-gcc \
576         AR=x86_64-ucb-akaros-ar \
577         RANLIB=x86_64-ucb-akaros-ranlib \
578         ../glibc-$(GLIBC_VERSION)/configure \
579                 --prefix=/usr \
580                 --host=$(ARCH)-ucb-akaros \
581                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
582                 --without-cvs \
583                 --disable-profile \
584                 --without-gd \
585                 --with-headers=$(SYSROOT)/usr/include \
586                 --disable-debug \
587                 --disable-sanity-checks \
588                 --enable-kernel= \
589                 --with-__thread \
590                 --with-tls \
591                 --without-nptl \
592                 --enable-shared \
593                 --enable-add-ons=no \
594                 --with-pkgversion="akaros-repo" \
595                 --with-elf \
596                 --enable-hacker-mode \
597                 --enable-static-nss \
598                 --enable-obsolete-rpc \
599                 --disable-build-nscd \
600                 --disable-nscd \
601                 $(GLIBC_CONFIGURE_FLAGS);
602         touch $@
603
604 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
605         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
606         make -j $(MAKE_JOBS)
607
608 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
609         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
610         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
611
612 ###################################
613 ####### AKAROS Libs Install #######
614 ###################################
615 .$(BINARY_PREFIX)akaros-libs-install:
616         cd $(AKAROSDIR); \
617         make ARCH=$(AKAROS_ARCH_DIR) userclean; \
618         make ARCH=$(AKAROS_ARCH_DIR) -j $(MAKE_JOBS) install-base-libs
619
620 ##################################
621 ########### Gcc Stage 3 ##########
622 ##################################
623 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
624         rm -rf $@
625         mkdir -p $@
626
627 native-gcc-stage3-prep:
628         mkdir -p $(INSTDIR)/usr; \
629
630 native-gcc-stage3-configure: native-gcc-stage3-prep
631         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
632         ../gcc-$(GCC_VERSION)/configure \
633                 --target=$(ARCH)-ucb-akaros \
634                 --host=$(ARCH)-ucb-akaros \
635                 --prefix=$(INSTDIR) \
636                 --with-gmp=$(XCCROOT) \
637                 --with-mpfr=$(XCCROOT) \
638                 --with-mpc=$(XCCROOT) \
639                 --enable-languages=c,c++,fortran \
640                 --with-pkgversion="akaros-repo" \
641                 --disable-__cxa_atexit \
642                 --disable-mudflap \
643                 --enable-libgomp \
644                 --disable-libssp \
645                 --disable-libquadmath \
646                 --disable-libquadmath-support \
647                 --with-ppl=no \
648                 --with-isl=no \
649                 --with-cloog=no \
650                 --with-libelf=no \
651                 --enable-threads=akaros \
652                 --enable-tls \
653                 --disable-nls \
654                 --disable-multilib \
655                 --enable-c99 \
656                 --enable-long-long \
657                 --enable-shared \
658                 --disable-canonical-prefixes \
659                 --disable-canonical-system-headers \
660                 --enable-linker-build-id \
661                 $(GCC_BUILD_FLAGS);
662
663 cross-gcc-stage3-configure:
664         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
665         CFLAGS="-O2 -g -pipe" \
666         CXXFLAGS="-O2 -g -pipe" \
667         LDFLAGS="-lstdc++ -lm" \
668         ../gcc-$(GCC_VERSION)/configure \
669                 --target=$(ARCH)-ucb-akaros \
670                 --prefix=$(INSTDIR) \
671                 --with-sysroot=$(SYSROOT) \
672                 --enable-languages=c,c++,fortran \
673                 --with-pkgversion="akaros-repo" \
674                 --disable-__cxa_atexit \
675                 --disable-mudflap \
676                 --enable-libgomp \
677                 --disable-libssp \
678                 --disable-libquadmath \
679                 --disable-libquadmath-support \
680                 --with-ppl=no \
681                 --with-isl=no \
682                 --with-cloog=no \
683                 --with-libelf=no \
684                 --enable-threads=akaros \
685                 --disable-nls \
686                 --disable-multilib \
687                 --with-local-prefix=$(SYSROOT) \
688                 --enable-c99 \
689                 --enable-long-long \
690                 --enable-shared \
691                 --disable-canonical-prefixes \
692                 --disable-canonical-system-headers \
693                 --enable-linker-build-id \
694                 $(GCC_BUILD_FLAGS);
695
696 .$(BINARY_PREFIX)gcc-stage3-configure:
697         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
698         if [ "$(CONFIG)" = "native" ]; then \
699                 $(MAKE) native-gcc-stage3-configure; \
700         else \
701                 $(MAKE) cross-gcc-stage3-configure; \
702         fi
703         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
704         touch $@
705
706 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
707         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
708         make -j $(MAKE_JOBS)
709
710 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
711         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
712         make -j $(MAKE_JOBS) install
713
714 ##################################
715 ######### GMP, MPFR, MPC #########
716 ##################################
717 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
718         rm -rf gmp-$(GMP_VERSION)
719         tar -jxf gmp-$(GMP_VERSION).tar.bz2
720         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
721
722 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
723         rm -rf mpfr-$(MPFR_VERSION)
724         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
725         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
726
727 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
728         rm -rf mpc-$(MPC_VERSION)
729         tar -zxf mpc-$(MPC_VERSION).tar.gz
730         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
731
732 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
733         rm -rf $@
734         mkdir -p $@
735
736 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
737         rm -rf $@
738         mkdir -p $@
739
740 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
741         rm -rf $@
742         mkdir -p $@
743
744 .$(BINARY_PREFIX)gmp-configure:
745         $(MAKE) $(BINARY_PREFIX)gmp-builddir
746         cd $(BINARY_PREFIX)gmp-builddir; \
747         ../gmp-$(GMP_VERSION)/configure \
748             --disable-static \
749             --prefix=$(INSTDIR) \
750             --host=$(ARCH)-ucb-akaros
751         touch $@
752
753 .$(BINARY_PREFIX)mpfr-configure:
754         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
755         cd $(BINARY_PREFIX)mpfr-builddir; \
756         ../mpfr-$(MPFR_VERSION)/configure \
757             --disable-static \
758             --prefix=$(INSTDIR) \
759             --with-gmp=$(INSTDIR) \
760             --host=$(ARCH)-ucb-akaros
761         touch $@
762
763 .$(BINARY_PREFIX)mpc-configure:
764         $(MAKE) $(BINARY_PREFIX)mpc-builddir
765         cd $(BINARY_PREFIX)mpc-builddir; \
766         ../mpc-$(MPC_VERSION)/configure \
767             --disable-static \
768             --prefix=$(INSTDIR) \
769             --with-gmp=$(INSTDIR) \
770             --with-mpfr=$(INSTDIR) \
771             --host=$(ARCH)-ucb-akaros
772         touch $@
773
774 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
775         cd $(BINARY_PREFIX)gmp-builddir; \
776         make -j $(MAKE_JOBS)
777
778 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
779         cd $(BINARY_PREFIX)mpfr-builddir; \
780         make -j $(MAKE_JOBS)
781
782 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
783         cd $(BINARY_PREFIX)mpc-builddir; \
784         make -j $(MAKE_JOBS)
785
786 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
787         cd $(BINARY_PREFIX)gmp-builddir; \
788         make -j $(MAKE_JOBS) install
789
790 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
791         cd $(BINARY_PREFIX)mpfr-builddir; \
792         make -j $(MAKE_JOBS) install
793
794 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
795         cd $(BINARY_PREFIX)mpc-builddir; \
796         make -j $(MAKE_JOBS) install
797
798 endif # BUILD_ERROR
799 endif # AKAROS_COMPILER_REAL_BUILD