aboutsummaryrefslogtreecommitdiff
path: root/Makefile.in
blob: f3aeca8867b6295d2fbe4f8eec43e2d3eb42290c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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

MAKE_JOBS := 16

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=riscv-linux \
		--prefix=$(INSTALL_DIR) \
		--enable-tls \
		--disable-multilib
	$(MAKE) -C $@ -j $(MAKE_JOBS)
	$(MAKE) -C $@ -j $(MAKE_JOBS) install

build-glibc-linux: src/glibc build-gcc-linux-stage1
	rm -rf $@
	mkdir $@
	cd $@ && CC= $(shell pwd)/$</configure \
		--host=riscv-linux \
		--prefix=$(INSTALL_DIR)/riscv-linux \
		libc_cv_forced_unwind=yes \
		libc_cv_c_cleanup=yes \
		--enable-shared \
		--enable-__thread \
		--disable-multilib \
		--with-headers=$(LINUX_DIR)/include
	$(MAKE) -C $@ -j $(MAKE_JOBS)
	$(MAKE) -C $@ -j $(MAKE_JOBS) install

build-gcc-linux-stage1: src/gcc build-binutils-linux
	rm -rf $@
	mkdir $@
	cd $@ && $(shell pwd)/$</configure \
		--target=riscv-linux \
		--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 $@ -j $(MAKE_JOBS) inhibit-libc=true
	$(MAKE) -C $@ -j $(MAKE_JOBS) install

build-gcc-linux-stage2: src/gcc build-glibc-linux
	rm -rf $@
	mkdir $@
	cd $@ && $(shell pwd)/$</configure \
		--target=riscv-linux \
		--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 $@ -j $(MAKE_JOBS)
	$(MAKE) -C $@ -j $(MAKE_JOBS) install

build-binutils-newlib: src/binutils
	rm -rf $@
	mkdir $@
	cd $@ && \
	CFLAGS+=-Wno-error=deprecated-declarations \
	$(shell pwd)/$</configure \
		--target=riscv-elf \
		--prefix=$(INSTALL_DIR) \
		--enable-tls
	$(MAKE) -C $@ -j $(MAKE_JOBS)
	$(MAKE) -C $@ -j $(MAKE_JOBS) 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=riscv-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 $@ -j $(MAKE_JOBS) inhibit-libc=true
	$(MAKE) -C $@ -j $(MAKE_JOBS) install
	for i in $(INSTALL_DIR)/bin/riscv-elf-*; do j=`echo $$i | sed 's/riscv-elf-/riscv-/'`; if [ ! -f $$j ]; then ln -s `basename $$i` $$j; fi; done

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: