upgraded to binutils 2.21.1
[akaros.git] / tools / compilers / gcc-glibc / Makefile
index 6d6bae5..2f62491 100644 (file)
@@ -1,55 +1,66 @@
+# Number of make jobs to spawn.  Define it in Makelocal
+MAKE_JOBS := 
+
 # Defines where to install the toolchain
 -include Makelocal
 
-ifndef ROSDIR
-busted0: 
-       @echo "You need to set ROSDIR to the path of the ROS source code. The best way to do this is to create a 'Makelocal' file in the current directory and put it in there."
-endif
-
-ifndef RAMP_INSTDIR
+ifndef RISCV_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."
+       @echo "You need to setup either a RISCV_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."; false
+riscv: busted
+x86: busted
 endif
 endif 
 
-BINUTILS_VERSION := 2.18
+# Check to make sure that we have gawk installed on our system and not some
+# other version of awk
+AWK := $(shell awk -W version 2>&1 | head -n 1 | awk '{print $$1}')
+ifneq ($(AWK),GNU)
+$(error You need to have 'gawk' installed on your system!)
+endif
+
+BINUTILS_VERSION := 2.21.1
 GCC_VERSION := 4.3.2
 GLIBC_VERSION := 2.11.1
 
 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
+# Configuration parameters for make-riscv
+RISCV_ARCH := riscv
+RISCV_BINARY_PREFIX := $(RISCV_ARCH)-ros-
+RISCV_GCC_BUILD_FLAGS := --with-cpu=v8
+RISCV_CFLAGS :=
 
 # Configuration parameters for x86
-X86_ARCH := i386
+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 riscv"
        @echo "  make x86"
-       @echo "  make ramp-revert"
+       @echo "  make riscv-revert"
        @echo "  make x86-revert"
-       @echo "  make ramp-uninstall"
+       @echo "  make riscv-uninstall"
        @echo "  make x86-uninstall"
        @echo "  make clean"
 
-ramp:
+riscv:
        export LD_LIBRARY_PATH=; \
        export DESTDIR=$(DESTDIR);\
-       export INSTDIR=$(RAMP_INSTDIR);\
-       export PATH=$(DESTDIR)$(RAMP_INSTDIR)/bin:$(PATH);\
-       export ARCH=$(RAMP_ARCH);\
-       export ROS_ARCH_DIR=$(RAMP_ARCH);\
-       export BINARY_PREFIX=$(RAMP_BINARY_PREFIX);\
-       export GCC_BUILD_FLAGS=$(RAMP_GCC_BUILD_FLAGS);\
+       export INSTDIR=$(RISCV_INSTDIR);\
+       export PATH=$(DESTDIR)$(RISCV_INSTDIR)/bin:$(PATH);\
+       export ARCH=$(RISCV_ARCH);\
+       export ARCH_CFLAGS=$(RISCV_CFLAGS);\
+       export ROS_ARCH_DIR=$(RISCV_ARCH);\
+       export BINARY_PREFIX=$(RISCV_BINARY_PREFIX);\
+       export GCC_BUILD_FLAGS=$(RISCV_GCC_BUILD_FLAGS);\
        $(MAKE) make-all
 
 x86:
@@ -59,39 +70,36 @@ x86:
        export INSTDIR=$(X86_INSTDIR);\
        export PATH=$(DESTDIR)$(X86_INSTDIR)/bin:$(PATH);\
        export ARCH=$(X86_ARCH);\
+       export ARCH_CFLAGS=$(X86_CFLAGS);\
        export ROS_ARCH_DIR=$(X86_ARCH);\
        export BINARY_PREFIX=$(X86_BINARY_PREFIX);\
        export GCC_BUILD_FLAGS=$(X86_GCC_BUILD_FLAGS);\
        $(MAKE) make-all
 
-make-all:
+make-all: 
        $(MAKE) .glibc-patch
        $(MAKE) .$(BINARY_PREFIX)binutils-make
        $(MAKE) .$(BINARY_PREFIX)binutils-install
-       $(MAKE) .$(BINARY_PREFIX)glibc-headers-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
-       ln -f $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtbegin.o \
-             $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtbeginT.o
-       ln -f $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtend.o \
-             $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtendT.o
        mkdir -p $(ROSDIR)/fs/$(ARCH)/lib
        cp -r $(INSTDIR)/$(ARCH)-ros/lib/* $(ROSDIR)/fs/$(ARCH)/lib
 
-ramp-uninstall:
-       -rm -rf $(RAMP_INSTDIR)
+riscv-uninstall:
+       -rm -rf $(RISCV_INSTDIR)
 
 x86-uninstall:
        -rm -rf $(X86_INSTDIR)
 
-ramp-revert: 
-       rm -rf $(RAMP_INSTDIR)
-       cp -r $(RAMP_BINARY_PREFIX)install.bak $(RAMP_INSTDIR)
+riscv-revert:
+       rm -rf $(RISCV_INSTDIR)
+       cp -r $(RISCV_BINARY_PREFIX)install.bak $(RISCV_INSTDIR)
 
 x86-revert: 
        rm -rf $(X86_INSTDIR)
@@ -119,17 +127,20 @@ glibc-clean:
        cd $(BINARY_PREFIX)glibc-builddir; \
        make clean
 
-binutils-$(BINUTILS_VERSION):
+%.tar.bz2:
+       wget http://akaros.cs.berkeley.edu/xcc/$@
+
+binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
        rm -rf binutils-$(BINUTILS_VERSION);
-       tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
+       tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
        patch -p0 < binutils-$(BINUTILS_VERSION)-ros.patch
+       patch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
 
 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); \
+       patch -p1 < ../gcc-$(GCC_VERSION)-ros.patch
        
        cd gcc-$(GCC_VERSION); \
        tar -zxf ../mpfr-2.3.2.tar.gz; \
@@ -144,10 +155,13 @@ 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); \
+       -cd glibc-$(GLIBC_VERSION); \
        diff -ruB --unidirectional-new-file \
             ../glibc-$(GLIBC_VERSION) \
             ../glibc-$(GLIBC_VERSION)-ros \
@@ -179,6 +193,7 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
        cd $(BINARY_PREFIX)binutils-builddir; \
        ./configure --enable-shared \
                    --disable-multilib \
+                   --disable-nls \
                    --target=$(ARCH)-ros \
                    --prefix=$(INSTDIR) \
                    --includedir=$(INSTDIR)/include \
@@ -187,42 +202,51 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
 
 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
        cd $(BINARY_PREFIX)binutils-builddir; \
-       make -j
+       make -j $(MAKE_JOBS)
 
 .$(BINARY_PREFIX)binutils-install:
        cd $(BINARY_PREFIX)binutils-builddir; \
-       make -j install
+       make -j $(MAKE_JOBS) install
 
-.$(BINARY_PREFIX)glibc-headers-configure: 
+.$(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=$(ROSDIR)/kern/include/ \
+                 --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
                  libc_cv_forced_unwind=yes \
                  libc_cv_c_cleanup=yes;
        touch $@
 
 .$(BINARY_PREFIX)glibc-headers-install: .$(BINARY_PREFIX)glibc-headers-configure
        cd $(BINARY_PREFIX)glibc-headers-builddir; \
-       make -j install-headers; \
+       make -j $(MAKE_JOBS) install-headers; \
        mkdir -p $(INSTDIR)/$(ARCH)-ros/include/gnu; \
-       touch $(INSTDIR)/$(ARCH)-ros/include/gnu/stubs.h; \
+       echo > $(INSTDIR)/$(ARCH)-ros/include/gnu/stubs.h; \
        cp bits/stdio_lim.h $(INSTDIR)/$(ARCH)-ros/include/bits/
 
 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
-       $(MAKE) -C $(ROSDIR) symlinks
+       rm -rf $(INSTDIR)/$(ARCH)-ros/sys-include/*
        mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include
        cp -r $(ROSDIR)/kern/include/ros \
           $(INSTDIR)/$(ARCH)-ros/sys-include/
-       cp -r $(ROSDIR)/kern/include/arch \
+       rm -f $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch
+       mkdir $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch
+       cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/ros/* \
+          $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch/
+       cp -r $(ROSDIR)/user/parlib/include/* \
           $(INSTDIR)/$(ARCH)-ros/sys-include/
+       cp -r $(ROSDIR)/user/pthread/*.h \
+          $(INSTDIR)/$(ARCH)-ros/sys-include/
+       rm -rf $(INSTDIR)/$(ARCH)-ros/sys-include/arch
+       ln -s $(ARCH) $(INSTDIR)/$(ARCH)-ros/sys-include/arch 
 
 .$(BINARY_PREFIX)gcc-stage1-configure: 
        $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
@@ -236,6 +260,7 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
                --disable-libmudflap \
                --disable-libssp \
                --disable-libgomp \
+               --disable-nls \
                --program-prefix=$(BINARY_PREFIX) \
                --target=$(ARCH)-ros \
                --prefix=$(INSTDIR) \
@@ -249,11 +274,13 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
        # 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
+       make -j $(MAKE_JOBS) inhibit_libc=true cross-compiling=yes
 
 .$(BINARY_PREFIX)gcc-stage1-install: 
        cd $(BINARY_PREFIX)gcc-stage1-builddir; \
-       make -j install
+       make -j $(MAKE_JOBS) 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
@@ -264,27 +291,30 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
                  --enable-shared \
                  --with-elf \
                  --with-tls \
+                 --disable-nls \
                  --with-__thread \
-                 --with-headers=$(ROSDIR)/kern/include/ \
+                 --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
                  --prefix=$(INSTDIR)/$(ARCH)-ros \
                  libc_cv_forced_unwind=yes \
-                 libc_cv_c_cleanup=yes;
+                 libc_cv_c_cleanup=yes \
+                 CFLAGS="$(ARCH_CFLAGS) -g -fpermissive -O2 -pipe";
        touch $@
 
 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
        cd $(BINARY_PREFIX)glibc-builddir; \
-       make -j
+       make -j $(MAKE_JOBS)
 
 .$(BINARY_PREFIX)glibc-install: 
        cd $(BINARY_PREFIX)glibc-builddir; \
-       make -j install
+       make -j $(MAKE_JOBS) install
 
-.$(BINARY_PREFIX)gcc-stage2-configure: 
+.$(BINARY_PREFIX)gcc-stage2-configure:
        $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
        cd $(BINARY_PREFIX)gcc-stage2-builddir; \
        ../gcc-$(GCC_VERSION)/configure \
                  --enable-shared \
                  --disable-multilib \
+                 --disable-nls \
                  --program-prefix=$(BINARY_PREFIX) \
                  --target=$(ARCH)-ros \
                  --prefix=$(INSTDIR) \
@@ -298,22 +328,13 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
 
 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
        cd $(BINARY_PREFIX)gcc-stage2-builddir; \
-       make -j
+       make -j $(MAKE_JOBS)
 
 .$(BINARY_PREFIX)gcc-stage2-install:
        cd $(BINARY_PREFIX)gcc-stage2-builddir; \
-       make -j install
+       make -j $(MAKE_JOBS) install
 
 patches:
-       -cd glibc-$(GLIBC_VERSION)/manual; make realclean
-       rm -rf glibc-$(GLIBC_VERSION)/autom4te.cache
-       mv glibc-$(GLIBC_VERSION) glibc-$(GLIBC_VERSION).new
-       tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
-       -diff -ruN glibc-$(GLIBC_VERSION) glibc-$(GLIBC_VERSION).new \
-             > glibc-$(GLIBC_VERSION)-ros.patch
-       rm -rf glibc-$(GLIBC_VERSION)
-       mv glibc-$(GLIBC_VERSION).new glibc-$(GLIBC_VERSION)
-       
        mv gcc-$(GCC_VERSION)/gmp .
        mv gcc-$(GCC_VERSION)/mpfr .
        rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache