Added back harts support
[akaros.git] / tools / compilers / gcc-glibc / Makefile
1 # Defines where to install the toolchain
2 -include Makelocal
3
4 ifndef ROSDIR
5 busted0: 
6         @echo "You need to set ROSDIR to the path of the ROS source code. The best way to do this is to create a 'Makelocal' file in the current directory and put it in there."
7 endif
8
9 ifndef RAMP_INSTDIR
10 ifndef X86_INSTDIR
11 busted: 
12         @echo "You need to setup either a RAMP_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."
13 endif
14 endif 
15
16 BINUTILS_VERSION := 2.18
17 GCC_VERSION := 4.3.2
18 GLIBC_VERSION := 2.11.1
19
20 BUILDDIR ?= $(shell pwd)/
21 DESTDIR ?= /
22
23 # Configuration parameters for make-ramp
24 RAMP_ARCH := sparc
25 RAMP_BINARY_PREFIX := $(RAMP_ARCH)-ros-
26 RAMP_GCC_BUILD_FLAGS := --with-cpu=v8
27
28 # Configuration parameters for x86
29 X86_ARCH := i386
30 X86_BINARY_PREFIX := $(X86_ARCH)-ros-
31 X86_GCC_BUILD_FLAGS := 
32
33 all:
34         @echo "You need to run one of the following commands, "
35         @echo "depending on which version of the cross compiler you are trying to generate:"
36         @echo "  make ramp"
37         @echo "  make x86"
38         @echo "  make ramp-revert"
39         @echo "  make x86-revert"
40         @echo "  make ramp-uninstall"
41         @echo "  make x86-uninstall"
42         @echo "  make clean"
43
44 ramp:
45         export LD_LIBRARY_PATH=; \
46         export DESTDIR=$(DESTDIR);\
47         export INSTDIR=$(RAMP_INSTDIR);\
48         export PATH=$(DESTDIR)$(RAMP_INSTDIR)/bin:$(PATH);\
49         export ARCH=$(RAMP_ARCH);\
50         export ROS_ARCH_DIR=$(RAMP_ARCH);\
51         export BINARY_PREFIX=$(RAMP_BINARY_PREFIX);\
52         export GCC_BUILD_FLAGS=$(RAMP_GCC_BUILD_FLAGS);\
53         $(MAKE) make-all
54
55 x86:
56         $(MAKE) .glibc-patch
57         export LD_LIBRARY_PATH=; \
58         export DESTDIR=$(DESTDIR);\
59         export INSTDIR=$(X86_INSTDIR);\
60         export PATH=$(DESTDIR)$(X86_INSTDIR)/bin:$(PATH);\
61         export ARCH=$(X86_ARCH);\
62         export ROS_ARCH_DIR=$(X86_ARCH);\
63         export BINARY_PREFIX=$(X86_BINARY_PREFIX);\
64         export GCC_BUILD_FLAGS=$(X86_GCC_BUILD_FLAGS);\
65         $(MAKE) make-all
66
67 make-all:
68         $(MAKE) .glibc-patch
69         $(MAKE) .$(BINARY_PREFIX)binutils-make
70         $(MAKE) .$(BINARY_PREFIX)binutils-install
71         $(MAKE) .$(BINARY_PREFIX)glibc-headers-install
72         $(MAKE) .$(BINARY_PREFIX)ros-headers-install
73         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-make
74         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
75         $(MAKE) .$(BINARY_PREFIX)glibc-make
76         $(MAKE) .$(BINARY_PREFIX)glibc-install
77         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-make
78         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-install
79         ln -f $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtbegin.o \
80               $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtbeginT.o
81         ln -f $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtend.o \
82               $(INSTDIR)/lib/gcc/$(ARCH)-ros/$(GCC_VERSION)/crtendT.o
83         mkdir -p $(ROSDIR)/fs/$(ARCH)/lib
84         cp -r $(INSTDIR)/$(ARCH)-ros/lib/* $(ROSDIR)/fs/$(ARCH)/lib
85
86 ramp-uninstall:
87         -rm -rf $(RAMP_INSTDIR)
88
89 x86-uninstall:
90         -rm -rf $(X86_INSTDIR)
91
92 ramp-revert: 
93         rm -rf $(RAMP_INSTDIR)
94         cp -r $(RAMP_BINARY_PREFIX)install.bak $(RAMP_INSTDIR)
95
96 x86-revert: 
97         rm -rf $(X86_INSTDIR)
98         cp -r $(X86_BINARY_PREFIX)install.bak $(X86_INSTDIR)
99
100 clean:
101         rm -rf binutils-$(BINUTILS_VERSION) 
102         rm -rf gcc-$(GCC_VERSION) 
103         rm -rf glibc-$(GLIBC_VERSION) 
104         rm -rf *-builddir
105         rm -rf .*-ros-*-configure
106         rm -rf *$(BINARY_PREFIX)install.bak
107
108 binutils-clean:
109         cd $(BINARY_PREFIX)binutils-builddir; \
110         make clean
111
112 gcc-clean:
113         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
114         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
115         make clean
116
117 glibc-clean:
118         cd $(BINARY_PREFIX)glibc-headers-builddir; \
119         cd $(BINARY_PREFIX)glibc-builddir; \
120         make clean
121
122 binutils-$(BINUTILS_VERSION):
123         rm -rf binutils-$(BINUTILS_VERSION);
124         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
125         patch -p0 < binutils-$(BINUTILS_VERSION)-ros.patch
126
127 gcc-$(GCC_VERSION):
128         rm -rf gcc-$(GCC_VERSION)
129         tar -zxf gcc-$(GCC_VERSION).tar.gz
130         patch -p0 < gcc-$(GCC_VERSION)-ros.patch
131         cd gcc-$(GCC_VERSION)/libstdc++-v3; \
132         autoconf
133         
134         cd gcc-$(GCC_VERSION); \
135         tar -zxf ../mpfr-2.3.2.tar.gz; \
136         mv mpfr* mpfr
137         
138         cd gcc-$(GCC_VERSION); \
139         tar -zxf ../gmp-4.2.4.tar.gz; \
140         mv gmp* gmp
141
142 glibc-$(GLIBC_VERSION): 
143         rm -rf glibc-$(GLIBC_VERSION)
144         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
145         rm glibc-$(GLIBC_VERSION)/sysdeps/sparc/sparc32/elf/start.S
146         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
147         $(MAKE) .glibc-patch
148
149 .glibc-patch: glibc-$(GLIBC_VERSION)
150         cd glibc-$(GLIBC_VERSION); \
151         diff -ruB --unidirectional-new-file \
152              ../glibc-$(GLIBC_VERSION) \
153              ../glibc-$(GLIBC_VERSION)-ros \
154              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
155              | patch -p2 
156
157 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
158         rm -rf $@
159         cp -R binutils-$(BINUTILS_VERSION) $@
160
161 $(BINARY_PREFIX)glibc-headers-builddir: glibc-$(GLIBC_VERSION)
162         rm -rf $@
163         mkdir -p $@
164
165 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
166         rm -rf $@
167         mkdir -p $@
168         
169 $(BINARY_PREFIX)glibc-builddir: glibc-$(GLIBC_VERSION)
170         rm -rf $@
171         mkdir -p $@
172
173 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
174         rm -rf $@
175         mkdir -p $@
176         
177 .$(BINARY_PREFIX)binutils-configure: 
178         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
179         cd $(BINARY_PREFIX)binutils-builddir; \
180         ./configure --enable-shared \
181                     --disable-multilib \
182                     --target=$(ARCH)-ros \
183                     --prefix=$(INSTDIR) \
184                     --includedir=$(INSTDIR)/include \
185                     --disable-werror;
186         touch $@
187
188 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
189         cd $(BINARY_PREFIX)binutils-builddir; \
190         make -j
191
192 .$(BINARY_PREFIX)binutils-install:
193         cd $(BINARY_PREFIX)binutils-builddir; \
194         make -j install
195
196 .$(BINARY_PREFIX)glibc-headers-configure: 
197         $(MAKE) $(BINARY_PREFIX)glibc-headers-builddir
198         cd $(BINARY_PREFIX)glibc-headers-builddir; \
199         ../glibc-$(GLIBC_VERSION)/configure \
200                   --host=$(ARCH)-ros \
201                   --enable-hacker-mode \
202                   --enable-shared \
203                   --with-elf \
204                   --with-tls \
205                   --with-__thread \
206                   --prefix=$(INSTDIR)/$(ARCH)-ros \
207                   --with-headers=$(ROSDIR)/kern/include/ \
208                   libc_cv_forced_unwind=yes \
209                   libc_cv_c_cleanup=yes;
210         touch $@
211
212 .$(BINARY_PREFIX)glibc-headers-install: .$(BINARY_PREFIX)glibc-headers-configure
213         cd $(BINARY_PREFIX)glibc-headers-builddir; \
214         make -j install-headers; \
215         mkdir -p $(INSTDIR)/$(ARCH)-ros/include/gnu; \
216         touch $(INSTDIR)/$(ARCH)-ros/include/gnu/stubs.h; \
217         cp bits/stdio_lim.h $(INSTDIR)/$(ARCH)-ros/include/bits/
218
219 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
220         $(MAKE) -C $(ROSDIR) symlinks
221         mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include/arch
222         cp -r $(ROSDIR)/kern/include/ros \
223            $(INSTDIR)/$(ARCH)-ros/sys-include/
224         cp -r $(ROSDIR)/kern/include/arch/* \
225            $(INSTDIR)/$(ARCH)-ros/sys-include/arch/
226
227 .$(BINARY_PREFIX)gcc-stage1-configure: 
228         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
229         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
230         ../gcc-$(GCC_VERSION)/configure \
231                 --enable-languages=c \
232                 --enable-shared \
233                 --disable-checking \
234                 --disable-werror \
235                 --disable-multilib \
236                 --disable-libmudflap \
237                 --disable-libssp \
238                 --disable-libgomp \
239                 --program-prefix=$(BINARY_PREFIX) \
240                 --target=$(ARCH)-ros \
241                 --prefix=$(INSTDIR) \
242                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
243                 $(GCC_BUILD_FLAGS);
244         touch $@
245
246 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
247         # Put the - in front of make because it actually fails and
248         # we don't want the whole make process to fail.
249         # It appears to still work though since this is just stage 1 of compiling
250         # Should really look into fixing this though...
251         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
252         make -j
253
254 .$(BINARY_PREFIX)gcc-stage1-install: 
255         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
256         make -j install
257
258 .$(BINARY_PREFIX)glibc-configure: 
259         $(MAKE) $(BINARY_PREFIX)glibc-builddir
260         cd $(BINARY_PREFIX)glibc-builddir; \
261         ../glibc-$(GLIBC_VERSION)/configure \
262                   --host=$(ARCH)-ros \
263                   --enable-hacker-mode \
264                   --enable-shared \
265                   --with-elf \
266                   --with-tls \
267                   --with-__thread \
268                   --with-headers=$(ROSDIR)/kern/include/ \
269                   --prefix=$(INSTDIR)/$(ARCH)-ros \
270                   libc_cv_forced_unwind=yes \
271                   libc_cv_c_cleanup=yes;
272         touch $@
273
274 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
275         cd $(BINARY_PREFIX)glibc-builddir; \
276         make -j
277
278 .$(BINARY_PREFIX)glibc-install: 
279         cd $(BINARY_PREFIX)glibc-builddir; \
280         make -j install
281
282 .$(BINARY_PREFIX)gcc-stage2-configure: 
283         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
284         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
285         ../gcc-$(GCC_VERSION)/configure \
286                   --enable-shared \
287                   --disable-multilib \
288                   --program-prefix=$(BINARY_PREFIX) \
289                   --target=$(ARCH)-ros \
290                   --prefix=$(INSTDIR) \
291                   --enable-languages=c,c++ \
292                   $(GCC_BUILD_FLAGS) \
293                   --with-tls \
294                   --with-__thread \
295                   --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
296                   --disable-werror;
297         touch $@
298
299 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
300         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
301         make -j
302
303 .$(BINARY_PREFIX)gcc-stage2-install:
304         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
305         make -j install
306
307 patches:
308         -cd glibc-$(GLIBC_VERSION)/manual; make realclean
309         rm -rf glibc-$(GLIBC_VERSION)/autom4te.cache
310         mv glibc-$(GLIBC_VERSION) glibc-$(GLIBC_VERSION).new
311         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
312         -diff -ruN glibc-$(GLIBC_VERSION) glibc-$(GLIBC_VERSION).new \
313               > glibc-$(GLIBC_VERSION)-ros.patch
314         rm -rf glibc-$(GLIBC_VERSION)
315         mv glibc-$(GLIBC_VERSION).new glibc-$(GLIBC_VERSION)
316         
317         mv gcc-$(GCC_VERSION)/gmp .
318         mv gcc-$(GCC_VERSION)/mpfr .
319         rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache
320         mv gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new
321         tar -zxf gcc-$(GCC_VERSION).tar.gz
322         -diff -ruN gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new \
323               > gcc-$(GCC_VERSION)-ros.patch
324         rm -rf gcc-$(GCC_VERSION)
325         mv gcc-$(GCC_VERSION).new gcc-$(GCC_VERSION)
326         mv gmp gcc-$(GCC_VERSION)
327         mv mpfr gcc-$(GCC_VERSION)
328         
329         mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
330         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
331         -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
332               > binutils-$(BINUTILS_VERSION)-ros.patch
333         rm -rf binutils-$(BINUTILS_VERSION)
334         mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
335