Added gccgo support for akaros
[akaros.git] / tools / compilers / gcc-glibc / Makefile
1 # Number of make jobs to spawn.  Define it in Makelocal
2 MAKE_JOBS := 
3
4 # Defines where to install the toolchain
5 -include Makelocal
6
7 ifndef RISCV_INSTDIR
8 ifndef X86_INSTDIR
9 busted: 
10         @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
11 riscv: busted
12 x86: busted
13 endif
14 endif 
15
16 # Check to make sure that we have gawk installed on our system and not some
17 # other version of awk
18 AWK := $(shell awk -W version 2>&1 | head -n 1 | awk '{print $$1}')
19 ifneq ($(AWK),GNU)
20 $(error You need to have 'gawk' installed on your system!)
21 endif
22
23 # Check to make sure that we have the GMP, MPFR, and MPC libraries installed
24 GMP_OK := $(shell echo "int main() {return 0;}" | gcc -x c - -lgmp -lmpfr -lmpc -o /dev/null > /dev/null && echo OK)
25 ifneq ($(GMP_OK),OK)
26 $(error You need to have the libraries GMP, MPFR, and MPC installed on your system!)
27 endif
28
29
30 BINUTILS_VERSION := 2.21.1
31 GCC_VERSION := 4.6.1
32 GLIBC_VERSION := 2.14.1
33
34 BUILDDIR ?= $(shell pwd)/
35 ROSDIR ?= $(BUILDDIR)/../../../
36 DESTDIR ?= /
37
38 # Configuration parameters for make-riscv
39 RISCV_ARCH := riscv
40 RISCV_BINARY_PREFIX := $(RISCV_ARCH)-ros-
41 RISCV_GCC_BUILD_FLAGS :=
42 RISCV_CFLAGS :=
43
44 # Configuration parameters for x86
45 X86_ARCH := i686
46 X86_BINARY_PREFIX := $(X86_ARCH)-ros-
47 X86_GCC_BUILD_FLAGS := 
48 X86_CFLAGS := -march=i486
49
50 all:
51         @echo "You need to run one of the following commands, "
52         @echo "depending on which version of the cross compiler you are trying to generate:"
53         @echo "  make riscv"
54         @echo "  make x86"
55         @echo "  make riscv-revert"
56         @echo "  make x86-revert"
57         @echo "  make riscv-uninstall"
58         @echo "  make x86-uninstall"
59         @echo "  make clean"
60
61 riscv:
62         export LD_LIBRARY_PATH=; \
63         export DESTDIR=$(DESTDIR);\
64         export INSTDIR=$(RISCV_INSTDIR);\
65         export PATH=$(DESTDIR)$(RISCV_INSTDIR)/bin:$(PATH);\
66         export ARCH=$(RISCV_ARCH);\
67         export ARCH_CFLAGS=$(RISCV_CFLAGS);\
68         export ROS_ARCH_DIR=$(RISCV_ARCH);\
69         export BINARY_PREFIX=$(RISCV_BINARY_PREFIX);\
70         export GCC_BUILD_FLAGS=$(RISCV_GCC_BUILD_FLAGS);\
71         $(MAKE) make-all
72
73 x86:
74         export LD_LIBRARY_PATH=; \
75         export DESTDIR=$(DESTDIR);\
76         export INSTDIR=$(X86_INSTDIR);\
77         export PATH=$(DESTDIR)$(X86_INSTDIR)/bin:$(PATH);\
78         export ARCH=$(X86_ARCH);\
79         export ARCH_CFLAGS=$(X86_CFLAGS);\
80         export ROS_ARCH_DIR=$(X86_ARCH);\
81         export BINARY_PREFIX=$(X86_BINARY_PREFIX);\
82         export GCC_BUILD_FLAGS=$(X86_GCC_BUILD_FLAGS);\
83         $(MAKE) make-all
84
85 make-all: 
86         $(MAKE) .$(BINARY_PREFIX)binutils-make
87         $(MAKE) .$(BINARY_PREFIX)binutils-install
88         $(MAKE) .$(BINARY_PREFIX)ros-headers-install
89         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-make
90         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
91         $(MAKE) .$(BINARY_PREFIX)glibc-make
92         $(MAKE) .$(BINARY_PREFIX)glibc-install
93         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-make
94         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-install
95         mkdir -p $(ROSDIR)/fs/$(ARCH)/lib
96         cp -r $(INSTDIR)/$(ARCH)-ros/lib/* $(ROSDIR)/fs/$(ARCH)/lib
97
98 riscv-uninstall:
99         -rm -rf $(RISCV_INSTDIR)
100
101 x86-uninstall:
102         -rm -rf $(X86_INSTDIR)
103
104 riscv-revert:
105         rm -rf $(RISCV_INSTDIR)
106         cp -r $(RISCV_BINARY_PREFIX)install.bak $(RISCV_INSTDIR)
107
108 x86-revert: 
109         rm -rf $(X86_INSTDIR)
110         cp -r $(X86_BINARY_PREFIX)install.bak $(X86_INSTDIR)
111
112 clean:
113         rm -rf binutils-$(BINUTILS_VERSION) 
114         rm -rf gcc-$(GCC_VERSION) 
115         rm -rf glibc-$(GLIBC_VERSION) 
116         rm -rf *-builddir
117         rm -rf .*-ros-*-configure
118         rm -rf *$(BINARY_PREFIX)install.bak
119
120 binutils-clean:
121         cd $(BINARY_PREFIX)binutils-builddir; \
122         make clean
123
124 gcc-clean:
125         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
126         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
127         make clean
128
129 glibc-clean:
130         cd $(BINARY_PREFIX)glibc-builddir; \
131         make clean
132
133 %.tar.bz2:
134         wget http://akaros.cs.berkeley.edu/xcc/$@
135
136 binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
137         rm -rf binutils-$(BINUTILS_VERSION);
138         tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
139         patch -p0 < binutils-$(BINUTILS_VERSION)-ros.patch
140         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
141
142 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
143         rm -rf gcc-$(GCC_VERSION)
144         tar -jxf gcc-$(GCC_VERSION).tar.bz2
145         $(MAKE) .gcc-ros-patch
146         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
147
148 .gcc-ros-patch:
149         -cd gcc-$(GCC_VERSION); \
150         diff -ruB --unidirectional-new-file \
151              ../gcc-$(GCC_VERSION) \
152              ../gcc-$(GCC_VERSION)-ros \
153              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
154              | patch -p2 
155
156 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
157         rm -rf glibc-$(GLIBC_VERSION)
158         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
159         $(MAKE) .glibc-ros-patch
160         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
161         rm glibc-$(GLIBC_VERSION)/sysdeps/sparc/sparc32/elf/start.S
162         rm glibc-$(GLIBC_VERSION)/sysdeps/riscv/elf/start.S
163         rm glibc-$(GLIBC_VERSION)/sysdeps/riscv/init-first.c
164         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
165         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/____longjmp_chk.S
166         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/init-first.c
167         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/sysdep.h
168
169 .glibc-ros-patch:
170         -cd glibc-$(GLIBC_VERSION); \
171         diff -ruB --unidirectional-new-file \
172              ../glibc-$(GLIBC_VERSION) \
173              ../glibc-$(GLIBC_VERSION)-ros \
174              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
175              | patch -p2 
176
177 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
178         rm -rf $@
179         mkdir -p $@
180
181 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
182         rm -rf $@
183         mkdir -p $@
184         
185 $(BINARY_PREFIX)glibc-builddir: glibc-$(GLIBC_VERSION)
186         rm -rf $@
187         mkdir -p $@
188
189 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
190         rm -rf $@
191         mkdir -p $@
192         
193 .$(BINARY_PREFIX)binutils-configure: 
194         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
195         cd $(BINARY_PREFIX)binutils-builddir; \
196         ../binutils-$(BINUTILS_VERSION)/configure \
197                     --enable-shared \
198                     --disable-multilib \
199                     --disable-nls \
200                     --target=$(ARCH)-ros \
201                     --prefix=$(INSTDIR) \
202                     --includedir=$(INSTDIR)/include \
203                     --disable-werror;
204         touch $@
205
206 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
207         cd $(BINARY_PREFIX)binutils-builddir; \
208         make -j $(MAKE_JOBS)
209
210 .$(BINARY_PREFIX)binutils-install:
211         cd $(BINARY_PREFIX)binutils-builddir; \
212         make -j $(MAKE_JOBS) install
213
214 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
215         rm -rf $(INSTDIR)/$(ARCH)-ros/sys-include/*
216         mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include
217         cp -r $(ROSDIR)/kern/include/ros \
218            $(INSTDIR)/$(ARCH)-ros/sys-include/
219         rm -f $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch
220         mkdir $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch
221         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/ros/* \
222            $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch/
223         cp -r $(ROSDIR)/user/parlib/include/* \
224            $(INSTDIR)/$(ARCH)-ros/sys-include/
225         cp -r $(ROSDIR)/user/pthread/*.h \
226            $(INSTDIR)/$(ARCH)-ros/sys-include/
227         rm -rf $(INSTDIR)/$(ARCH)-ros/sys-include/arch
228         ln -s $(ARCH) $(INSTDIR)/$(ARCH)-ros/sys-include/arch 
229
230 .$(BINARY_PREFIX)gcc-stage1-configure: 
231         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
232         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
233         ../gcc-$(GCC_VERSION)/configure \
234                 --enable-languages=c \
235                 --enable-shared \
236                 --enable-tls \
237                 --disable-checking \
238                 --disable-werror \
239                 --disable-multilib \
240                 --disable-libmudflap \
241                 --disable-libssp \
242                 --disable-libquadmath \
243                 --disable-libgomp \
244                 --disable-nls \
245                 --program-prefix=$(BINARY_PREFIX) \
246                 --target=$(ARCH)-ros \
247                 --prefix=$(INSTDIR) \
248                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
249                 $(GCC_BUILD_FLAGS);
250         touch $@
251
252 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
253         # Put the - in front of make because it actually fails and
254         # we don't want the whole make process to fail.
255         # It appears to still work though since this is just stage 1 of compiling
256         # Should really look into fixing this though...
257         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
258         make -j $(MAKE_JOBS) inhibit_libc=true cross-compiling=yes
259
260 .$(BINARY_PREFIX)gcc-stage1-install: 
261         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
262         make -j $(MAKE_JOBS) install
263         #-ln -vs libgcc.a `$(BINARY_PREFIX)gcc -print-libgcc-file-name | \
264         #                 sed 's/libgcc/&_eh/'`
265
266 .$(BINARY_PREFIX)glibc-configure: 
267         $(MAKE) $(BINARY_PREFIX)glibc-builddir
268         cd $(BINARY_PREFIX)glibc-builddir; \
269         ../glibc-$(GLIBC_VERSION)/configure \
270                   --host=$(ARCH)-ros \
271                   --enable-hacker-mode \
272                   --enable-shared \
273                   --with-elf \
274                   --with-tls \
275                   --disable-nls \
276                   --with-__thread \
277                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
278                   --prefix=$(INSTDIR)/$(ARCH)-ros \
279                   libc_cv_forced_unwind=yes \
280                   libc_cv_c_cleanup=yes \
281                   CFLAGS="$(ARCH_CFLAGS) -g -fpermissive -O2 -pipe";
282         touch $@
283
284 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
285         cd $(BINARY_PREFIX)glibc-builddir; \
286         make -j $(MAKE_JOBS)
287
288 .$(BINARY_PREFIX)glibc-install: 
289         cd $(BINARY_PREFIX)glibc-builddir; \
290         make -j $(MAKE_JOBS) install
291
292 .$(BINARY_PREFIX)gcc-stage2-configure:
293         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
294         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
295         ../gcc-$(GCC_VERSION)/configure \
296                   --enable-shared \
297                   --enable-tls \
298                   --disable-multilib \
299                   --disable-nls \
300                   --program-prefix=$(BINARY_PREFIX) \
301                   --target=$(ARCH)-ros \
302                   --prefix=$(INSTDIR) \
303                   --enable-languages=c,c++,go \
304                   $(GCC_BUILD_FLAGS) \
305                   --without-libffi \
306                   --with-__thread \
307                   --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
308                   --disable-werror;
309         touch $@
310
311 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
312         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
313         make -j $(MAKE_JOBS)
314
315 .$(BINARY_PREFIX)gcc-stage2-install:
316         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
317         make -j $(MAKE_JOBS) install
318
319 patches: gcc-$(GCC_VERSION) binutils-$(BINUTILS_VERSION)
320         rm -rf orig-src
321         mkdir orig-src
322         
323         find . -name autom4te.cache | xargs rm -rf
324         patch --no-backup-if-mismatch -Rp0 < gcc-$(GCC_VERSION)-riscv.patch
325         tar -C orig-src -jxf gcc-$(GCC_VERSION).tar.bz2
326         -diff -ruN orig-src/gcc-$(GCC_VERSION) gcc-$(GCC_VERSION) \
327               > gcc-$(GCC_VERSION)-ros.patch
328         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
329         
330         patch --no-backup-if-mismatch -Rp0 < binutils-$(BINUTILS_VERSION)-riscv.patch
331         tar -C orig-src -jxf binutils-$(BINUTILS_VERSION).tar.bz2
332         -diff -ruN orig-src/binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION) \
333               > binutils-$(BINUTILS_VERSION)-ros.patch
334         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
335         
336         rm -rf orig-src