Massive glibc and directory structure change
[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         $(MAKE) .glibc-patch
146
147 .glibc-patch: glibc-$(GLIBC_VERSION)
148         cd glibc-$(GLIBC_VERSION); \
149         diff -ruB --unidirectional-new-file \
150              ../glibc-$(GLIBC_VERSION) \
151              ../glibc-$(GLIBC_VERSION)-ros \
152              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
153              | patch -p2 
154
155 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
156         rm -rf $@
157         cp -R binutils-$(BINUTILS_VERSION) $@
158
159 $(BINARY_PREFIX)glibc-headers-builddir: glibc-$(GLIBC_VERSION)
160         rm -rf $@
161         mkdir -p $@
162
163 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
164         rm -rf $@
165         mkdir -p $@
166         
167 $(BINARY_PREFIX)glibc-builddir: glibc-$(GLIBC_VERSION)
168         rm -rf $@
169         mkdir -p $@
170
171 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
172         rm -rf $@
173         mkdir -p $@
174         
175 .$(BINARY_PREFIX)binutils-configure: 
176         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
177         cd $(BINARY_PREFIX)binutils-builddir; \
178         ./configure --enable-shared \
179                     --disable-multilib \
180                     --target=$(ARCH)-ros \
181                     --prefix=$(INSTDIR) \
182                     --includedir=$(INSTDIR)/include \
183                     --disable-werror;
184         touch $@
185
186 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
187         cd $(BINARY_PREFIX)binutils-builddir; \
188         make -j
189
190 .$(BINARY_PREFIX)binutils-install:
191         cd $(BINARY_PREFIX)binutils-builddir; \
192         make -j install
193
194 .$(BINARY_PREFIX)glibc-headers-configure: 
195         $(MAKE) $(BINARY_PREFIX)glibc-headers-builddir
196         cd $(BINARY_PREFIX)glibc-headers-builddir; \
197         ../glibc-$(GLIBC_VERSION)/configure \
198                   --host=$(ARCH)-ros \
199                   --enable-hacker-mode \
200                   --enable-shared \
201                   --with-elf \
202                   --with-tls \
203                   --with-__thread \
204                   --prefix=$(INSTDIR)/$(ARCH)-ros \
205                   --with-headers=$(ROSDIR)/kern/include/ \
206                   libc_cv_forced_unwind=yes \
207                   libc_cv_c_cleanup=yes;
208         touch $@
209
210 .$(BINARY_PREFIX)glibc-headers-install: .$(BINARY_PREFIX)glibc-headers-configure
211         cd $(BINARY_PREFIX)glibc-headers-builddir; \
212         make -j install-headers; \
213         mkdir -p $(INSTDIR)/$(ARCH)-ros/include/gnu; \
214         touch $(INSTDIR)/$(ARCH)-ros/include/gnu/stubs.h; \
215         cp bits/stdio_lim.h $(INSTDIR)/$(ARCH)-ros/include/bits/
216
217 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
218         $(MAKE) -C $(ROSDIR) symlinks
219         mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include
220         cp -r $(ROSDIR)/kern/include/ros \
221            $(INSTDIR)/$(ARCH)-ros/sys-include/
222         cp -r $(ROSDIR)/kern/include/arch \
223            $(INSTDIR)/$(ARCH)-ros/sys-include/
224
225 .$(BINARY_PREFIX)gcc-stage1-configure: 
226         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
227         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
228         ../gcc-$(GCC_VERSION)/configure \
229                 --enable-languages=c \
230                 --enable-shared \
231                 --disable-checking \
232                 --disable-werror \
233                 --disable-multilib \
234                 --disable-libmudflap \
235                 --disable-libssp \
236                 --disable-libgomp \
237                 --program-prefix=$(BINARY_PREFIX) \
238                 --target=$(ARCH)-ros \
239                 --prefix=$(INSTDIR) \
240                 --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
241                 $(GCC_BUILD_FLAGS);
242         touch $@
243
244 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
245         # Put the - in front of make because it actually fails and
246         # we don't want the whole make process to fail.
247         # It appears to still work though since this is just stage 1 of compiling
248         # Should really look into fixing this though...
249         -cd $(BINARY_PREFIX)gcc-stage1-builddir; \
250         make -j
251
252 .$(BINARY_PREFIX)gcc-stage1-install: 
253         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
254         make -j install
255
256 .$(BINARY_PREFIX)glibc-configure: 
257         $(MAKE) $(BINARY_PREFIX)glibc-builddir
258         cd $(BINARY_PREFIX)glibc-builddir; \
259         ../glibc-$(GLIBC_VERSION)/configure \
260                   --host=$(ARCH)-ros \
261                   --enable-hacker-mode \
262                   --enable-shared \
263                   --with-elf \
264                   --with-tls \
265                   --with-__thread \
266                   --with-headers=$(ROSDIR)/kern/include/ \
267                   --prefix=$(INSTDIR)/$(ARCH)-ros \
268                   libc_cv_forced_unwind=yes \
269                   libc_cv_c_cleanup=yes;
270         touch $@
271
272 .$(BINARY_PREFIX)glibc-make: .$(BINARY_PREFIX)glibc-configure
273         cd $(BINARY_PREFIX)glibc-builddir; \
274         make -j
275
276 .$(BINARY_PREFIX)glibc-install: 
277         cd $(BINARY_PREFIX)glibc-builddir; \
278         make -j install
279
280 .$(BINARY_PREFIX)gcc-stage2-configure: 
281         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
282         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
283         ../gcc-$(GCC_VERSION)/configure \
284                   --enable-shared \
285                   --disable-multilib \
286                   --program-prefix=$(BINARY_PREFIX) \
287                   --target=$(ARCH)-ros \
288                   --prefix=$(INSTDIR) \
289                   --enable-languages=c,c++ \
290                   $(GCC_BUILD_FLAGS) \
291                   --with-tls \
292                   --with-__thread \
293                   --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
294                   --disable-werror;
295         touch $@
296
297 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
298         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
299         make -j
300
301 .$(BINARY_PREFIX)gcc-stage2-install:
302         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
303         make -j install
304
305 patches:
306         -cd glibc-$(GLIBC_VERSION)/manual; make realclean
307         rm -rf glibc-$(GLIBC_VERSION)/autom4te.cache
308         mv glibc-$(GLIBC_VERSION) glibc-$(GLIBC_VERSION).new
309         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
310         -diff -ruN glibc-$(GLIBC_VERSION) glibc-$(GLIBC_VERSION).new \
311               > glibc-$(GLIBC_VERSION)-ros.patch
312         rm -rf glibc-$(GLIBC_VERSION)
313         mv glibc-$(GLIBC_VERSION).new glibc-$(GLIBC_VERSION)
314         
315         mv gcc-$(GCC_VERSION)/gmp .
316         mv gcc-$(GCC_VERSION)/mpfr .
317         rm -rf gcc-$(GCC_VERSION)/libstdc++-v3/autom4te.cache
318         mv gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new
319         tar -zxf gcc-$(GCC_VERSION).tar.gz
320         -diff -ruN gcc-$(GCC_VERSION) gcc-$(GCC_VERSION).new \
321               > gcc-$(GCC_VERSION)-ros.patch
322         rm -rf gcc-$(GCC_VERSION)
323         mv gcc-$(GCC_VERSION).new gcc-$(GCC_VERSION)
324         mv gmp gcc-$(GCC_VERSION)
325         mv mpfr gcc-$(GCC_VERSION)
326         
327         mv binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new
328         tar -zxf binutils-$(BINUTILS_VERSION).tar.gz
329         -diff -ruN binutils-$(BINUTILS_VERSION) binutils-$(BINUTILS_VERSION).new \
330               > binutils-$(BINUTILS_VERSION)-ros.patch
331         rm -rf binutils-$(BINUTILS_VERSION)
332         mv binutils-$(BINUTILS_VERSION).new binutils-$(BINUTILS_VERSION)
333