350d2900b89a7e160bdb4da260f0f1f6ec02b5df
[akaros.git] / tools / compilers / gcc-glibc / Makefile
1 # Number of make jobs to spawn.  Define it in Makelocal
2 MAKE_JOBS :=
3
4 BINUTILS_VERSION := 2.24
5 GCC_VERSION := 4.9.2
6 GLIBC_VERSION := 2.19
7 GMP_VERSION := 5.1.3
8 MPFR_VERSION := 3.1.2
9 MPC_VERSION := 1.0.2
10
11 # Defines where to install the toolchain
12 -include Makelocal
13
14 define print-usage
15         @echo "Usage: make <arch> [ <config> ] [ <subcmd> ] "
16         @echo "    Valid archs are: 'x86_64', 'riscv'"
17         @echo "    Valid configs are: 'cross', 'native'"
18         @echo "    Valid subcommands are: 'build', 'uninstall', check-env'"
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
34 VALID_CLEANS := clean inst-clean
35 VALID_TARGETS := $(VALID_ARCHS) $(VALID_CONFIGS) \
36                  $(VALID_SUBCMDS) $(VALID_CLEANS)
37 ARCH := $(filter $(VALID_ARCHS),$(MAKECMDGOALS))
38 CONFIG := $(filter $(VALID_CONFIGS),$(MAKECMDGOALS))
39 SUBCMDS := $(filter $(VALID_SUBCMDS),$(MAKECMDGOALS))
40 CLEANS := $(filter $(VALID_CLEANS),$(MAKECMDGOALS))
41 INVALID_TARGETS := $(filter-out $(VALID_TARGETS),$(MAKECMDGOALS))
42 NONCLEANGOALS := $(filter-out $(CLEANS),$(MAKECMDGOALS))
43 ifeq ($(words $(CONFIG)),0)
44     CONFIG := cross
45 endif
46 ifeq ($(words $(SUBCMDS)),0)
47     SUBCMDS := build
48 endif
49
50 .PHONY: $(VALID_TARGETS)
51
52 OK_TO_BUILD :=
53 ifeq ($(words $(ARCH)),1)
54     ifeq ($(words $(CONFIG)),1)
55         ifeq ($(INVALID_TARGETS),)
56             OK_TO_BUILD := 1
57         endif
58     endif
59 endif
60 ifeq ($(OK_TO_BUILD),)
61 all $(NONCLEANGOALS): make-real
62         @echo "" > /dev/null
63 make-real:
64         $(print-usage)
65 else
66 all $(NONCLEANGOALS): make-real
67         @echo "" > /dev/null
68 make-real:
69         @export AKAROS_COMPILER_REAL_BUILD=true; \
70          export ARCH=$(ARCH); \
71          export CONFIG=$(CONFIG); \
72          $(MAKE) --no-print-directory $(patsubst %, %-real, $(SUBCMDS))
73 endif
74
75 clean:
76         @rm -rf binutils-$(BINUTILS_VERSION)
77         @rm -rf gcc-$(GCC_VERSION)
78         @rm -rf glibc-$(GLIBC_VERSION)
79         @rm -rf gmp-$(GMP_VERSION)
80         @rm -rf mpfr-$(MPFR_VERSION)
81         @rm -rf mpc-$(MPC_VERSION)
82         @rm -rf *-builddir
83         @rm -rf .*-configure
84         @rm -rf .glibc-$(GLIBC_VERSION)-akaros.patch
85         @rm -rf .gcc-$(GCC_VERSION)-akaros.patch
86         @echo "    Removed configs, build dirs, and extracted sources"
87
88 inst-clean: clean
89         @for a in $(VALID_ARCHS); do \
90                 for c in $(VALID_CONFIGS); do \
91                         $(MAKE) --no-print-directory $$a $$c uninstall; \
92                 done \
93         done
94
95 else # AKAROS_COMPILER_REAL_BUILD
96
97 # Set up some global variables to help us through the make based on the
98 # platform we are building for.
99 ifeq ($(ARCH),x86_64)
100     AKAROS_ARCH_DIR := x86
101     ARCH_CFLAGS :=
102     GLIBC_CONFIGURE_FLAGS := "--disable-multi-arch"
103     GCC_BUILD_FLAGS := CFLAGS="-fPIC"
104 endif
105 ifeq ($(ARCH),riscv)
106     AKAROS_ARCH_DIR := riscv
107     ARCH_CFLAGS :=
108     GLIBC_CONFIGURE_FLAGS := 
109     GCC_BUILD_FLAGS :=
110 endif
111 ifeq ($(CONFIG),cross)
112     INSTDIR_STRING := $(shell echo $(ARCH) | tr 'a-z' 'A-Z')_INSTDIR
113 else
114     INSTDIR_STRING := $(shell echo $(ARCH) | tr 'a-z' 'A-Z')_NATIVE_INSTDIR
115     XCCROOT := $(shell dirname $(shell which $(ARCH)-ucb-akaros-gcc) 2>/dev/null)/..
116 endif
117 BUILDDIR ?= $(shell pwd)/
118 AKAROSDIR ?= $(BUILDDIR)/../../../
119 INSTDIR := $($(INSTDIR_STRING))
120 BINARY_PREFIX := $(ARCH)-ucb-akaros-
121 SYSROOT := $(INSTDIR)/$(ARCH)-ucb-akaros/sysroot
122 PATH := /$(INSTDIR)/bin:$(PATH)
123
124 BUILD_ERRORS :=
125 BUILD_ERROR_DELIMITER := <\#\#>
126 define add_error
127 $(BUILD_ERRORS)$(1)$(BUILD_ERROR_DELIMITER)
128 endef
129
130 # Check for additional errors before building
131 AWK := $(shell awk -W version 2>&1 | head -n 1 | awk '{print $$1}')
132 ifneq ($(AWK),GNU)
133 define BUILD_ERROR
134     You need to have 'gawk' installed on your system before proceeding!"
135 endef
136 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
137 endif
138 ifeq ($(INSTDIR),)
139 define BUILD_ERROR
140     You need to setup $(INSTDIR_STRING), to point to where you
141     want your compiler installed. The best way to do this is to create
142     a 'Makelocal' file in the current directory and put a definition
143     for this variable in there.
144 endef
145 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
146 endif 
147 ifeq ($(CONFIG),native)
148 ifeq ($(shell which $(ARCH)-ucb-akaros-gcc 2>/dev/null),)
149 define BUILD_ERROR
150     No $(ARCH) Akaros cross-compiler installed in path. Make sure you have
151     built and installed the $(ARCH) cross-compiler using 'make $(ARCH)'
152     before trying to build the crossed-native compiler.
153 endef
154 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
155 endif
156 endif
157 ifeq ($(ARCH),riscv)
158 ifeq ($(shell grep "CONFIG_RISCV=y" $(AKAROSDIR)/.config),)
159 define BUILD_ERROR
160     Akaros tree not configured for $(ARCH)
161     Make sure you have configured AKAROSDIR for this architecture before proceeding
162     e.g. cd $$AKAROSDIR
163          make ARCH=riscv defconfig
164 endef
165 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
166 endif
167 endif
168 ifeq ($(ARCH),x86_64)
169 ifeq ($(shell grep "CONFIG_X86_64=y" $(AKAROSDIR)/.config),)
170 define BUILD_ERROR
171     Akaros tree not configured for x86_64
172     Make sure you have configured AKAROSDIR for this architecture before proceeding
173     e.g. cd $$AKAROSDIR
174          make ARCH=x86 defconfig
175          make ARCH=x86 menuconfig -> Set 64 bit option
176 endef
177 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
178 endif
179 endif
180
181 ROBUST_SUBCMDS := uninstall
182 ifeq ($(filter-out $(patsubst %, %-real, $(ROBUST_SUBCMDS)), $(MAKECMDGOALS)),)
183     BUILD_ERRORS :=
184 endif
185
186 ifdef BUILD_ERRORS
187
188 export BUILD_ERRORS
189 $(MAKECMDGOALS): make-real
190         @echo "" > /dev/null
191 make-real:
192         @echo "$${BUILD_ERRORS}" |\
193         awk '\
194                 BEGIN { RS="<##>"; FS="<##>"; }\
195                 { str[NR] = $$i; }\
196                 END { for (i = 1; i < NR; i++) {\
197                                 print "Error Detected:";\
198                                 print substr(str[i], 2); }}\
199         '
200         @exit 2
201
202 else # BUILD_ERROR
203
204 check-env-real:
205         @echo "    Your environment checks out. Build away!"
206
207 ifeq ($(CONFIG),cross)
208 build-real:
209         $(MAKE) .$(BINARY_PREFIX)binutils-install
210         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
211         $(MAKE) .$(BINARY_PREFIX)akaros-headers-install
212         $(MAKE) .$(BINARY_PREFIX)dummy-libs-install
213         $(MAKE) .$(BINARY_PREFIX)glibc-stage1-install
214         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-install
215         $(MAKE) .$(BINARY_PREFIX)glibc-stage2-install
216         $(MAKE) .$(BINARY_PREFIX)akaros-libs-install
217         $(MAKE) .$(BINARY_PREFIX)gcc-stage3-install
218         $(MAKE) .$(BINARY_PREFIX)gmp-install
219         $(MAKE) .$(BINARY_PREFIX)mpfr-install
220         $(MAKE) .$(BINARY_PREFIX)mpc-install
221 else
222 build-real:
223         $(MAKE) .$(BINARY_PREFIX)binutils-install
224         $(MAKE) .$(BINARY_PREFIX)gcc-stage3-install
225 endif
226
227 uninstall-real:
228         @dir=$(INSTDIR);\
229         if [ "$${dir}" != "" ]; then\
230                 rm -rf $${dir};\
231                 echo "    Removed $${dir} ($(ARCH)-$(CONFIG)-inst)";\
232         fi
233
234 %.tar.bz2:
235         wget http://akaros.cs.berkeley.edu/xcc/$@
236
237 %.tar.gz:
238         wget http://akaros.cs.berkeley.edu/xcc/$@
239
240 #################################
241 ########### BINUTILS ############
242 #################################
243 binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
244         rm -rf binutils-$(BINUTILS_VERSION);
245         tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
246         patch -p0 < binutils-$(BINUTILS_VERSION)-akaros.patch
247         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
248
249 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
250         rm -rf $@
251         mkdir -p $@
252
253 native-binutils-configure:
254         cd $(BINARY_PREFIX)binutils-builddir; \
255         CFLAGS="-O2 -g -pipe" \
256         CXXFLAGS="-O2 -g -pipe" \
257         LDFLAGS="" \
258         ../binutils-$(BINUTILS_VERSION)/configure \
259                 --target=$(ARCH)-ucb-akaros \
260                 --host=$(ARCH)-ucb-akaros \
261                 --prefix=$(INSTDIR) \
262                 --disable-werror \
263                 --enable-ld=yes \
264                 --enable-gold=yes \
265                 --enable-plugins=yes \
266                 --with-pkgversion="akaros-repo" \
267                 --disable-multilib \
268                 --disable-nls
269
270 cross-binutils-configure:
271         cd $(BINARY_PREFIX)binutils-builddir; \
272         CFLAGS="-O2 -g -pipe" \
273         CXXFLAGS="-O2 -g -pipe" \
274         LDFLAGS="" \
275         ../binutils-$(BINUTILS_VERSION)/configure \
276                 --target=$(ARCH)-ucb-akaros \
277                 --prefix=$(INSTDIR) \
278                 --disable-werror \
279                 --enable-ld=yes \
280                 --enable-gold=yes \
281                 --enable-plugins=yes \
282                 --with-pkgversion="akaros-repo" \
283                 --disable-multilib \
284                 --disable-nls \
285                 --with-sysroot=$(SYSROOT)
286
287 .$(BINARY_PREFIX)binutils-configure: 
288         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
289         if [ "$(CONFIG)" = "native" ]; then \
290                 $(MAKE) native-binutils-configure; \
291         else \
292                 $(MAKE) cross-binutils-configure; \
293         fi
294         echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
295         touch $@
296
297 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
298         cd $(BINARY_PREFIX)binutils-builddir; \
299         make -j $(MAKE_JOBS)
300
301 .$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
302         cd $(BINARY_PREFIX)binutils-builddir; \
303         make -j $(MAKE_JOBS) install
304
305 binutils-clean:
306         cd $(BINARY_PREFIX)binutils-builddir; \
307         make clean
308
309 #################################
310 ########## GCC Stage 1 ##########
311 #################################
312 .gcc-akaros-patch:
313         -cd gcc-$(GCC_VERSION); \
314         diff -ruB --unidirectional-new-file \
315              ../gcc-$(GCC_VERSION) \
316              ../gcc-$(GCC_VERSION)-akaros \
317              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
318              > ../.gcc-$(GCC_VERSION)-akaros.patch; \
319              patch -p2 < ../.gcc-$(GCC_VERSION)-akaros.patch
320
321 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2 \
322                     gmp-$(GMP_VERSION) \
323                     mpfr-$(MPFR_VERSION) \
324                     mpc-$(MPC_VERSION)
325         rm -rf gcc-$(GCC_VERSION)
326         tar -jxf gcc-$(GCC_VERSION).tar.bz2
327         $(MAKE) .gcc-akaros-patch
328         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
329         (cd gcc-$(GCC_VERSION) && \
330          ln -s ../gmp-$(GMP_VERSION) gmp && \
331          ln -s ../mpfr-$(MPFR_VERSION) mpfr && \
332          ln -s ../mpc-$(MPC_VERSION) mpc)
333
334 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
335         rm -rf $@
336         mkdir -p $@
337
338 .$(BINARY_PREFIX)gcc-stage1-configure: 
339         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
340         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
341         CFLAGS="-O2 -g -pipe" \
342         CXXFLAGS="-O2 -g -pipe" \
343         LDFLAGS="-lstdc++ -lm" \
344         ../gcc-$(GCC_VERSION)/configure \
345                 --target=$(ARCH)-ucb-akaros \
346                 --prefix=$(INSTDIR) \
347                 --with-local-prefix=$(SYSROOT) \
348                 --disable-mudflap \
349                 --with-sysroot=$(SYSROOT) \
350                 --with-newlib \
351                 --enable-threads=no \
352                 --enable-tls \
353                 --disable-shared \
354                 --with-pkgversion="akaros-repo" \
355                 --disable-__cxa_atexit \
356                 --with-ppl=no \
357                 --with-isl=no \
358                 --with-cloog=no \
359                 --with-libelf=no \
360                 --disable-lto \
361                 --disable-libgomp \
362                 --disable-mudflap \
363                 --disable-nls \
364                 --disable-multilib \
365                 --enable-languages=c \
366                 $(GCC_BUILD_FLAGS);
367         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
368         touch $@
369
370 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
371         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
372         make -j $(MAKE_JOBS) all-gcc;
373
374 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
375         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
376         make -j $(MAKE_JOBS) install-gcc;
377
378 #################################
379 ########## GCC Stage 2 ##########
380 #################################
381 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
382         rm -rf $@
383         mkdir -p $@
384
385 .$(BINARY_PREFIX)gcc-stage2-configure: 
386         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
387         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
388         CFLAGS="-O2 -g -pipe" \
389         CXXFLAGS="-O2 -g -pipe" \
390         LDFLAGS="-lstdc++ -lm" \
391         ../gcc-$(GCC_VERSION)/configure \
392                 --target=$(ARCH)-ucb-akaros \
393                 --prefix=$(INSTDIR) \
394                 --with-local-prefix=$(SYSROOT) \
395                 --disable-mudflap \
396                 --with-sysroot=$(SYSROOT) \
397                 --with-newlib \
398                 --enable-threads=no \
399                 --enable-tls \
400                 --disable-shared \
401                 --with-pkgversion="akaros-repo" \
402                 --disable-__cxa_atexit \
403                 --with-ppl=no \
404                 --with-sil=no \
405                 --with-cloog=no \
406                 --with-libelf=no \
407                 --disable-lto \
408                 --disable-libgomp \
409                 --disable-libmudflap \
410                 --disable-nls \
411                 --enable-languages=c,c++,fortran \
412                 --disable-multilib \
413                 $(GCC_BUILD_FLAGS);
414         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
415         touch $@
416
417 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
418         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
419         make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
420                              all-gcc \
421                              all-target-libgcc;
422
423 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
424         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
425         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
426
427 ####################################
428 ######### AKAROS Headers ###########
429 ####################################
430 .$(BINARY_PREFIX)akaros-headers-install: $(AKAROSDIR)
431         rm -rf $(SYSROOT)/usr/include/*
432         mkdir -p $(SYSROOT)/usr/include
433         cp -r $(AKAROSDIR)/kern/include/ros \
434             $(SYSROOT)/usr/include/
435         rm -f $(SYSROOT)/usr/include/ros/arch
436         mkdir $(SYSROOT)/usr/include/ros/arch
437         cp -r $(AKAROSDIR)/kern/arch/$(AKAROS_ARCH_DIR)/ros/* \
438             $(SYSROOT)/usr/include/ros/arch/
439         mkdir -p $(SYSROOT)/usr/include/parlib
440         cp -r $(AKAROSDIR)/user/parlib/include/* \
441             $(SYSROOT)/usr/include/parlib/
442         cp -r $(AKAROSDIR)/user/pthread/*.h \
443             $(SYSROOT)/usr/include/
444
445 #################################
446 ###### Dummy Libs Install #######
447 #################################
448 .$(BINARY_PREFIX)dummy-libs-install:
449         rm -rf $(SYSROOT)/usr/lib/libparlib.a
450         mkdir -p $(SYSROOT)/usr/lib
451         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
452
453 #################################
454 ######### Glibc Stage 1 #########
455 #################################
456 .glibc-akaros-patch:
457         -cd glibc-$(GLIBC_VERSION); \
458         diff -ruB --unidirectional-new-file \
459              ../glibc-$(GLIBC_VERSION) \
460              ../glibc-$(GLIBC_VERSION)-akaros \
461              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
462              > ../.glibc-$(GLIBC_VERSION)-akaros.patch; \
463              patch -p2 < ../.glibc-$(GLIBC_VERSION)-akaros.patch
464
465 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
466 # parlib's pthread.h.
467 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
468         rm -rf glibc-$(GLIBC_VERSION)
469         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
470         rm glibc-$(GLIBC_VERSION)/include/pthread.h
471         $(MAKE) .glibc-akaros-patch
472         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
473
474 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
475         rm -rf $@
476         mkdir -p $@
477
478 .$(BINARY_PREFIX)glibc-stage1-configure: 
479         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
480         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
481         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
482         CXXFLAGS="-fpermissive" \
483         CC=$(ARCH)-ucb-akaros-gcc \
484         AR=$(ARCH)-ucb-akaros-ar \
485         RANLIB=$(ARCH)-ucb-akaros-ranlib \
486         ../glibc-$(GLIBC_VERSION)/configure \
487                 --prefix=/usr \
488                 --host=$(ARCH)-ucb-akaros \
489                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
490                 --without-cvs \
491                 --disable-profile \
492                 --without-gd \
493                 --with-headers=$(SYSROOT)/usr/include \
494                 --disable-debug \
495                 --disable-sanity-checks \
496                 --enable-kernel= \
497                 --with-__thread \
498                 --with-tls \
499                 --without-nptl \
500                 --enable-shared \
501                 --enable-add-ons=no \
502                 --with-pkgversion="akaros-repo" \
503                 --with-elf \
504                 --enable-hacker-mode \
505                 --enable-static-nss \
506                 --enable-obsolete-rpc \
507                 --disable-build-nscd \
508                 --disable-nscd \
509                 $(GLIBC_CONFIGURE_FLAGS);
510         touch $@
511
512 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
513         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
514         make -j $(MAKE_JOBS) \
515                 install_root=$(SYSROOT) \
516                 install-bootstrap-headers=yes \
517                 install-headers; \
518         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
519         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
520         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
521         make -j $(MAKE_JOBS) csu/subdir_lib;
522
523 ####################################
524 ########## Glibc Stage 2  ##########
525 ####################################
526 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
527         rm -rf $@
528         mkdir -p $@
529
530 .$(BINARY_PREFIX)glibc-stage2-configure: 
531         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
532         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
533         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
534         CXXFLAGS="-fpermissive" \
535         CC=x86_64-ucb-akaros-gcc \
536         AR=x86_64-ucb-akaros-ar \
537         RANLIB=x86_64-ucb-akaros-ranlib \
538         ../glibc-$(GLIBC_VERSION)/configure \
539                 --prefix=/usr \
540                 --host=$(ARCH)-ucb-akaros \
541                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
542                 --without-cvs \
543                 --disable-profile \
544                 --without-gd \
545                 --with-headers=$(SYSROOT)/usr/include \
546                 --disable-debug \
547                 --disable-sanity-checks \
548                 --enable-kernel= \
549                 --with-__thread \
550                 --with-tls \
551                 --without-nptl \
552                 --enable-shared \
553                 --enable-add-ons=no \
554                 --with-pkgversion="akaros-repo" \
555                 --with-elf \
556                 --enable-hacker-mode \
557                 --enable-static-nss \
558                 --enable-obsolete-rpc \
559                 --disable-build-nscd \
560                 --disable-nscd \
561                 $(GLIBC_CONFIGURE_FLAGS);
562         touch $@
563
564 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
565         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
566         make -j $(MAKE_JOBS)
567
568 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
569         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
570         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
571
572 ###################################
573 ####### AKAROS Libs Install #######
574 ###################################
575 .$(BINARY_PREFIX)akaros-libs-install:
576         cd $(AKAROSDIR); \
577         make ARCH=$(AKAROS_ARCH_DIR) userclean; \
578         make ARCH=$(AKAROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
579
580 ##################################
581 ########### Gcc Stage 3 ##########
582 ##################################
583 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
584         rm -rf $@
585         mkdir -p $@
586
587 native-gcc-stage3-prep:
588         mkdir -p $(INSTDIR)/usr; \
589
590 native-gcc-stage3-configure: native-gcc-stage3-prep
591         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
592         ../gcc-$(GCC_VERSION)/configure \
593                 --target=$(ARCH)-ucb-akaros \
594                 --host=$(ARCH)-ucb-akaros \
595                 --prefix=$(INSTDIR) \
596                 --with-gmp=$(XCCROOT) \
597                 --with-mpfr=$(XCCROOT) \
598                 --with-mpc=$(XCCROOT) \
599                 --enable-languages=c,c++,fortran \
600                 --with-pkgversion="akaros-repo" \
601                 --disable-__cxa_atexit \
602                 --disable-mudflap \
603                 --enable-libgomp \
604                 --disable-libssp \
605                 --disable-libquadmath \
606                 --disable-libquadmath-support \
607                 --with-ppl=no \
608                 --with-isl=no \
609                 --with-cloog=no \
610                 --with-libelf=no \
611                 --enable-threads=no \
612                 --enable-tls \
613                 --disable-nls \
614                 --disable-multilib \
615                 --enable-c99 \
616                 --enable-long-long \
617                 --enable-shared \
618                 $(GCC_BUILD_FLAGS);
619
620 cross-gcc-stage3-configure:
621         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
622         CFLAGS="-O2 -g -pipe" \
623         CXXFLAGS="-O2 -g -pipe" \
624         LDFLAGS="-lstdc++ -lm" \
625         ../gcc-$(GCC_VERSION)/configure \
626                 --target=$(ARCH)-ucb-akaros \
627                 --prefix=$(INSTDIR) \
628                 --with-sysroot=$(SYSROOT) \
629                 --enable-languages=c,c++,fortran \
630                 --with-pkgversion="akaros-repo" \
631                 --disable-__cxa_atexit \
632                 --disable-mudflap \
633                 --enable-libgomp \
634                 --disable-libssp \
635                 --disable-libquadmath \
636                 --disable-libquadmath-support \
637                 --with-ppl=no \
638                 --with-isl=no \
639                 --with-cloog=no \
640                 --with-libelf=no \
641                 --enable-threads=no \
642                 --disable-nls \
643                 --disable-multilib \
644                 --with-local-prefix=$(SYSROOT) \
645                 --enable-c99 \
646                 --enable-long-long \
647                 --enable-shared \
648                 $(GCC_BUILD_FLAGS);
649
650 .$(BINARY_PREFIX)gcc-stage3-configure:
651         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
652         if [ "$(CONFIG)" = "native" ]; then \
653                 $(MAKE) native-gcc-stage3-configure; \
654         else \
655                 $(MAKE) cross-gcc-stage3-configure; \
656         fi
657         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
658         touch $@
659
660 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
661         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
662         make -j $(MAKE_JOBS)
663
664 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
665         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
666         make -j $(MAKE_JOBS) install
667
668 ##################################
669 ######### GMP, MPFR, MPC #########
670 ##################################
671 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
672         rm -rf gmp-$(GMP_VERSION)
673         tar -jxf gmp-$(GMP_VERSION).tar.bz2
674         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
675
676 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
677         rm -rf mpfr-$(MPFR_VERSION)
678         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
679         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
680
681 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
682         rm -rf mpc-$(MPC_VERSION)
683         tar -zxf mpc-$(MPC_VERSION).tar.gz
684         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
685
686 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
687         rm -rf $@
688         mkdir -p $@
689
690 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
691         rm -rf $@
692         mkdir -p $@
693
694 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
695         rm -rf $@
696         mkdir -p $@
697
698 .$(BINARY_PREFIX)gmp-configure:
699         $(MAKE) $(BINARY_PREFIX)gmp-builddir
700         cd $(BINARY_PREFIX)gmp-builddir; \
701         ../gmp-$(GMP_VERSION)/configure \
702             --disable-static \
703             --prefix=$(INSTDIR) \
704             --host=$(ARCH)-ucb-akaros
705         touch $@
706
707 .$(BINARY_PREFIX)mpfr-configure:
708         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
709         cd $(BINARY_PREFIX)mpfr-builddir; \
710         ../mpfr-$(MPFR_VERSION)/configure \
711             --disable-static \
712             --prefix=$(INSTDIR) \
713             --with-gmp=$(INSTDIR) \
714             --host=$(ARCH)-ucb-akaros
715         touch $@
716
717 .$(BINARY_PREFIX)mpc-configure:
718         $(MAKE) $(BINARY_PREFIX)mpc-builddir
719         cd $(BINARY_PREFIX)mpc-builddir; \
720         ../mpc-$(MPC_VERSION)/configure \
721             --disable-static \
722             --prefix=$(INSTDIR) \
723             --with-gmp=$(INSTDIR) \
724             --with-mpfr=$(INSTDIR) \
725             --host=$(ARCH)-ucb-akaros
726         touch $@
727
728 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
729         cd $(BINARY_PREFIX)gmp-builddir; \
730         make -j $(MAKE_JOBS)
731
732 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
733         cd $(BINARY_PREFIX)mpfr-builddir; \
734         make -j $(MAKE_JOBS)
735
736 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
737         cd $(BINARY_PREFIX)mpc-builddir; \
738         make -j $(MAKE_JOBS)
739
740 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
741         cd $(BINARY_PREFIX)gmp-builddir; \
742         make -j $(MAKE_JOBS) install
743
744 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
745         cd $(BINARY_PREFIX)mpfr-builddir; \
746         make -j $(MAKE_JOBS) install
747
748 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
749         cd $(BINARY_PREFIX)mpc-builddir; \
750         make -j $(MAKE_JOBS) install
751
752 endif # BUILD_ERROR
753 endif # AKAROS_COMPILER_REAL_BUILD