GNU toolchain for RISC-V, including GCC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
4.9 KiB

INSTALL_DIR := @prefix@
srcdir := $(shell cd @top_srcdir@ && pwd)
PACKAGES := binutils gcc glibc newlib
gcc_version := 4.9.1
binutils_version := 2.24
glibc_version := 2.20
newlib_version := 1.18.0
GNU_MIRROR := ftp://mirrors.kernel.org/gnu
gcc_url := $(GNU_MIRROR)/gcc/gcc-$(gcc_version)/gcc-$(gcc_version).tar.gz
binutils_url := $(GNU_MIRROR)/binutils/binutils-$(binutils_version).tar.gz
glibc_url := $(GNU_MIRROR)/glibc/glibc-$(glibc_version).tar.gz
newlib_url := ftp://sourceware.org/pub/newlib/newlib-$(newlib_version).tar.gz
LINUX_DIR := $(srcdir)/linux-headers/
BASH := /bin/bash
SHELL := $(BASH)
# Check that we have gawk installed. Set awk=gawk if necessary.
ifeq ($(shell awk --version | grep GNU),)
ifeq ($(shell gawk --version),)
$(error You must have gawk installed on your system!)
else
PATH := $(srcdir)/scripts/gawk:$(PATH)
SHELL := PATH="$(PATH)" $(BASH)
endif
endif
# Check that we have gsed installed. Set sed=gsed if necessary.
ifeq ($(shell sed --version 2> /dev/null | grep GNU),)
ifeq ($(shell gsed --version),)
$(error You must have gsed installed on your system!)
else
PATH := $(srcdir)/scripts/gsed:$(PATH)
SHELL := PATH="$(PATH)" $(BASH)
endif
endif
newlib: build-gcc-newlib
linux: build-gcc-linux-stage2
$(addprefix src/original-,$(PACKAGES)):
mkdir -p src
rm -rf $@ $(subst original-,,$@)-*
cd src && curl $($(subst src/original-,,$@)_url) | tar zx
mv $(subst original-,,$@)-$($(subst src/original-,,$@)_version) $@
$(addprefix src/,$(PACKAGES)): src/%: src/original-%
rm -rf $@ $@.tmp
cp -r $< $@.tmp
rsync -a --link-dest=$(srcdir)/$(shell basename $@) $(srcdir)/$(shell basename $@)/ $@.tmp
cd $@.tmp && patch -p1 < $(srcdir)/patches/$(shell basename $@)
mv $@.tmp $@
.PHONY: patches $(addprefix $(srcdir)/patches/,$(PACKAGES))
$(addprefix $(srcdir)/patches/,$(PACKAGES)): $(srcdir)/patches/%: src/%
-cd src/$(shell basename $@) && rm `cd $(srcdir)/$(shell basename $@) && find . -type f`
-cd src && diff --exclude=manual --exclude=autom4te.cache -rupN original-$(shell basename $@) $(shell basename $@) | filterdiff --remove-timestamps > $@
rsync -a --link-dest=$(srcdir)/$(shell basename $@) $(srcdir)/$(shell basename $@)/ $<
patches: $(addprefix $(srcdir)/patches/,$(PACKAGES))
build-binutils-linux: src/binutils
rm -rf $@
mkdir $@
cd $@ && \
CFLAGS+=-Wno-error=deprecated-declarations \
$(shell pwd)/$</configure \
--target=riscv64-unknown-linux-gnu \
--prefix=$(INSTALL_DIR) \
--enable-tls \
--disable-multilib
$(MAKE) -C $@
$(MAKE) -C $@ install
build-glibc-linux: src/glibc build-gcc-linux-stage1
rm -rf $@
mkdir $@
cd $@ && CC= $(shell pwd)/$</configure \
--host=riscv64-unknown-linux-gnu \
--prefix=$(INSTALL_DIR)/riscv64-unknown-linux-gnu \
libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
--enable-shared \
--enable-__thread \
--disable-multilib \
--with-headers=$(LINUX_DIR)/include
$(MAKE) -C $@
$(MAKE) -C $@ install
build-gcc-linux-stage1: src/gcc build-binutils-linux
rm -rf $@
mkdir $@
cd $@ && $(shell pwd)/$</configure \
--target=riscv64-unknown-linux-gnu \
--prefix=$(INSTALL_DIR) \
--enable-shared \
--disable-threads \
--enable-tls \
--enable-languages=c \
--disable-libatomic \
--disable-libmudflap \
--disable-libssp \
--disable-libquadmath \
--disable-libgomp \
--disable-nls \
--disable-multilib \
--disable-bootstrap
-$(MAKE) -C $@ inhibit-libc=true
$(MAKE) -C $@ install
build-gcc-linux-stage2: src/gcc build-glibc-linux
rm -rf $@
mkdir $@
cd $@ && $(shell pwd)/$</configure \
--target=riscv64-unknown-linux-gnu \
--prefix=$(INSTALL_DIR) \
--enable-shared \
--enable-tls \
--enable-languages=c,c++ \
--disable-libmudflap \
--disable-libssp \
--disable-libquadmath \
--disable-nls \
--disable-multilib \
--disable-bootstrap \
--with-headers=$(LINUX_DIR)/include
$(MAKE) -C $@
$(MAKE) -C $@ install
build-binutils-newlib: src/binutils
rm -rf $@
mkdir $@
cd $@ && \
CFLAGS+=-Wno-error=deprecated-declarations \
$(shell pwd)/$</configure \
--target=riscv64-unknown-elf \
--prefix=$(INSTALL_DIR) \
--enable-tls
$(MAKE) -C $@
$(MAKE) -C $@ install
src/newlib-gcc: src/gcc src/newlib
rm -rf $@
rsync -a --link-dest=$(shell pwd)/src/gcc $(shell pwd)/src/gcc/* $@
rsync -a --link-dest=$(shell pwd)/src/newlib/newlib $(shell pwd)/src/newlib/newlib $@
rsync -a --link-dest=$(shell pwd)/src/newlib/libgloss $(shell pwd)/src/newlib/libgloss $@
build-gcc-newlib: src/newlib-gcc build-binutils-newlib
rm -rf $@
mkdir $@
cd $@ && $(shell pwd)/$</configure \
--target=riscv64-unknown-elf \
--prefix=$(INSTALL_DIR) \
--disable-shared \
--disable-threads \
--enable-tls \
--enable-languages=c,c++ \
--with-newlib \
--disable-libmudflap \
--disable-libssp \
--disable-libquadmath \
--disable-libgomp \
--disable-nls
$(MAKE) -C $@ inhibit-libc=true
$(MAKE) -C $@ install
clean:
rm -rf build-* $(addprefix src/,$(PACKAGES))
distclean:
rm -rf build-* src
# All of the packages install themselves, so our install target does nothing.
install: