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