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