e0638704c540eaaf3903fc6da322e2ea95ed0607
[carl9170fw.git] / Makefile
1 BINUTILS_VER=2.27
2 BINUTILS_TAR=binutils-$(BINUTILS_VER).tar.bz2
3 BINUTILS_URL="http://mirrors.kernel.org/gnu/binutils/$(BINUTILS_TAR)"
4
5 NEWLIB_VER=2.4.0
6 NEWLIB_TAR=newlib-$(NEWLIB_VER).tar.gz
7 NEWLIB_URL="ftp://sourceware.org/pub/newlib/$(NEWLIB_TAR)"
8
9 GCC_VER=6.2.0
10 GCC_TAR=gcc-$(GCC_VER).tar.bz2
11 GCC_URL="http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VER)/$(GCC_TAR)"
12
13 JOBS?=$(shell grep -c ^processor /proc/cpuinfo)
14
15 BASEDIR=$(shell pwd)
16
17 define checksum
18 @if grep -q '  $(subst .,\.,$(1))$$' SHA256SUMS; then                   \
19         grep '  $(subst .,\.,$(1))$$' SHA256SUMS | sha256sum -c || rm $(1);     \
20 else                                                                    \
21         echo "WARNING: no checksum defined for $(1)";                   \
22 fi
23 endef
24
25 all: clean gcc
26
27 src/$(BINUTILS_TAR):
28         wget -P "$(BASEDIR)/src" $(BINUTILS_URL)
29         $(call checksum,$@)
30
31 src/$(NEWLIB_TAR):
32         wget -P "$(BASEDIR)/src" $(NEWLIB_URL)
33         $(call checksum,$@)
34
35 src/$(GCC_TAR):
36         wget -P "$(BASEDIR)/src" $(GCC_URL)
37         $(call checksum,$@)
38
39 src/binutils-$(BINUTILS_VER): src/$(BINUTILS_TAR)
40         tar -C "$(BASEDIR)/src" -xf $<
41
42 src/newlib-$(NEWLIB_VER): src/$(NEWLIB_TAR)
43         tar -C "$(BASEDIR)/src" -xf $<
44
45 src/gcc-$(GCC_VER): src/$(GCC_TAR) src/newlib-$(NEWLIB_VER)
46         tar -C "$(BASEDIR)/src" -xf $<
47         ln -s $(BASEDIR)/src/newlib-$(NEWLIB_VER)/newlib $@
48         ln -s $(BASEDIR)/src/newlib-$(NEWLIB_VER)/libgloss $@
49
50 binutils: src/binutils-$(BINUTILS_VER)
51         mkdir -p "$(BASEDIR)/build/binutils"
52         cd "$(BASEDIR)/build/binutils"; \
53         $(BASEDIR)/$</configure --target=sh-elf --prefix=$(BASEDIR)/inst; \
54         $(MAKE) -j$(JOBS); \
55         $(MAKE) install
56
57 gcc: src/gcc-$(GCC_VER) binutils
58         mkdir -p "$(BASEDIR)/build/gcc"
59         cd "$(BASEDIR)/build/gcc"; \
60         $(BASEDIR)/$</configure --target=sh-elf --prefix=$(BASEDIR)/inst -enable-languages=c --without-pkgversion --with-newlib; \
61         $(MAKE) -j$(JOBS); \
62         $(MAKE) install
63
64 clean:
65         rm -rf "$(BASEDIR)/build" "$(BASEDIR)/inst"
66
67 distclean: clean
68         rm -rf "$(BASEDIR)/src"