Fixed bug in userspace brk
[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/ros/*
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
233 .$(BINARY_PREFIX)gcc-stage1-configure: 
234         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
235         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
236         ../gcc-$(GCC_VERSION)/configure \
237                 --enable-languages=c \
238                 --enable-shared \
239                 --disable-checking \
240                 --disable-werror \
241                 --disable-multilib \
242                 --disable-libmudflap \
243                 --disable-libssp \
244                 --disable-libgomp \
245                 --disable-nls \
246                 --program-prefix=$(BINARY_PREFIX) \
247                 --target=$(ARCH)-ros \
248                 --prefix=$(INSTDIR) \
249                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
250                 $(GCC_BUILD_FLAGS);
251         touch $@
252
253 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
254         # Put the - in front of make because it actually fails and
255         # we don't want the whole make process to fail.
256         # It appears to still work though since this is just stage 1 of compiling
257         # Should really look into fixing this though...
258         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
259         make -j $(MAKE_JOBS) inhibit_libc=true cross-compiling=yes
260
261 .$(BINARY_PREFIX)gcc-stage1-install: 
262         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
263         make -j $(MAKE_JOBS) install
264         #-ln -vs libgcc.a `$(BINARY_PREFIX)gcc -print-libgcc-file-name | \
265         #                 sed 's/libgcc/&_eh/'`
266
267 .$(BINARY_PREFIX)glibc-configure: 
268         $(MAKE) $(BINARY_PREFIX)glibc-builddir
269         cd $(BINARY_PREFIX)glibc-builddir; \
270         ../glibc-$(GLIBC_VERSION)/configure \
271                   --host=$(ARCH)-ros \
272                   --enable-hacker-mode \
273                   --enable-shared \
274                   --with-elf \
275                   --with-tls \
276                   --disable-nls \
277                   --with-__thread \
278                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
279                   --prefix=$(INSTDIR)/$(ARCH)-ros \
280                   libc_cv_forced_unwind=yes \
281                   libc_cv_c_cleanup=yes \
282                   CFLAGS="$(ARCH_CFLAGS) -fpermissive -O2 -pipe";
283         touch $@
284
285 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
286         cd $(BINARY_PREFIX)glibc-builddir; \
287         make -j $(MAKE_JOBS)
288
289 .$(BINARY_PREFIX)glibc-install: 
290         cd $(BINARY_PREFIX)glibc-builddir; \
291         make -j $(MAKE_JOBS) install
292
293 .$(BINARY_PREFIX)gcc-stage2-configure:
294         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
295         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
296         ../gcc-$(GCC_VERSION)/configure \
297                   --enable-shared \
298                   --disable-multilib \
299                   --disable-nls \
300                   --program-prefix=$(BINARY_PREFIX) \
301                   --target=$(ARCH)-ros \
302                   --prefix=$(INSTDIR) \
303                   --enable-languages=c,c++ \
304                   $(GCC_BUILD_FLAGS) \
305                   --with-tls \
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:
320         mv gcc-$(GCC_VERSION)/gmp .
321         mv gcc-$(GCC_VERSION)/mpfr .
322         rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache
323         mv gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new
324         tar -zxf gcc-$(GCC_VERSION).tar.gz
325         -diff -ruN gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new \
326               > gcc-$(GCC_VERSION)-ros.patch
327         rm -rf gcc-$(GCC_VERSION)
328         mv gcc-$(GCC_VERSION).new gcc-$(GCC_VERSION)
329         mv gmp gcc-$(GCC_VERSION)
330         mv mpfr gcc-$(GCC_VERSION)
331         
332         mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
333         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
334         -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
335               > binutils-$(BINUTILS_VERSION)-ros.patch
336         rm -rf binutils-$(BINUTILS_VERSION)
337         mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
338