Clean up some tabs in 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 RISCV_INSTDIR
8 ifndef I686_INSTDIR
9 ifndef X86_64_INSTDIR
10 busted: 
11         @echo "You need to setup either a RISCV_INSTDIR, an I686_INSTDIR, or an X86_64_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
12 riscv: busted
13 i686: busted
14 x86_64: busted
15 endif
16 endif 
17 endif 
18
19 # Check to make sure that we have gawk installed on our system and not some
20 # other version of awk
21 AWK := $(shell awk -W version 2>&1 | head -n 1 | awk '{print $$1}')
22 ifneq ($(AWK),GNU)
23 $(error You need to have 'gawk' installed on your system!)
24 endif
25
26 # Check to make sure that we have the GMP, MPFR, and MPC libraries installed
27 GMP_OK := $(shell echo "int main() {return 0;}" | gcc -x c - -lgmp -lmpfr -lmpc -o /dev/null > /dev/null && echo OK)
28 ifneq ($(GMP_OK),OK)
29 $(error You need to have the libraries GMP, MPFR, and MPC installed on your system!)
30 endif
31
32 BINUTILS_VERSION := 2.21.1
33 GCC_VERSION := 4.6.1
34 GLIBC_VERSION := 2.14.1
35
36 BUILDDIR ?= $(shell pwd)/
37 ROSDIR ?= $(BUILDDIR)/../../../
38 DESTDIR ?= /
39
40 # Configuration parameters for make-riscv
41 RISCV_ARCH := riscv
42 RISCV_BINARY_PREFIX := $(RISCV_ARCH)-ros-
43 RISCV_GLIBC_CONFIGURE_FLAGS := 
44 RISCV_GCC_BUILD_FLAGS := 
45 RISCV_CFLAGS :=
46
47 # Configuration parameters for x86
48 I686_ARCH := i686
49 I686_BINARY_PREFIX := $(I686_ARCH)-ros-
50 I686_GLIBC_CONFIGURE_FLAGS := 
51 I686_GCC_BUILD_FLAGS := 
52 I686_CFLAGS := -march=i486
53
54 # Configuration parameters for x86_64
55 X86_64_ARCH := x86_64
56 X86_64_BINARY_PREFIX := $(X86_64_ARCH)-ros-
57 X86_64_GLIBC_CONFIGURE_FLAGS := "--disable-multi-arch"
58 X86_64_GCC_BUILD_FLAGS := CFLAGS="-fPIC"
59 X86_64_CFLAGS :=
60
61 #If actually building the cross compiler, make sure that the akaros tree is
62 #properly configured for the architecture we are creating the cross compiler
63 #for.
64 ifneq (,$(filter riscv,$(MAKECMDGOALS)))
65 ifeq (,$(shell grep "CONFIG_RISCV=y" $(ROSDIR)/.config))
66 error: 
67         @echo "Akaros tree not configured for riscv"
68         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
69         @echo "e.g. cd \$$ROSDIR"
70         @echo "     make ARCH=riscv defconfig"
71         @false
72 riscv: error
73 endif
74 endif
75 ifneq (,$(filter i686,$(MAKECMDGOALS)))
76 ifeq (,$(shell grep "CONFIG_X86_32=y" $(ROSDIR)/.config))
77 error: 
78         @echo "Akaros tree not configured for i686"
79         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
80         @echo "e.g. cd \$$ROSDIR"
81         @echo "     make ARCH=x86 defconfig"
82         @false
83 i686: error
84 endif
85 endif
86 ifneq (,$(filter x86_64,$(MAKECMDGOALS)))
87 ifeq (,$(shell grep "CONFIG_X86_64=y" $(ROSDIR)/.config))
88 error: 
89         @echo "Akaros tree not configured for x86_64"
90         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
91         @echo "e.g. cd \$$ROSDIR"
92         @echo "     make ARCH=x86 defconfig"
93         @echo "     make ARCH=x86 menuconfig -> Set 64 bit option"
94         @false
95 x86_64: error
96 endif
97 endif
98
99 all:
100         @echo "You need to run one of the following commands, "
101         @echo "depending on which version of the cross compiler you are trying to generate:"
102         @echo "  make riscv"
103         @echo "  make i686"
104         @echo "  make x86_64"
105         @echo "  make riscv-revert"
106         @echo "  make i686-revert"
107         @echo "  make x86_64-revert"
108         @echo "  make riscv-uninstall"
109         @echo "  make i686-uninstall"
110         @echo "  make x86_64-uninstall"
111         @echo "  make clean"
112
113 riscv:
114         export LD_LIBRARY_PATH=; \
115         export DESTDIR=$(DESTDIR);\
116         export INSTDIR=$(RISCV_INSTDIR);\
117         export PATH=$(DESTDIR)$(RISCV_INSTDIR)/bin:$(PATH);\
118         export ARCH=$(RISCV_ARCH);\
119         export ARCH_CFLAGS=$(RISCV_CFLAGS);\
120         export ROS_ARCH_DIR=$(RISCV_ARCH);\
121         export BINARY_PREFIX=$(RISCV_BINARY_PREFIX);\
122         export GLIBC_CONFIGURE_FLAGS=$(RISCV_GLIBC_CONFIGURE_FLAGS);\
123         export GCC_BUILD_FLAGS=$(RISCV_GCC_BUILD_FLAGS);\
124         $(MAKE) make-all
125
126 i686:
127         export LD_LIBRARY_PATH=; \
128         export DESTDIR=$(DESTDIR);\
129         export INSTDIR=$(I686_INSTDIR);\
130         export PATH=$(DESTDIR)$(I686_INSTDIR)/bin:$(PATH);\
131         export ARCH=$(I686_ARCH);\
132         export ARCH_CFLAGS=$(I686_CFLAGS);\
133         export ROS_ARCH_DIR=x86;\
134         export BINARY_PREFIX=$(I686_BINARY_PREFIX);\
135         export GLIBC_CONFIGURE_FLAGS=$(I686_GLIBC_CONFIGURE_FLAGS);\
136         export GCC_BUILD_FLAGS=$(I686_GCC_BUILD_FLAGS);\
137         $(MAKE) make-all
138
139 x86_64:
140         export LD_LIBRARY_PATH=; \
141         export DESTDIR=$(DESTDIR);\
142         export INSTDIR=$(X86_64_INSTDIR);\
143         export PATH=$(DESTDIR)$(X86_64_INSTDIR)/bin:$(PATH);\
144         export ARCH=$(X86_64_ARCH);\
145         export ARCH_CFLAGS=$(X86_64_CFLAGS);\
146         export ROS_ARCH_DIR=x86;\
147         export BINARY_PREFIX=$(X86_64_BINARY_PREFIX);\
148         export GLIBC_CONFIGURE_FLAGS=$(X86_64_GLIBC_CONFIGURE_FLAGS);\
149         export GCC_BUILD_FLAGS=$(X86_64_GCC_BUILD_FLAGS);\
150         $(MAKE) make-all
151
152 make-all: 
153         $(MAKE) .$(BINARY_PREFIX)binutils-install
154         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
155         $(MAKE) .$(BINARY_PREFIX)ros-headers-install
156         $(MAKE) .$(BINARY_PREFIX)dummy-libs-install
157         $(MAKE) .$(BINARY_PREFIX)glibc-stage1-install
158         $(MAKE) .$(BINARY_PREFIX)gcc-stage2-install
159         $(MAKE) .$(BINARY_PREFIX)glibc-stage2-install
160         $(MAKE) .$(BINARY_PREFIX)ros-libs-install
161         $(MAKE) .$(BINARY_PREFIX)gcc-stage3-install
162
163 riscv-uninstall:
164         -rm -rf $(RISCV_INSTDIR)
165
166 i686-uninstall:
167         -rm -rf $(I686_INSTDIR)
168
169 x86_64-uninstall:
170         -rm -rf $(X86_64_INSTDIR)
171
172 riscv-revert:
173         rm -rf $(RISCV_INSTDIR)
174         cp -r $(RISCV_BINARY_PREFIX)install.bak $(RISCV_INSTDIR)
175
176 i686-revert: 
177         rm -rf $(I686_INSTDIR)
178         cp -r $(I686_BINARY_PREFIX)install.bak $(I686_INSTDIR)
179
180 x86_64-revert: 
181         rm -rf $(X86_64_INSTDIR)
182         cp -r $(X86_64_BINARY_PREFIX)install.bak $(X86_64_INSTDIR)
183
184 %.tar.bz2:
185         wget http://akaros.cs.berkeley.edu/xcc/$@
186
187 #################################
188 ########### BINUTILS ############
189 #################################
190 binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
191         rm -rf binutils-$(BINUTILS_VERSION);
192         tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
193         patch -p0 < binutils-$(BINUTILS_VERSION)-ros.patch
194         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
195         patch -p0 < binutils-$(BINUTILS_VERSION)-objdump.patch
196
197 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
198         rm -rf $@
199         mkdir -p $@
200
201 .$(BINARY_PREFIX)binutils-configure: 
202         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
203         cd $(BINARY_PREFIX)binutils-builddir; \
204         ../binutils-$(BINUTILS_VERSION)/configure \
205                     --target=$(ARCH)-ros \
206                     --prefix=$(INSTDIR) \
207                     --disable-nls;
208         echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
209         touch $@
210
211 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
212         cd $(BINARY_PREFIX)binutils-builddir; \
213         make -j $(MAKE_JOBS)
214
215 .$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
216         cd $(BINARY_PREFIX)binutils-builddir; \
217         make -j $(MAKE_JOBS) install
218
219 binutils-clean:
220         cd $(BINARY_PREFIX)binutils-builddir; \
221         make clean
222
223 #################################
224 ########## GCC Stage 1 ##########
225 #################################
226 .gcc-ros-patch:
227         -cd gcc-$(GCC_VERSION); \
228         diff -ruB --unidirectional-new-file \
229              ../gcc-$(GCC_VERSION) \
230              ../gcc-$(GCC_VERSION)-ros \
231              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
232              | patch -p2 
233
234 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
235         rm -rf gcc-$(GCC_VERSION)
236         tar -jxf gcc-$(GCC_VERSION).tar.bz2
237         $(MAKE) .gcc-ros-patch
238         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
239
240 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
241         rm -rf $@
242         mkdir -p $@
243
244 .$(BINARY_PREFIX)gcc-stage1-configure: 
245         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
246         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
247         ../gcc-$(GCC_VERSION)/configure \
248                 --target=$(ARCH)-ros \
249                 --program-prefix=$(BINARY_PREFIX) \
250                 --prefix=$(INSTDIR) \
251                 --disable-nls \
252                 --disable-shared \
253                 --enable-languages=c,c++ \
254                 --without-headers \
255                 $(GCC_BUILD_FLAGS);
256         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
257         touch $@
258
259 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
260         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
261         make -j $(MAKE_JOBS) all-gcc;
262
263 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
264         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
265         make -j $(MAKE_JOBS) install-gcc;
266
267 #################################
268 ########## GCC Stage 2 ##########
269 #################################
270 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
271         rm -rf $@
272         mkdir -p $@
273
274 .$(BINARY_PREFIX)gcc-stage2-configure: 
275         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
276         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
277         ../gcc-$(GCC_VERSION)/configure \
278                 --target=$(ARCH)-ros \
279                 --program-prefix=$(BINARY_PREFIX) \
280                 --prefix=$(INSTDIR) \
281                 --disable-nls \
282                 --disable-shared \
283                 --disable-multilib \
284                 --enable-languages=c \
285                 --without-headers \
286                 $(GCC_BUILD_FLAGS);
287         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
288         touch $@
289
290 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
291         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
292         make -j $(MAKE_JOBS) all-gcc all-target-libgcc;
293
294 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
295         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
296         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
297
298 #################################
299 ######### ROS Headers ###########
300 #################################
301 .$(BINARY_PREFIX)ros-headers-install: $(ROSDIR)
302         rm -rf $(INSTDIR)/$(ARCH)-ros/sys-include/*
303         mkdir -p $(INSTDIR)/$(ARCH)-ros/sys-include
304         cp -r $(ROSDIR)/kern/include/ros \
305            $(INSTDIR)/$(ARCH)-ros/sys-include/
306         rm -f $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch
307         mkdir $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch
308         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/ros/* \
309            $(INSTDIR)/$(ARCH)-ros/sys-include/ros/arch/
310         cp -r $(ROSDIR)/user/parlib/include/* \
311            $(INSTDIR)/$(ARCH)-ros/sys-include/
312         cp -r $(ROSDIR)/user/pthread/*.h \
313            $(INSTDIR)/$(ARCH)-ros/sys-include/
314         rm -rf $(INSTDIR)/$(ARCH)-ros/sys-include/arch
315         ln -s $(ROS_ARCH_DIR) $(INSTDIR)/$(ARCH)-ros/sys-include/arch 
316
317 #################################
318 ###### Dummy Libs Install #######
319 #################################
320 .$(BINARY_PREFIX)dummy-libs-install:
321         rm -rf $(INSTDIR)/$(ARCH)-ros/lib/libparlib.a
322         rm -rf $(INSTDIR)/$(ARCH)-ros/lib/libgcc_eh.a
323         $(ARCH)-ros-ar cr $(INSTDIR)/$(ARCH)-ros/lib/libparlib.a
324         $(ARCH)-ros-ar cr $(INSTDIR)/$(ARCH)-ros/lib/libgcc_eh.a
325
326 #################################
327 ######### Glibc Stage 1 #########
328 #################################
329 .glibc-ros-patch:
330         -cd glibc-$(GLIBC_VERSION); \
331         diff -ruB --unidirectional-new-file \
332              ../glibc-$(GLIBC_VERSION) \
333              ../glibc-$(GLIBC_VERSION)-ros \
334              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
335              | patch -p2 
336
337 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
338         rm -rf glibc-$(GLIBC_VERSION)
339         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
340         $(MAKE) .glibc-ros-patch
341         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
342         rm glibc-$(GLIBC_VERSION)/sysdeps/riscv/elf/start.S
343         rm glibc-$(GLIBC_VERSION)/sysdeps/i386/elf/start.S
344         rm glibc-$(GLIBC_VERSION)/sysdeps/x86_64/elf/start.S
345
346 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
347         rm -rf $@
348         mkdir -p $@
349
350 .$(BINARY_PREFIX)glibc-stage1-configure: 
351         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
352         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
353         ../glibc-$(GLIBC_VERSION)/configure \
354                   --host=$(ARCH)-ros \
355                   --prefix=$(INSTDIR)/$(ARCH)-ros \
356                   --enable-hacker-mode \
357                   --disable-shared \
358               --disable-add-ons \
359                   --disable-nls \
360                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
361                   --with-elf \
362                   --with-tls \
363                   --with-__thread \
364                   $(GLIBC_CONFIGURE_FLAGS) \
365                   CFLAGS="$(ARCH_CFLAGS) -g -fpermissive -O2 -pipe";
366         touch $@
367
368 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
369         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
370         comma=, make -j $(MAKE_JOBS) install-headers install-bootstrap-headers=yes; \
371
372 ####################################
373 ########## Glibc Stage 2  ##########
374 ####################################
375 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
376         rm -rf $@
377         mkdir -p $@
378
379 .$(BINARY_PREFIX)glibc-stage2-configure: 
380         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
381         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
382         ../glibc-$(GLIBC_VERSION)/configure \
383                   --host=$(ARCH)-ros \
384                   --enable-hacker-mode \
385                   --enable-shared \
386                   --disable-nls \
387                   --with-elf \
388                   --with-tls \
389                   --with-__thread \
390                   --with-headers=$(INSTDIR)/$(ARCH)-ros/sys-include \
391                   --prefix=$(INSTDIR)/$(ARCH)-ros \
392                   libc_cv_forced_unwind=yes \
393                   libc_cv_c_cleanup=yes \
394                   $(GLIBC_CONFIGURE_FLAGS) \
395                   CFLAGS="$(ARCH_CFLAGS) -g -fpermissive -O2 -pipe";
396         touch $@
397
398 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
399         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
400         make -j $(MAKE_JOBS) || make -j $(MAKE_JOBS)
401
402 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
403         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
404         make -j $(MAKE_JOBS) install
405
406 #################################
407 ####### ROS Libs Install #######
408 #################################
409 .$(BINARY_PREFIX)ros-libs-install:
410         cd $(ROSDIR); \
411         make ARCH=$(ROS_ARCH_DIR) userclean; \
412         make ARCH=$(ROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
413
414 ##################################
415 ########### Gcc Stage 3 ##########
416 ##################################
417 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
418         rm -rf $@
419         mkdir -p $@
420
421 .$(BINARY_PREFIX)gcc-stage3-configure:
422         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
423         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
424         ../gcc-$(GCC_VERSION)/configure \
425                   --target=$(ARCH)-ros \
426                   --program-prefix=$(BINARY_PREFIX) \
427                   --prefix=$(INSTDIR) \
428                   --disable-nls \
429                   --disable-werror \
430                   --disable-multilib \
431                   --enable-shared \
432                   --enable-tls \
433                   --enable-libgomp \
434                   --enable-languages=c,c++ \
435                   --with-__thread \
436                   --with-headers=$(INSTDIR)/$(ARCH)-ros/include \
437                   $(GCC_BUILD_FLAGS);
438         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
439         touch $@
440
441 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
442         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
443         make -j $(MAKE_JOBS)
444
445 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
446         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
447         make -j $(MAKE_JOBS) install
448
449 clean:
450         rm -rf binutils-$(BINUTILS_VERSION) 
451         rm -rf gcc-$(GCC_VERSION) 
452         rm -rf glibc-$(GLIBC_VERSION) 
453         rm -rf *-builddir
454         rm -rf .*-ros-*-configure
455         rm -rf *$(BINARY_PREFIX)install.bak
456