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