kconfig: use pkg-config for ncurses detection
[akaros.git] / tools / compilers / gcc-glibc / Makefile
index 1d58171..736499b 100644 (file)
-# Defines where to install the toolchain
--include Makelocal
+# Number of make jobs to spawn.  Define it in Makelocal
+MAKE_JOBS ?= $(shell expr `cat /proc/cpuinfo | grep processor | wc -l` - 1)
+
+BINUTILS_VERSION := 2.30
+GCC_VERSION := 4.9.2
+GLIBC_VERSION := 2.19
+GMP_VERSION := 5.1.3
+MPFR_VERSION := 3.1.2
+MPC_VERSION := 1.0.2
+
+ifndef AKAROS_TOOLCHAINS
+    $(error AKAROS_TOOLCHAINS is empty!  You must set it!)
+endif
 
-ifndef RAMP_INSTDIR
-ifndef X86_INSTDIR
-busted: 
-       @echo "You need to setup either a RAMP_INSTDIR or X86_INSTDIR to point to where you want the tools installed. The best way to do this is to create a 'Makelocal' file in the current directory and put it in there."
+# Defines where to install the toolchain
+RISCV_INSTDIR         := $(AKAROS_TOOLCHAINS)/riscv-ucb-akaros-gcc/
+X86_64_INSTDIR        := $(AKAROS_TOOLCHAINS)/x86_64-ucb-akaros-gcc/
+X86_64_NATIVE_INSTDIR := $(AKAROS_TOOLCHAINS)/x86_64-ucb-akaros-gcc-native/
+
+define print-usage
+       @echo "Usage: make <arch> [ <config> ] [ <subcmd> ] "
+       @echo "    Valid archs are: 'x86_64', 'riscv'"
+       @echo "    Valid configs are: 'cross', 'native'"
+       @echo "    Valid subcommands are: 'build', 'uninstall', check-env' 'install-headers'"
+       @echo "    If no config is specified, the 'cross' config is assumed by default."
+       @echo "    If no subcommand is specified, the 'build' subcommand is assumed by default."
+       @echo ""
+       @echo "Additional pseudo targets exist for:"
+       @echo "    make clean"
+       @echo "        Cleanup the build environment"
+       @echo "    make inst-clean"
+       @echo "        Cleanup the build environment and uninstall all compilers for all archs."
+endef
+
+# Make sure the list of targets is sane!
+ifndef AKAROS_COMPILER_REAL_BUILD
+VALID_ARCHS := x86_64 riscv
+VALID_CONFIGS := cross native
+VALID_SUBCMDS := build uninstall check-env install-headers
+VALID_CLEANS := clean inst-clean
+VALID_TARGETS := $(VALID_ARCHS) $(VALID_CONFIGS) \
+                 $(VALID_SUBCMDS) $(VALID_CLEANS)
+ARCH := $(filter $(VALID_ARCHS),$(MAKECMDGOALS))
+CONFIG := $(filter $(VALID_CONFIGS),$(MAKECMDGOALS))
+SUBCMDS := $(filter $(VALID_SUBCMDS),$(MAKECMDGOALS))
+CLEANS := $(filter $(VALID_CLEANS),$(MAKECMDGOALS))
+INVALID_TARGETS := $(filter-out $(VALID_TARGETS),$(MAKECMDGOALS))
+NONCLEANGOALS := $(filter-out $(CLEANS),$(MAKECMDGOALS))
+ifeq ($(words $(CONFIG)),0)
+    CONFIG := cross
+endif
+ifeq ($(words $(SUBCMDS)),0)
+    SUBCMDS := build
 endif
-endif 
 
-BINUTILS_VERSION := 2.18
-GCC_VERSION := 4.3.2
-GLIBC_VERSION := 2.11.1
+.PHONY: $(VALID_TARGETS)
 
-BUILDDIR ?= $(shell pwd)/
-ROSDIR ?= $(BUILDDIR)/../../../
-DESTDIR ?= /
-
-# Configuration parameters for make-ramp
-RAMP_ARCH := sparc
-RAMP_BINARY_PREFIX := $(RAMP_ARCH)-ros-
-RAMP_GCC_BUILD_FLAGS := --with-cpu=v8
-RAMP_CFLAGS :=
-
-# Configuration parameters for x86
-X86_ARCH := i686
-X86_BINARY_PREFIX := $(X86_ARCH)-ros-
-X86_GCC_BUILD_FLAGS := 
-X86_CFLAGS := -march=i486
-
-all:
-       @echo "You need to run one of the following commands, "
-       @echo "depending on which version of the cross compiler you are trying to generate:"
-       @echo "  make ramp"
-       @echo "  make x86"
-       @echo "  make ramp-revert"
-       @echo "  make x86-revert"
-       @echo "  make ramp-uninstall"
-       @echo "  make x86-uninstall"
-       @echo "  make clean"
-
-ramp:
-       export LD_LIBRARY_PATH=; \
-       export DESTDIR=$(DESTDIR);\
-       export INSTDIR=$(RAMP_INSTDIR);\
-       export PATH=$(DESTDIR)$(RAMP_INSTDIR)/bin:$(PATH);\
-       export ARCH=$(RAMP_ARCH);\
-       export ARCH_CFLAGS=$(RAMP_CFLAGS);\
-       export ROS_ARCH_DIR=$(RAMP_ARCH);\
-       export BINARY_PREFIX=$(RAMP_BINARY_PREFIX);\
-       export GCC_BUILD_FLAGS=$(RAMP_GCC_BUILD_FLAGS);\
-       $(MAKE) make-all
-
-x86:
-       $(MAKE) .glibc-patch
-       export LD_LIBRARY_PATH=; \
-       export DESTDIR=$(DESTDIR);\
-       export INSTDIR=$(X86_INSTDIR);\
-       export PATH=$(DESTDIR)$(X86_INSTDIR)/bin:$(PATH);\
-       export ARCH=$(X86_ARCH);\
-       export ARCH_CFLAGS=$(X86_CFLAGS);\
-       export ROS_ARCH_DIR=i386;\
-       export BINARY_PREFIX=$(X86_BINARY_PREFIX);\
-       export GCC_BUILD_FLAGS=$(X86_GCC_BUILD_FLAGS);\
-       $(MAKE) make-all
-
-make-all:
-       $(MAKE) .glibc-patch
-       $(MAKE) .$(BINARY_PREFIX)binutils-make
-       $(MAKE) .$(BINARY_PREFIX)binutils-install
-       $(MAKE) .$(BINARY_PREFIX)ros-headers-install
-       $(MAKE) .$(BINARY_PREFIX)glibc-headers-install
-       $(MAKE) .$(BINARY_PREFIX)gcc-stage1-make
-       $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
-       $(MAKE) .$(BINARY_PREFIX)glibc-make
-       $(MAKE) .$(BINARY_PREFIX)glibc-install
-       $(MAKE) .$(BINARY_PREFIX)gcc-stage2-make
-       $(MAKE) .$(BINARY_PREFIX)gcc-stage2-install
-       mkdir -p $(ROSDIR)/fs/$(ARCH)/lib
-       cp -r $(INSTDIR)/$(ARCH)-ros/lib/* $(ROSDIR)/fs/$(ARCH)/lib
-
-ramp-uninstall:
-       -rm -rf $(RAMP_INSTDIR)
-
-x86-uninstall:
-       -rm -rf $(X86_INSTDIR)
-
-ramp-revert: 
-       rm -rf $(RAMP_INSTDIR)
-       cp -r $(RAMP_BINARY_PREFIX)install.bak $(RAMP_INSTDIR)
-
-x86-revert: 
-       rm -rf $(X86_INSTDIR)
-       cp -r $(X86_BINARY_PREFIX)install.bak $(X86_INSTDIR)
+OK_TO_BUILD :=
+ifeq ($(words $(ARCH)),1)
+    ifeq ($(words $(CONFIG)),1)
+        ifeq ($(INVALID_TARGETS),)
+            OK_TO_BUILD := 1
+        endif
+    endif
+endif
+ifeq ($(OK_TO_BUILD),)
+all $(NONCLEANGOALS): make-real
+       @echo "" > /dev/null
+make-real:
+       $(print-usage)
+else
+all $(NONCLEANGOALS): make-real
+       @echo "" > /dev/null
+make-real:
+       @export AKAROS_COMPILER_REAL_BUILD=true; \
+        export ARCH=$(ARCH); \
+        export CONFIG=$(CONFIG); \
+        $(MAKE) --no-print-directory $(patsubst %, %-real, $(SUBCMDS))
+endif
 
 clean:
-       rm -rf binutils-$(BINUTILS_VERSION) 
-       rm -rf gcc-$(GCC_VERSION) 
-       rm -rf glibc-$(GLIBC_VERSION) 
-       rm -rf *-builddir
-       rm -rf .*-ros-*-configure
-       rm -rf *$(BINARY_PREFIX)install.bak
+       @rm -rf binutils-$(BINUTILS_VERSION)
+       @rm -rf gcc-$(GCC_VERSION)
+       @rm -rf glibc-$(GLIBC_VERSION)
+       @rm -rf gmp-$(GMP_VERSION)
+       @rm -rf mpfr-$(MPFR_VERSION)
+       @rm -rf mpc-$(MPC_VERSION)
+       @rm -rf *-builddir
+       @rm -rf .*-configure
+       @rm -rf .glibc-$(GLIBC_VERSION)-akaros.patch
+       @rm -rf .gcc-$(GCC_VERSION)-akaros.patch
+       @echo "    Removed configs, build dirs, and extracted sources"
+
+inst-clean: clean
+       @for a in $(VALID_ARCHS); do \
+               for c in $(VALID_CONFIGS); do \
+                       $(MAKE) --no-print-directory $$a $$c uninstall; \
+               done \
+       done
+
+else # AKAROS_COMPILER_REAL_BUILD
+
+# Set up some global variables to help us through the make based on the
+# platform we are building for.
+ifeq ($(ARCH),x86_64)
+    AKAROS_ARCH_DIR := x86
+    ARCH_CFLAGS :=
+    GLIBC_CONFIGURE_FLAGS := "--disable-multi-arch"
+    GCC_BUILD_FLAGS := CFLAGS="-fPIC"
+endif
+ifeq ($(ARCH),riscv)
+    AKAROS_ARCH_DIR := riscv
+    ARCH_CFLAGS :=
+    GLIBC_CONFIGURE_FLAGS :=
+    GCC_BUILD_FLAGS :=
+endif
+ifeq ($(CONFIG),cross)
+    INSTDIR_STRING := $(shell echo $(ARCH) | tr 'a-z' 'A-Z')_INSTDIR
+else
+    INSTDIR_STRING := $(shell echo $(ARCH) | tr 'a-z' 'A-Z')_NATIVE_INSTDIR
+    XCCROOT := $(shell dirname $(shell which $(ARCH)-ucb-akaros-gcc) 2>/dev/null)/..
+endif
+BUILDDIR ?= $(shell pwd)/
+AKAROSDIR ?= $(BUILDDIR)/../../../
+INSTDIR := $($(INSTDIR_STRING))
+BINARY_PREFIX := $(ARCH)-ucb-akaros-
+SYSROOT := $(INSTDIR)/$(ARCH)-ucb-akaros/sysroot
+PATH := /$(INSTDIR)/bin:$(PATH)
+
+BUILD_ERRORS :=
+BUILD_ERROR_DELIMITER := <\#\#>
+define add_error
+$(BUILD_ERRORS)$(1)$(BUILD_ERROR_DELIMITER)
+endef
+
+# Check for additional errors before building
+AWK := $(shell awk -W version 2>&1 | head -n 1 | awk '{print $$1}')
+ifneq ($(AWK),GNU)
+define BUILD_ERROR
+    You need to have 'gawk' installed on your system before proceeding!"
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
 
-binutils-clean:
-       cd $(BINARY_PREFIX)binutils-builddir; \
-       make clean
+GPPEXISTS := $(shell which g++ > /dev/null 2>&1 ; echo $$?)
+ifneq ($(GPPEXISTS),0)
+define BUILD_ERROR
+    You need to have 'g++' installed on your system before proceeding!"
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
 
-gcc-clean:
-       cd $(BINARY_PREFIX)gcc-stage1-builddir; \
-       cd $(BINARY_PREFIX)gcc-stage2-builddir; \
-       make clean
+FLEXEXISTS := $(shell which flex > /dev/null 2>&1 ; echo $$?)
+ifneq ($(FLEXEXISTS),0)
+define BUILD_ERROR
+    You need to have 'flex' installed on your system before proceeding!"
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
 
-glibc-clean:
-       cd $(BINARY_PREFIX)glibc-headers-builddir; \
-       cd $(BINARY_PREFIX)glibc-builddir; \
-       make clean
+BISONEXISTS := $(shell which bison > /dev/null 2>&1 ; echo $$?)
+ifneq ($(BISONEXISTS),0)
+define BUILD_ERROR
+    You need to have 'bison' installed on your system before proceeding!"
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
 
-binutils-$(BINUTILS_VERSION):
-       rm -rf binutils-$(BINUTILS_VERSION);
-       tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
-       patch -p0 < binutils-$(BINUTILS_VERSION)-ros.patch
+ifeq ($(INSTDIR),)
+define BUILD_ERROR
+    You need to setup $(INSTDIR_STRING), to point to where you
+    want your compiler installed. The best way to do this is to create
+    a 'Makelocal' file in the current directory and put a definition
+    for this variable in there.
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
 
-gcc-$(GCC_VERSION):
-       rm -rf gcc-$(GCC_VERSION)
-       tar -zxf gcc-$(GCC_VERSION).tar.gz
-       patch -p0 < gcc-$(GCC_VERSION)-ros.patch
-       cd gcc-$(GCC_VERSION)/libstdc++-v3; \
-       autoconf
-       
-       cd gcc-$(GCC_VERSION); \
-       tar -zxf ../mpfr-2.3.2.tar.gz; \
-       mv mpfr* mpfr
-       
-       cd gcc-$(GCC_VERSION); \
-       tar -zxf ../gmp-4.2.4.tar.gz; \
-       mv gmp* gmp
-
-glibc-$(GLIBC_VERSION): 
-       rm -rf glibc-$(GLIBC_VERSION)
-       tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
-       rm glibc-$(GLIBC_VERSION)/sysdeps/sparc/sparc32/elf/start.S
-       rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
-       rm glibc-$(GLIBC_VERSION)/sysdeps/i386/____longjmp_chk.S
-       rm glibc-$(GLIBC_VERSION)/sysdeps/i386/init-first.c
-       rm glibc-$(GLIBC_VERSION)/sysdeps/i386/sysdep.h
-       $(MAKE) .glibc-patch
-
-.glibc-patch: glibc-$(GLIBC_VERSION)
-       cd glibc-$(GLIBC_VERSION); \
-       diff -ruB --unidirectional-new-file \
-            ../glibc-$(GLIBC_VERSION) \
-            ../glibc-$(GLIBC_VERSION)-ros \
-            | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
-            | patch -p2 
+ifeq ($(CONFIG),native)
+ifeq ($(shell which $(ARCH)-ucb-akaros-gcc 2>/dev/null),)
+define BUILD_ERROR
+    No $(ARCH) Akaros cross-compiler installed in path. Make sure you have
+    built and installed the $(ARCH) cross-compiler using 'make $(ARCH)'
+    before trying to build the crossed-native compiler.
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
+endif
+ifeq ($(ARCH),riscv)
+ifeq ($(shell grep "CONFIG_RISCV=y" $(AKAROSDIR)/.config),)
+define BUILD_ERROR
+    Akaros tree not configured for $(ARCH)
+    Make sure you have configured AKAROSDIR for this architecture before proceeding
+    e.g. cd $$AKAROSDIR
+         make ARCH=riscv defconfig
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
+endif
 
-$(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
-       rm -rf $@
-       cp -R binutils-$(BINUTILS_VERSION) $@
+ifeq ($(ARCH),x86_64)
+ifeq ($(shell grep "CONFIG_X86_64=y" $(AKAROSDIR)/.config),)
+define BUILD_ERROR
+    Akaros tree not configured for x86_64
+    Make sure you have configured AKAROSDIR for this architecture before proceeding
+    e.g. cd $$AKAROSDIR
+         make ARCH=x86 defconfig
+         make ARCH=x86 menuconfig -> Set 64 bit option
+endef
+BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
+endif
+endif
 
-$(BINARY_PREFIX)glibc-headers-builddir: glibc-$(GLIBC_VERSION)
-       rm -rf $@
-       mkdir -p $@
+ROBUST_SUBCMDS := uninstall
+ifeq ($(filter-out $(patsubst %, %-real, $(ROBUST_SUBCMDS)), $(MAKECMDGOALS)),)
+    BUILD_ERRORS :=
+endif
 
-$(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
-       rm -rf $@
-       mkdir -p $@
-       
-$(BINARY_PREFIX)glibc-builddir: glibc-$(GLIBC_VERSION)
-       rm -rf $@
-       mkdir -p $@
+ifdef BUILD_ERRORS
+
+export BUILD_ERRORS
+$(MAKECMDGOALS): make-real
+       @echo "" > /dev/null
+make-real:
+       @echo "$${BUILD_ERRORS}" |\
+       awk '\
+               BEGIN { RS="$(BUILD_ERROR_DELIMITER)"; FS="$(BUILD_ERROR_DELIMITER)"; }\
+               { str[NR] = $$i; }\
+               END { for (i = 1; i < NR; i++) {\
+                               print "Error Detected:";\
+                               print substr(str[i], 2); }}\
+       '
+       @exit 2
+
+else # BUILD_ERROR
+
+# Make sure that LD_LIBRARY_PATH is not set during the build process
+unexport LD_LIBRARY_PATH
+
+check-env-real:
+       @echo "    Your environment checks out. Build away!"
+
+define make_and_log
+       $(MAKE) $(1) > build_logs/$(2).log 2>&1
+       @echo "make $(2) succeeded"
+endef
+
+ifeq ($(CONFIG),cross)
+build-real:
+       $(shell mkdir -p build_logs)
+       $(call make_and_log,.$(BINARY_PREFIX)binutils-install,$(BINARY_PREFIX)binutils-install)
+       $(call make_and_log,.$(BINARY_PREFIX)gcc-stage1-install,$(BINARY_PREFIX)gcc-stage1-install)
+       $(call make_and_log,.$(BINARY_PREFIX)headers-clean,$(BINARY_PREFIX)headers-clean)
+       $(call make_and_log,.$(BINARY_PREFIX)akaros-headers-install,$(BINARY_PREFIX)akaros-headers-install)
+       $(call make_and_log,.$(BINARY_PREFIX)dummy-libs-install,$(BINARY_PREFIX)dummy-libs-install)
+       $(call make_and_log,.$(BINARY_PREFIX)glibc-stage1-install,$(BINARY_PREFIX)glibc-stage1-install)
+       $(call make_and_log,.$(BINARY_PREFIX)gcc-stage2-install,$(BINARY_PREFIX)gcc-stage2-install)
+       $(call make_and_log,.$(BINARY_PREFIX)glibc-stage2-install,$(BINARY_PREFIX)glibc-stage2-install)
+       $(call make_and_log,.$(BINARY_PREFIX)akaros-libs-install,$(BINARY_PREFIX)akaros-libs-install)
+       $(call make_and_log,.$(BINARY_PREFIX)gcc-stage3-install,$(BINARY_PREFIX)gcc-stage3-install)
+       $(call make_and_log,.$(BINARY_PREFIX)gmp-install,$(BINARY_PREFIX)gmp-install)
+       $(call make_and_log,.$(BINARY_PREFIX)mpfr-install,$(BINARY_PREFIX)mpfr-install)
+       $(call make_and_log,.$(BINARY_PREFIX)mpc-install,$(BINARY_PREFIX)mpc-install)
+else
+build-real:
+       $(shell mkdir -p build_logs)
+       $(call make_and_log,.$(BINARY_PREFIX)binutils-install,$(BINARY_PREFIX)binutils-install)
+       $(call make_and_log,.$(BINARY_PREFIX)gcc-stage3-install,$(BINARY_PREFIX)gcc-stage3-install)
+endif
 
-$(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
+uninstall-real:
+       @dir=$(INSTDIR);\
+       if [ "$${dir}" != "" ]; then\
+               rm -rf $${dir};\
+               echo "    Removed $${dir} ($(ARCH)-$(CONFIG)-inst)";\
+       fi
+
+install-headers-real: .$(BINARY_PREFIX)akaros-headers-install
+
+%.tar.bz2:
+       wget http://akaros.cs.berkeley.edu/xcc/$@
+
+%.tar.gz:
+       wget http://akaros.cs.berkeley.edu/xcc/$@
+
+#################################
+########### BINUTILS ############
+#################################
+binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
+       rm -rf binutils-$(BINUTILS_VERSION);
+       tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
+       patch -p0 < binutils-$(BINUTILS_VERSION)-akaros.patch
+
+$(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
        rm -rf $@
        mkdir -p $@
-       
-.$(BINARY_PREFIX)binutils-configure: 
-       $(MAKE) $(BINARY_PREFIX)binutils-builddir 
+
+native-binutils-configure:
+       cd $(BINARY_PREFIX)binutils-builddir; \
+       CFLAGS="-O2 -g -pipe" \
+       CXXFLAGS="-O2 -g -pipe" \
+       LDFLAGS="" \
+       ../binutils-$(BINUTILS_VERSION)/configure \
+               --target=$(ARCH)-ucb-akaros \
+               --host=$(ARCH)-ucb-akaros \
+               --prefix=$(INSTDIR) \
+               --disable-werror \
+               --enable-ld=yes \
+               --enable-gold=yes \
+               --enable-plugins=yes \
+               --with-pkgversion="akaros-repo" \
+               --disable-multilib \
+               --disable-nls
+
+cross-binutils-configure:
        cd $(BINARY_PREFIX)binutils-builddir; \
-       ./configure --enable-shared \
-                   --disable-multilib \
-                   --disable-nls \
-                   --target=$(ARCH)-ros \
-                   --prefix=$(INSTDIR) \
-                   --includedir=$(INSTDIR)/include \
-                   --disable-werror;
+       CFLAGS="-O2 -g -pipe" \
+       CXXFLAGS="-O2 -g -pipe" \
+       LDFLAGS="" \
+       ../binutils-$(BINUTILS_VERSION)/configure \
+               --target=$(ARCH)-ucb-akaros \
+               --prefix=$(INSTDIR) \
+               --disable-werror \
+               --enable-ld=yes \
+               --enable-gold=yes \
+               --enable-plugins=yes \
+               --with-pkgversion="akaros-repo" \
+               --disable-multilib \
+               --disable-nls \
+               --with-sysroot=$(SYSROOT)
+
+.$(BINARY_PREFIX)binutils-configure:
+       $(MAKE) $(BINARY_PREFIX)binutils-builddir
+       if [ "$(CONFIG)" = "native" ]; then \
+               $(MAKE) native-binutils-configure; \
+       else \
+               $(MAKE) cross-binutils-configure; \
+       fi
+       echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
        touch $@
 
 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
        cd $(BINARY_PREFIX)binutils-builddir; \
-       make -j
+       make -j $(MAKE_JOBS)
 
-.$(BINARY_PREFIX)binutils-install:
+.$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
        cd $(BINARY_PREFIX)binutils-builddir; \
-       make -j install
+       make -j $(MAKE_JOBS) install
 
-.$(BINARY_PREFIX)glibc-headers-configure:
-       $(MAKE) $(BINARY_PREFIX)glibc-headers-builddir
-       cd $(BINARY_PREFIX)glibc-headers-builddir; \
-       ../glibc-$(GLIBC_VERSION)/configure \
-                 --host=$(ARCH)-ros \
-                 --enable-hacker-mode \
-                 --enable-shared \
-                 --disable-nls \
-                 --with-elf \
-                 --with-tls \
-                 --with-__thread \
-                 --prefix=$(INSTDIR)/$(ARCH)-ros \
-                 --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
-                 libc_cv_forced_unwind=yes \
-                 libc_cv_c_cleanup=yes;
-       touch $@
+binutils-clean:
+       cd $(BINARY_PREFIX)binutils-builddir; \
+       make clean
 
-.$(BINARY_PREFIX)glibc-headers-install: .$(BINARY_PREFIX)glibc-headers-configure
-       cd $(BINARY_PREFIX)glibc-headers-builddir; \
-       make -j install-headers; \
-       mkdir -p $(INSTDIR)/$(ARCH)-ros/include/gnu; \
-       echo > $(INSTDIR)/$(ARCH)-ros/include/gnu/stubs.h; \
-       cp bits/stdio_lim.h $(INSTDIR)/$(ARCH)-ros/include/bits/
-
-.$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
-       mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include/arch
-       cp -r $(ROSDIR)/kern/include/ros \
-          $(INSTDIR)/$(ARCH)-ros/sys-include/
-       cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/* \
-          $(INSTDIR)/$(ARCH)-ros/sys-include/arch/
-
-.$(BINARY_PREFIX)gcc-stage1-configure: 
+#################################
+########## GCC Stage 1 ##########
+#################################
+.gcc-akaros-directory-patch:
+       -cd gcc-$(GCC_VERSION); \
+       diff -ruB --unidirectional-new-file \
+            ../gcc-$(GCC_VERSION) \
+            ../gcc-$(GCC_VERSION)-akaros \
+            | grep -v "Only in ../gcc-$(GCC_VERSION)" \
+            > ../.gcc-$(GCC_VERSION)-akaros-directory.patch; \
+            patch -p2 < ../.gcc-$(GCC_VERSION)-akaros-directory.patch
+
+gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2 \
+                   gmp-$(GMP_VERSION) \
+                   mpfr-$(MPFR_VERSION) \
+                   mpc-$(MPC_VERSION)
+       rm -rf gcc-$(GCC_VERSION)
+       tar -jxf gcc-$(GCC_VERSION).tar.bz2
+       $(MAKE) .gcc-akaros-directory-patch
+       patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-r233572.patch
+       patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
+       patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-existing.patch
+       (cd gcc-$(GCC_VERSION) && \
+        ln -s ../gmp-$(GMP_VERSION) gmp && \
+        ln -s ../mpfr-$(MPFR_VERSION) mpfr && \
+        ln -s ../mpc-$(MPC_VERSION) mpc)
+
+$(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
+       rm -rf $@
+       mkdir -p $@
+
+.$(BINARY_PREFIX)gcc-stage1-configure:
        $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
        cd $(BINARY_PREFIX)gcc-stage1-builddir; \
+       CFLAGS="-O2 -g -pipe" \
+       CXXFLAGS="-O2 -g -pipe" \
+       LDFLAGS="-lstdc++ -lm" \
        ../gcc-$(GCC_VERSION)/configure \
-               --enable-languages=c \
-               --enable-shared \
-               --disable-checking \
-               --disable-werror \
-               --disable-multilib \
-               --disable-libmudflap \
-               --disable-libssp \
-               --disable-libgomp \
-               --disable-nls \
-               --program-prefix=$(BINARY_PREFIX) \
-               --target=$(ARCH)-ros \
-               --prefix=$(INSTDIR) \
-               --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
-               $(GCC_BUILD_FLAGS);
+               --target=$(ARCH)-ucb-akaros \
+               --prefix=$(INSTDIR) \
+               --with-local-prefix=$(SYSROOT) \
+               --disable-mudflap \
+               --with-sysroot=$(SYSROOT) \
+               --with-newlib \
+               --enable-threads=no \
+               --enable-tls \
+               --disable-shared \
+               --with-pkgversion="akaros-repo" \
+               --disable-__cxa_atexit \
+               --with-ppl=no \
+               --with-isl=no \
+               --with-cloog=no \
+               --with-libelf=no \
+               --disable-lto \
+               --disable-libgomp \
+               --disable-mudflap \
+               --disable-nls \
+               --disable-multilib \
+               --enable-languages=c \
+               --enable-linker-build-id \
+               $(GCC_BUILD_FLAGS);
+       echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
        touch $@
 
 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
-       # Put the - in front of make because it actually fails and
-       # we don't want the whole make process to fail.
-       # It appears to still work though since this is just stage 1 of compiling
-       # Should really look into fixing this though...
-       -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
-       make -j inhibit_libc=true cross-compiling=yes
-
-.$(BINARY_PREFIX)gcc-stage1-install: 
        cd $(BINARY_PREFIX)gcc-stage1-builddir; \
-       make -j install
-       #-ln -vs libgcc.a `$(BINARY_PREFIX)gcc -print-libgcc-file-name | \
-       #                 sed 's/libgcc/&_eh/'`
-
-.$(BINARY_PREFIX)glibc-configure: 
-       $(MAKE) $(BINARY_PREFIX)glibc-builddir
-       cd $(BINARY_PREFIX)glibc-builddir; \
-       ../glibc-$(GLIBC_VERSION)/configure \
-                 --host=$(ARCH)-ros \
-                 --enable-hacker-mode \
-                 --enable-shared \
-                 --with-elf \
-                 --with-tls \
-                 --disable-nls \
-                 --with-__thread \
-                 --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
-                 --prefix=$(INSTDIR)/$(ARCH)-ros \
-                 libc_cv_forced_unwind=yes \
-                 libc_cv_c_cleanup=yes \
-                 CFLAGS="$(ARCH_CFLAGS) -O2 -pipe";
-       touch $@
+       make -j $(MAKE_JOBS) all-gcc;
 
-.$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
-       cd $(BINARY_PREFIX)glibc-builddir; \
-       make -j
+.$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
+       cd $(BINARY_PREFIX)gcc-stage1-builddir; \
+       make -j $(MAKE_JOBS) install-gcc;
 
-.$(BINARY_PREFIX)glibc-install: 
-       cd $(BINARY_PREFIX)glibc-builddir; \
-       make -j install
+#################################
+########## GCC Stage 2 ##########
+#################################
+$(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
+       rm -rf $@
+       mkdir -p $@
 
 .$(BINARY_PREFIX)gcc-stage2-configure:
        $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
        cd $(BINARY_PREFIX)gcc-stage2-builddir; \
+       CFLAGS="-O2 -g -pipe" \
+       CXXFLAGS="-O2 -g -pipe" \
+       LDFLAGS="-lstdc++ -lm" \
        ../gcc-$(GCC_VERSION)/configure \
-                 --enable-shared \
-                 --disable-multilib \
-                 --disable-nls \
-                 --program-prefix=$(BINARY_PREFIX) \
-                 --target=$(ARCH)-ros \
-                 --prefix=$(INSTDIR) \
-                 --enable-languages=c,c++ \
-                 $(GCC_BUILD_FLAGS) \
-                 --with-tls \
-                 --with-__thread \
-                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
-                 --disable-werror;
+               --target=$(ARCH)-ucb-akaros \
+               --prefix=$(INSTDIR) \
+               --with-local-prefix=$(SYSROOT) \
+               --disable-mudflap \
+               --with-sysroot=$(SYSROOT) \
+               --with-newlib \
+               --enable-threads=no \
+               --enable-tls \
+               --disable-shared \
+               --with-pkgversion="akaros-repo" \
+               --disable-__cxa_atexit \
+               --with-ppl=no \
+               --with-sil=no \
+               --with-cloog=no \
+               --with-libelf=no \
+               --disable-lto \
+               --disable-libgomp \
+               --disable-libmudflap \
+               --disable-nls \
+               --enable-languages=c,c++,fortran \
+               --disable-multilib \
+               --enable-linker-build-id \
+               $(GCC_BUILD_FLAGS);
+       echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
        touch $@
 
 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
        cd $(BINARY_PREFIX)gcc-stage2-builddir; \
-       make -j
+       make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
+                            all-gcc \
+                            all-target-libgcc;
 
-.$(BINARY_PREFIX)gcc-stage2-install:
+.$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
        cd $(BINARY_PREFIX)gcc-stage2-builddir; \
-       make -j install
-
-patches:
-       mv gcc-$(GCC_VERSION)/gmp .
-       mv gcc-$(GCC_VERSION)/mpfr .
-       rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache
-       mv gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new
-       tar -zxf gcc-$(GCC_VERSION).tar.gz
-       -diff -ruN gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new \
-             > gcc-$(GCC_VERSION)-ros.patch
-       rm -rf gcc-$(GCC_VERSION)
-       mv gcc-$(GCC_VERSION).new gcc-$(GCC_VERSION)
-       mv gmp gcc-$(GCC_VERSION)
-       mv mpfr gcc-$(GCC_VERSION)
-       
-       mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
-       tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
-       -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
-             > binutils-$(BINUTILS_VERSION)-ros.patch
-       rm -rf binutils-$(BINUTILS_VERSION)
-       mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
+       make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
+
+#################################
+############ Headers ############
+#################################
+.$(BINARY_PREFIX)headers-clean:
+       rm -rf $(SYSROOT)/usr/include/*
+
+.$(BINARY_PREFIX)akaros-headers-install: $(AKAROSDIR)
+       mkdir -p $(SYSROOT)/usr/include
+       rm -rf $(SYSROOT)/usr/include/ros
+       cp -r $(AKAROSDIR)/kern/include/ros \
+           $(SYSROOT)/usr/include/
+       rm -rf $(SYSROOT)/usr/include/ros/arch
+       mkdir -p $(SYSROOT)/usr/include/ros/arch
+       cp -r $(AKAROSDIR)/kern/arch/$(AKAROS_ARCH_DIR)/ros/* \
+           $(SYSROOT)/usr/include/ros/arch/
+       cp -r $(AKAROSDIR)/user/parlib/include/* \
+           $(SYSROOT)/usr/include/
+       cp -r $(AKAROSDIR)/user/pthread/*.h \
+           $(SYSROOT)/usr/include/
+
+#################################
+###### Dummy Libs Install #######
+#################################
+.$(BINARY_PREFIX)dummy-libs-install:
+       rm -rf $(SYSROOT)/usr/lib/libparlib.a
+       mkdir -p $(SYSROOT)/usr/lib
+       $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
+
+#################################
+######### Glibc Stage 1 #########
+#################################
+.glibc-akaros-directory-patch:
+       -cd glibc-$(GLIBC_VERSION); \
+       diff -ruB --unidirectional-new-file \
+            ../glibc-$(GLIBC_VERSION) \
+            ../glibc-$(GLIBC_VERSION)-akaros \
+            | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
+            > ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch; \
+            patch -p2 < ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch
+
+# On occasion, include/pthread.h was getting installed in stage 2, clobbering
+# parlib's pthread.h.
+glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
+       rm -rf glibc-$(GLIBC_VERSION)
+       tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
+       rm glibc-$(GLIBC_VERSION)/include/pthread.h
+       $(MAKE) .glibc-akaros-directory-patch
+       patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
+       patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-existing.patch
+
+$(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
+       rm -rf $@
+       mkdir -p $@
+
+.$(BINARY_PREFIX)glibc-stage1-configure:
+       $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
+       cd $(BINARY_PREFIX)glibc-stage1-builddir; \
+       CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
+       CXXFLAGS="-fpermissive" \
+       CC=$(ARCH)-ucb-akaros-gcc \
+       AR=$(ARCH)-ucb-akaros-ar \
+       RANLIB=$(ARCH)-ucb-akaros-ranlib \
+       ../glibc-$(GLIBC_VERSION)/configure \
+               --prefix=/usr \
+               --host=$(ARCH)-ucb-akaros \
+               --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
+               --without-cvs \
+               --disable-profile \
+               --without-gd \
+               --with-headers=$(SYSROOT)/usr/include \
+               --disable-debug \
+               --disable-sanity-checks \
+               --enable-kernel= \
+               --with-__thread \
+               --with-tls \
+               --without-nptl \
+               --enable-shared \
+               --enable-add-ons=no \
+               --with-pkgversion="akaros-repo" \
+               --with-elf \
+               --enable-hacker-mode \
+               --enable-static-nss \
+               --enable-obsolete-rpc \
+               --disable-build-nscd \
+               --disable-nscd \
+               $(GLIBC_CONFIGURE_FLAGS);
+       touch $@
+
+.$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
+       cd $(BINARY_PREFIX)glibc-stage1-builddir; \
+       make -j $(MAKE_JOBS) \
+               install_root=$(SYSROOT) \
+               install-bootstrap-headers=yes \
+               install-headers; \
+       touch $(SYSROOT)/usr/include/gnu/stubs.h; \
+       cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
+       cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
+       make -j $(MAKE_JOBS) csu/subdir_lib;
+
+####################################
+########## Glibc Stage 2  ##########
+####################################
+$(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
+       rm -rf $@
+       mkdir -p $@
+
+.$(BINARY_PREFIX)glibc-stage2-configure:
+       $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
+       cd $(BINARY_PREFIX)glibc-stage2-builddir; \
+       CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
+       CXXFLAGS="-fpermissive" \
+       CC=x86_64-ucb-akaros-gcc \
+       AR=x86_64-ucb-akaros-ar \
+       RANLIB=x86_64-ucb-akaros-ranlib \
+       ../glibc-$(GLIBC_VERSION)/configure \
+               --prefix=/usr \
+               --host=$(ARCH)-ucb-akaros \
+               --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
+               --without-cvs \
+               --disable-profile \
+               --without-gd \
+               --with-headers=$(SYSROOT)/usr/include \
+               --disable-debug \
+               --disable-sanity-checks \
+               --enable-kernel= \
+               --with-__thread \
+               --with-tls \
+               --without-nptl \
+               --enable-shared \
+               --enable-add-ons=no \
+               --with-pkgversion="akaros-repo" \
+               --with-elf \
+               --enable-hacker-mode \
+               --enable-static-nss \
+               --enable-obsolete-rpc \
+               --disable-build-nscd \
+               --disable-nscd \
+               $(GLIBC_CONFIGURE_FLAGS);
+       touch $@
+
+.$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
+       cd $(BINARY_PREFIX)glibc-stage2-builddir; \
+       make -j $(MAKE_JOBS)
+
+.$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
+       cd $(BINARY_PREFIX)glibc-stage2-builddir; \
+       make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
+
+###################################
+####### AKAROS Libs Install #######
+###################################
+.$(BINARY_PREFIX)akaros-libs-install:
+       cd $(AKAROSDIR); \
+       make ARCH=$(AKAROS_ARCH_DIR) userclean; \
+       make ARCH=$(AKAROS_ARCH_DIR) -j $(MAKE_JOBS) install-base-libs
+
+##################################
+########### Gcc Stage 3 ##########
+##################################
+$(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
+       rm -rf $@
+       mkdir -p $@
+
+native-gcc-stage3-prep:
+       mkdir -p $(INSTDIR)/usr; \
+
+native-gcc-stage3-configure: native-gcc-stage3-prep
+       cd $(BINARY_PREFIX)gcc-stage3-builddir; \
+       ../gcc-$(GCC_VERSION)/configure \
+               --target=$(ARCH)-ucb-akaros \
+               --host=$(ARCH)-ucb-akaros \
+               --prefix=$(INSTDIR) \
+               --with-gmp=$(XCCROOT) \
+               --with-mpfr=$(XCCROOT) \
+               --with-mpc=$(XCCROOT) \
+               --enable-languages=c,c++,fortran \
+               --with-pkgversion="akaros-repo" \
+               --disable-__cxa_atexit \
+               --disable-mudflap \
+               --enable-libgomp \
+               --disable-libssp \
+               --disable-libquadmath \
+               --disable-libquadmath-support \
+               --with-ppl=no \
+               --with-isl=no \
+               --with-cloog=no \
+               --with-libelf=no \
+               --enable-threads=akaros \
+               --enable-tls \
+               --disable-nls \
+               --disable-multilib \
+               --enable-c99 \
+               --enable-long-long \
+               --enable-shared \
+               --disable-canonical-prefixes \
+               --disable-canonical-system-headers \
+               --enable-linker-build-id \
+               $(GCC_BUILD_FLAGS);
+
+cross-gcc-stage3-configure:
+       cd $(BINARY_PREFIX)gcc-stage3-builddir; \
+       CFLAGS="-O2 -g -pipe" \
+       CXXFLAGS="-O2 -g -pipe" \
+       LDFLAGS="-lstdc++ -lm" \
+       ../gcc-$(GCC_VERSION)/configure \
+               --target=$(ARCH)-ucb-akaros \
+               --prefix=$(INSTDIR) \
+               --with-sysroot=$(SYSROOT) \
+               --enable-languages=c,c++,fortran \
+               --with-pkgversion="akaros-repo" \
+               --disable-__cxa_atexit \
+               --disable-mudflap \
+               --enable-libgomp \
+               --disable-libssp \
+               --disable-libquadmath \
+               --disable-libquadmath-support \
+               --with-ppl=no \
+               --with-isl=no \
+               --with-cloog=no \
+               --with-libelf=no \
+               --enable-threads=akaros \
+               --disable-nls \
+               --disable-multilib \
+               --with-local-prefix=$(SYSROOT) \
+               --enable-c99 \
+               --enable-long-long \
+               --enable-shared \
+               --disable-canonical-prefixes \
+               --disable-canonical-system-headers \
+               --enable-linker-build-id \
+               $(GCC_BUILD_FLAGS);
+
+.$(BINARY_PREFIX)gcc-stage3-configure:
+       $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
+       if [ "$(CONFIG)" = "native" ]; then \
+               $(MAKE) native-gcc-stage3-configure; \
+       else \
+               $(MAKE) cross-gcc-stage3-configure; \
+       fi
+       echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
+       touch $@
+
+.$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
+       cd $(BINARY_PREFIX)gcc-stage3-builddir; \
+       make -j $(MAKE_JOBS)
+
+.$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
+       cd $(BINARY_PREFIX)gcc-stage3-builddir; \
+       make -j $(MAKE_JOBS) install
+
+##################################
+######### GMP, MPFR, MPC #########
+##################################
+gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
+       rm -rf gmp-$(GMP_VERSION)
+       tar -jxf gmp-$(GMP_VERSION).tar.bz2
+       patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
+
+mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
+       rm -rf mpfr-$(MPFR_VERSION)
+       tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
+       patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
+
+mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
+       rm -rf mpc-$(MPC_VERSION)
+       tar -zxf mpc-$(MPC_VERSION).tar.gz
+       patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
+
+$(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
+       rm -rf $@
+       mkdir -p $@
+
+$(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
+       rm -rf $@
+       mkdir -p $@
+
+$(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
+       rm -rf $@
+       mkdir -p $@
+
+.$(BINARY_PREFIX)gmp-configure:
+       $(MAKE) $(BINARY_PREFIX)gmp-builddir
+       cd $(BINARY_PREFIX)gmp-builddir; \
+       ../gmp-$(GMP_VERSION)/configure \
+           --disable-static \
+           --prefix=$(INSTDIR) \
+           --host=$(ARCH)-ucb-akaros
+       touch $@
+
+.$(BINARY_PREFIX)mpfr-configure:
+       $(MAKE) $(BINARY_PREFIX)mpfr-builddir
+       cd $(BINARY_PREFIX)mpfr-builddir; \
+       ../mpfr-$(MPFR_VERSION)/configure \
+           --disable-static \
+           --prefix=$(INSTDIR) \
+           --with-gmp=$(INSTDIR) \
+           --host=$(ARCH)-ucb-akaros
+       touch $@
+
+.$(BINARY_PREFIX)mpc-configure:
+       $(MAKE) $(BINARY_PREFIX)mpc-builddir
+       cd $(BINARY_PREFIX)mpc-builddir; \
+       ../mpc-$(MPC_VERSION)/configure \
+           --disable-static \
+           --prefix=$(INSTDIR) \
+           --with-gmp=$(INSTDIR) \
+           --with-mpfr=$(INSTDIR) \
+           --host=$(ARCH)-ucb-akaros
+       touch $@
+
+.$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
+       cd $(BINARY_PREFIX)gmp-builddir; \
+       make -j $(MAKE_JOBS)
+
+.$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
+       cd $(BINARY_PREFIX)mpfr-builddir; \
+       make -j $(MAKE_JOBS)
+
+.$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
+       cd $(BINARY_PREFIX)mpc-builddir; \
+       make -j $(MAKE_JOBS)
+
+.$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
+       cd $(BINARY_PREFIX)gmp-builddir; \
+       make -j $(MAKE_JOBS) install
+
+.$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
+       cd $(BINARY_PREFIX)mpfr-builddir; \
+       make -j $(MAKE_JOBS) install
+
+.$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
+       cd $(BINARY_PREFIX)mpc-builddir; \
+       make -j $(MAKE_JOBS) install
 
+endif # BUILD_ERROR
+endif # AKAROS_COMPILER_REAL_BUILD