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