Fixes XCC texinfo dependency
[akaros.git] / tools / compilers / gcc-glibc / Makefile
index 9286249..0850d5f 100644 (file)
@@ -1,26 +1,45 @@
+# Number of make jobs to spawn.  Define it in Makelocal
+MAKE_JOBS := 
+
 # Defines where to install the toolchain
 -include Makelocal
 
-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
-GCC_VERSION := 4.3.2
-GLIBC_VERSION := 2.11.1
+# 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
+
+# Check to make sure that we have the GMP, MPFR, and MPC libraries installed
+GMP_OK := $(shell echo "int main() {return 0;}" | gcc -x c - -lgmp -lmpfr -lmpc -o /dev/null > /dev/null && echo OK)
+ifneq ($(GMP_OK),OK)
+$(error You need to have the libraries GMP, MPFR, and MPC installed on your system!)
+endif
+
+
+BINUTILS_VERSION := 2.21.1
+GCC_VERSION := 4.6.1
+GLIBC_VERSION := 2.14.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
-RAMP_CFLAGS :=
+# Configuration parameters for make-riscv
+RISCV_ARCH := riscv
+RISCV_BINARY_PREFIX := $(RISCV_ARCH)-ros-
+RISCV_GCC_BUILD_FLAGS := 
+RISCV_CFLAGS :=
 
 # Configuration parameters for x86
 X86_ARCH := i686
@@ -31,28 +50,27 @@ 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 ARCH_CFLAGS=$(RAMP_CFLAGS);\
-       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:
-       $(MAKE) .glibc-patch
        export LD_LIBRARY_PATH=; \
        export DESTDIR=$(DESTDIR);\
        export INSTDIR=$(X86_INSTDIR);\
@@ -64,30 +82,30 @@ x86:
        export GCC_BUILD_FLAGS=$(X86_GCC_BUILD_FLAGS);\
        $(MAKE) make-all
 
-make-all:
-       $(MAKE) .glibc-patch
+make-all: 
        $(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)ros-install-dummy-libs
        $(MAKE) .$(BINARY_PREFIX)glibc-make
        $(MAKE) .$(BINARY_PREFIX)glibc-install
+       $(MAKE) .$(BINARY_PREFIX)ros-install-libs
        $(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)
+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)
@@ -111,40 +129,47 @@ gcc-clean:
        make clean
 
 glibc-clean:
-       cd $(BINARY_PREFIX)glibc-headers-builddir; \
        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 --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
 
-gcc-$(GCC_VERSION):
+gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
        rm -rf gcc-$(GCC_VERSION)
-       tar -zxf gcc-$(GCC_VERSION).tar.gz
-       patch -p0 < gcc-$(GCC_VERSION)-ros.patch
-       
-       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
+       tar -jxf gcc-$(GCC_VERSION).tar.bz2
+       $(MAKE) .gcc-ros-patch
+       patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
 
-glibc-$(GLIBC_VERSION): 
+.gcc-ros-patch:
+       -cd gcc-$(GCC_VERSION); \
+       diff -ruB --unidirectional-new-file \
+            ../gcc-$(GCC_VERSION) \
+            ../gcc-$(GCC_VERSION)-ros \
+            | grep -v "Only in ../gcc-$(GCC_VERSION)" \
+            | patch -p2 
+
+glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
        rm -rf glibc-$(GLIBC_VERSION)
        tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
+       $(MAKE) .glibc-ros-patch
+       patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
        rm glibc-$(GLIBC_VERSION)/sysdeps/sparc/sparc32/elf/start.S
+       rm glibc-$(GLIBC_VERSION)/sysdeps/riscv/elf/start.S
+       rm glibc-$(GLIBC_VERSION)/sysdeps/riscv/init-first.c
        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); \
+.glibc-ros-patch:
+       -cd glibc-$(GLIBC_VERSION); \
        diff -ruB --unidirectional-new-file \
             ../glibc-$(GLIBC_VERSION) \
             ../glibc-$(GLIBC_VERSION)-ros \
@@ -153,10 +178,6 @@ glibc-$(GLIBC_VERSION):
 
 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
        rm -rf $@
-       cp -R binutils-$(BINUTILS_VERSION) $@
-
-$(BINARY_PREFIX)glibc-headers-builddir: glibc-$(GLIBC_VERSION)
-       rm -rf $@
        mkdir -p $@
 
 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
@@ -174,53 +195,40 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
 .$(BINARY_PREFIX)binutils-configure: 
        $(MAKE) $(BINARY_PREFIX)binutils-builddir 
        cd $(BINARY_PREFIX)binutils-builddir; \
-       ./configure --enable-shared \
+       ../binutils-$(BINUTILS_VERSION)/configure \
+                   --enable-shared \
                    --disable-multilib \
                    --disable-nls \
                    --target=$(ARCH)-ros \
                    --prefix=$(INSTDIR) \
                    --includedir=$(INSTDIR)/include \
                    --disable-werror;
+       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:
        cd $(BINARY_PREFIX)binutils-builddir; \
-       make -j 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 $@
-
-.$(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/
+       make -j $(MAKE_JOBS) install
 
 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
-       mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include/arch
+       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/arch/$(ROS_ARCH_DIR)/* \
-          $(INSTDIR)/$(ARCH)-ros/sys-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
@@ -228,18 +236,21 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
        ../gcc-$(GCC_VERSION)/configure \
                --enable-languages=c \
                --enable-shared \
+               --enable-tls \
                --disable-checking \
                --disable-werror \
                --disable-multilib \
-               --disable-libmudflap \
-               --disable-libssp \
-               --disable-libgomp \
+               --disable-libmudflap \
+               --disable-libssp \
+               --disable-libquadmath \
+               --disable-libgomp \
                --disable-nls \
                --program-prefix=$(BINARY_PREFIX) \
                --target=$(ARCH)-ros \
                --prefix=$(INSTDIR) \
                --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
                $(GCC_BUILD_FLAGS);
+       echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
        touch $@
 
 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
@@ -248,14 +259,18 @@ $(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 inhibit_libc=true cross-compiling=yes
+       make -j $(MAKE_JOBS) inhibit_libc=true cross-compiling=yes
 
 .$(BINARY_PREFIX)gcc-stage1-install: 
-       cd $(BINARY_PREFIX)gcc-stage1-builddir; \
-       make -j install
+       -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
+       make -j $(MAKE_JOBS) install
        #-ln -vs libgcc.a `$(BINARY_PREFIX)gcc -print-libgcc-file-name | \
        #                 sed 's/libgcc/&_eh/'`
 
+.$(BINARY_PREFIX)ros-install-dummy-libs:
+       rm -rf $(INSTDIR)/$(ARCH)-ros/lib/libparlib.a
+       $(ARCH)-ros-ar cr $(INSTDIR)/$(ARCH)-ros/lib/libparlib.a
+
 .$(BINARY_PREFIX)glibc-configure: 
        $(MAKE) $(BINARY_PREFIX)glibc-builddir
        cd $(BINARY_PREFIX)glibc-builddir; \
@@ -265,66 +280,72 @@ $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
                  --enable-shared \
                  --with-elf \
                  --with-tls \
-                 --disable-nls \
+                 --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) -fpermissive -O2 -pipe";
+                 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)ros-install-libs:
+       cd $(ROSDIR); \
+       make userclean; \
+       make TARGET_ARCH=$(ARCH) -j $(MAKE_JOBS) install-libs
 
 .$(BINARY_PREFIX)gcc-stage2-configure:
        $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
        cd $(BINARY_PREFIX)gcc-stage2-builddir; \
        ../gcc-$(GCC_VERSION)/configure \
                  --enable-shared \
+                 --enable-tls \
+                 --enable-libgomp \
                  --disable-multilib \
-                 --disable-nls \
+                 --disable-nls \
                  --program-prefix=$(BINARY_PREFIX) \
                  --target=$(ARCH)-ros \
                  --prefix=$(INSTDIR) \
                  --enable-languages=c,c++ \
                  $(GCC_BUILD_FLAGS) \
-                 --with-tls \
+                 --without-libffi \
                  --with-__thread \
                  --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
                  --disable-werror;
+       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)
 
 .$(BINARY_PREFIX)gcc-stage2-install:
        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 \
+       make -j $(MAKE_JOBS) install
+
+patches: gcc-$(GCC_VERSION) binutils-$(BINUTILS_VERSION)
+       rm -rf orig-src
+       mkdir orig-src
+       
+       find . -name autom4te.cache | xargs rm -rf
+       patch --no-backup-if-mismatch -Rp0 < gcc-$(GCC_VERSION)-riscv.patch
+       tar -C orig-src -jxf gcc-$(GCC_VERSION).tar.bz2
+       -diff -ruN orig-src/gcc-$(GCC_VERSION) gcc-$(GCC_VERSION) \
              > 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)
+       patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
        
-       mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
-       tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
-       -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
+       patch --no-backup-if-mismatch -Rp0 < binutils-$(BINUTILS_VERSION)-riscv.patch
+       tar -C orig-src -jxf binutils-$(BINUTILS_VERSION).tar.bz2
+       -diff -ruN orig-src/binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION) \
              > binutils-$(BINUTILS_VERSION)-ros.patch
-       rm -rf binutils-$(BINUTILS_VERSION)
-       mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
-
+       patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
+       
+       rm -rf orig-src