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