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