Toolchain target: make inst-clean
[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 X86_64_INSTDIR
9 ifndef X86_64_NATIVE_INSTDIR
10 busted: 
11         @echo "You need to setup either a RISCV_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 x86_64: busted
14 x86_64-native: 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 BINUTILS_VERSION := 2.24
27 GCC_VERSION := 4.9.2
28 GLIBC_VERSION := 2.19
29 GMP_VERSION := 5.1.3
30 MPFR_VERSION := 3.1.2
31 MPC_VERSION := 1.0.2
32
33 BUILDDIR ?= $(shell pwd)/
34 ROSDIR ?= $(BUILDDIR)/../../../
35 DESTDIR ?= /
36
37 # Configuration parameters for make-riscv
38 RISCV_ARCH := riscv
39 RISCV_BINARY_PREFIX := $(RISCV_ARCH)-ucb-akaros-
40 RISCV_SYSROOT := $(RISCV_INSTDIR)/$(RISCV_ARCH)-ucb-akaros/sysroot
41 RISCV_GLIBC_CONFIGURE_FLAGS := 
42 RISCV_GCC_BUILD_FLAGS := 
43 RISCV_CFLAGS :=
44
45 # Configuration parameters for x86_64
46 X86_64_ARCH := x86_64
47 X86_64_BINARY_PREFIX := $(X86_64_ARCH)-ucb-akaros-
48 X86_64_SYSROOT := $(X86_64_INSTDIR)/$(X86_64_ARCH)-ucb-akaros/sysroot
49 X86_64_GLIBC_CONFIGURE_FLAGS := "--disable-multi-arch"
50 X86_64_GCC_BUILD_FLAGS := CFLAGS="-fPIC"
51 X86_64_CFLAGS :=
52
53 # Configuration parameters for x86_64-native
54 X86_64_NATIVE_ARCH := x86_64
55 X86_64_NATIVE_BINARY_PREFIX := 
56 X86_64_NATIVE_SYSROOT := $(X86_64_NATIVE_INSTDIR)
57 X86_64_NATIVE_GCC_BUILD_FLAGS := CFLAGS="-fPIC"
58 X86_64_NATIVE_CFLAGS :=
59
60 #If actually building the cross compiler, make sure that the akaros tree is
61 #properly configured for the architecture we are creating the cross compiler
62 #for.
63 ifneq (,$(filter riscv,$(MAKECMDGOALS)))
64 ifeq (,$(shell grep "CONFIG_RISCV=y" $(ROSDIR)/.config))
65 error: 
66         @echo "Akaros tree not configured for riscv"
67         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
68         @echo "e.g. cd \$$ROSDIR"
69         @echo "     make ARCH=riscv defconfig"
70         @false
71 riscv: error
72 endif
73 endif
74 ifneq (,$(filter x86_64,$(MAKECMDGOALS)))
75 ifeq (,$(shell grep "CONFIG_X86_64=y" $(ROSDIR)/.config))
76 error: 
77         @echo "Akaros tree not configured for x86_64"
78         @echo "Make sure you have configured ROSDIR for this architecture before proceeding"
79         @echo "e.g. cd \$$ROSDIR"
80         @echo "     make ARCH=x86 defconfig"
81         @echo "     make ARCH=x86 menuconfig -> Set 64 bit option"
82         @false
83 x86_64: error
84 endif
85 endif
86 ifneq (,$(filter x86_64-native,$(MAKECMDGOALS)))
87 ifeq (,$(shell which x86_64-ucb-akaros-gcc))
88 error: 
89         @echo "No x86_64 Akaros cross-compiler installed in path"
90         @echo "Make sure you have built and installed the x86_64 cross-compiler using 'make x86_64'
91         @echo "before trying to build the crossed-native compiler.
92         @false
93 x86_64: error
94 endif
95 endif
96
97 all:
98         @echo "You need to run one of the following commands, "
99         @echo "depending on which version of the cross compiler you are trying to generate:"
100         @echo "  make riscv"
101         @echo "  make x86_64"
102         @echo "  make x86-64-native"
103         @echo "  make riscv-revert"
104         @echo "  make x86_64-revert"
105         @echo "  make x86_64-native-revert"
106         @echo "  make riscv-uninstall"
107         @echo "  make x86_64-uninstall"
108         @echo "  make x86_64-native-uninstall"
109         @echo "  make clean"
110         @echo "  make inst-clean"
111
112 riscv:
113         export LD_LIBRARY_PATH=; \
114         export DESTDIR=$(DESTDIR);\
115         export INSTDIR=$(RISCV_INSTDIR);\
116         export SYSROOT=$(RISCV_SYSROOT);\
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 x86_64:
127         export LD_LIBRARY_PATH=; \
128         export DESTDIR=$(DESTDIR);\
129         export INSTDIR=$(X86_64_INSTDIR);\
130         export SYSROOT=$(X86_64_SYSROOT);\
131         export PATH=$(DESTDIR)$(X86_64_INSTDIR)/bin:$(PATH);\
132         export ARCH=$(X86_64_ARCH);\
133         export ARCH_CFLAGS=$(X86_64_CFLAGS);\
134         export ROS_ARCH_DIR=x86;\
135         export BINARY_PREFIX=$(X86_64_BINARY_PREFIX);\
136         export GLIBC_CONFIGURE_FLAGS=$(X86_64_GLIBC_CONFIGURE_FLAGS);\
137         export GCC_BUILD_FLAGS=$(X86_64_GCC_BUILD_FLAGS);\
138         $(MAKE) make-all
139
140 x86_64-native:
141         export NATIVE_BUILD=true; \
142         export LD_LIBRARY_PATH=; \
143         export DESTDIR=$(DESTDIR);\
144         export INSTDIR=$(X86_64_NATIVE_INSTDIR);\
145         export SYSROOT=$(X86_64_NATIVE_SYSROOT);\
146         export ARCH=$(X86_64_NATIVE_ARCH);\
147         export BINARY_PREFIX=$(X86_64_NATIVE_BINARY_PREFIX);\
148         export GCC_BUILD_FLAGS=$(X86_64_NATIVE_GCC_BUILD_FLAGS);\
149         export CXXROOT=$(shell dirname $(shell which $(X86_64_NATIVE_ARCH)-ucb-akaros-gcc))/..; \
150         $(MAKE) make-native-all
151
152 make-all: 
153         $(MAKE) .$(BINARY_PREFIX)binutils-install
154         $(MAKE) .$(BINARY_PREFIX)gcc-stage1-install
155         $(MAKE) .$(BINARY_PREFIX)akaros-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)akaros-libs-install
161         $(MAKE) .$(BINARY_PREFIX)gcc-stage3-install
162         $(MAKE) .$(BINARY_PREFIX)gmp-install
163         $(MAKE) .$(BINARY_PREFIX)mpfr-install
164         $(MAKE) .$(BINARY_PREFIX)mpc-install
165
166 make-native-all:
167         $(MAKE) .$(BINARY_PREFIX)binutils-install
168         $(MAKE) .$(BINARY_PREFIX)gcc-stage3-install
169
170 riscv-uninstall:
171         @rm -rf $(RISCV_INSTDIR)
172         @echo "Removed $(RISCV_INSTDIR) (riscv-inst)"
173
174 x86_64-uninstall:
175         @rm -rf $(X86_64_INSTDIR)
176         @echo "Removed $(X86_64_INSTDIR) (x86_64-inst)"
177
178 x86_64-native-uninstall:
179         @rm -rf $(X86_64_NATIVE_INSTDIR)
180         @echo "Removed $(X86_64_NATIVE_INSTDIR) (x86_64-native-inst)"
181
182 riscv-revert:
183         rm -rf $(RISCV_INSTDIR)
184         cp -r $(RISCV_BINARY_PREFIX)install.bak $(RISCV_INSTDIR)
185
186 x86_64-revert: 
187         rm -rf $(X86_64_INSTDIR)
188         cp -r $(X86_64_BINARY_PREFIX)install.bak $(X86_64_INSTDIR)
189
190 x86_64-native-revert: 
191         rm -rf $(X86_64_NATIVE_INSTDIR)
192         cp -r $(X86_64_NATIVE_BINARY_PREFIX)install.bak $(X86_64_NATIVE_INSTDIR)
193
194 %.tar.bz2:
195         wget http://akaros.cs.berkeley.edu/xcc/$@
196
197 %.tar.gz:
198         wget http://akaros.cs.berkeley.edu/xcc/$@
199
200 #################################
201 ########### BINUTILS ############
202 #################################
203 binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
204         rm -rf binutils-$(BINUTILS_VERSION);
205         tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
206         patch -p0 < binutils-$(BINUTILS_VERSION)-akaros.patch
207         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
208
209 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
210         rm -rf $@
211         mkdir -p $@
212
213 native-binutils-configure:
214         cd $(BINARY_PREFIX)binutils-builddir; \
215         CFLAGS="-O2 -g -pipe" \
216         CXXFLAGS="-O2 -g -pipe" \
217         LDFLAGS="" \
218         ../binutils-$(BINUTILS_VERSION)/configure \
219                 --target=$(ARCH)-ucb-akaros \
220                 --host=$(ARCH)-ucb-akaros \
221                 --prefix=$(INSTDIR) \
222                 --disable-werror \
223                 --enable-ld=yes \
224                 --enable-gold=yes \
225                 --enable-plugins=yes \
226                 --with-pkgversion="akaros-repo" \
227                 --disable-multilib \
228                 --disable-nls
229
230 cross-binutils-configure:
231         cd $(BINARY_PREFIX)binutils-builddir; \
232         CFLAGS="-O2 -g -pipe" \
233         CXXFLAGS="-O2 -g -pipe" \
234         LDFLAGS="" \
235         ../binutils-$(BINUTILS_VERSION)/configure \
236                 --target=$(ARCH)-ucb-akaros \
237                 --prefix=$(INSTDIR) \
238                 --disable-werror \
239                 --enable-ld=yes \
240                 --enable-gold=yes \
241                 --enable-plugins=yes \
242                 --with-pkgversion="akaros-repo" \
243                 --disable-multilib \
244                 --disable-nls \
245                 --with-sysroot=$(SYSROOT)
246
247 .$(BINARY_PREFIX)binutils-configure: 
248         $(MAKE) $(BINARY_PREFIX)binutils-builddir 
249         if [ "$(NATIVE_BUILD)" = "true" ]; then \
250                 $(MAKE) native-binutils-configure; \
251         else \
252                 $(MAKE) cross-binutils-configure; \
253         fi
254         echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
255         touch $@
256
257 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
258         cd $(BINARY_PREFIX)binutils-builddir; \
259         make -j $(MAKE_JOBS)
260
261 .$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
262         cd $(BINARY_PREFIX)binutils-builddir; \
263         make -j $(MAKE_JOBS) install
264
265 binutils-clean:
266         cd $(BINARY_PREFIX)binutils-builddir; \
267         make clean
268
269 #################################
270 ########## GCC Stage 1 ##########
271 #################################
272 .gcc-akaros-patch:
273         -cd gcc-$(GCC_VERSION); \
274         diff -ruB --unidirectional-new-file \
275              ../gcc-$(GCC_VERSION) \
276              ../gcc-$(GCC_VERSION)-akaros \
277              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
278              > ../.gcc-$(GCC_VERSION)-akaros.patch; \
279              patch -p2 < ../.gcc-$(GCC_VERSION)-akaros.patch
280
281 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2 \
282                     gmp-$(GMP_VERSION) \
283                     mpfr-$(MPFR_VERSION) \
284                     mpc-$(MPC_VERSION)
285         rm -rf gcc-$(GCC_VERSION)
286         tar -jxf gcc-$(GCC_VERSION).tar.bz2
287         $(MAKE) .gcc-akaros-patch
288         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
289         (cd gcc-$(GCC_VERSION) && \
290          ln -s ../gmp-$(GMP_VERSION) gmp && \
291          ln -s ../mpfr-$(MPFR_VERSION) mpfr && \
292          ln -s ../mpc-$(MPC_VERSION) mpc)
293
294 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
295         rm -rf $@
296         mkdir -p $@
297
298 .$(BINARY_PREFIX)gcc-stage1-configure: 
299         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
300         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
301         CFLAGS="-O2 -g -pipe" \
302         CXXFLAGS="-O2 -g -pipe" \
303         LDFLAGS="-lstdc++ -lm" \
304         ../gcc-$(GCC_VERSION)/configure \
305                 --target=$(ARCH)-ucb-akaros \
306                 --prefix=$(INSTDIR) \
307                 --with-local-prefix=$(SYSROOT) \
308                 --disable-mudflap \
309                 --with-sysroot=$(SYSROOT) \
310                 --with-newlib \
311                 --enable-threads=no \
312                 --enable-tls \
313                 --disable-shared \
314                 --with-pkgversion="akaros-repo" \
315                 --disable-__cxa_atexit \
316                 --with-ppl=no \
317                 --with-isl=no \
318                 --with-cloog=no \
319                 --with-libelf=no \
320                 --disable-lto \
321                 --disable-libgomp \
322                 --disable-mudflap \
323                 --disable-nls \
324                 --disable-multilib \
325                 --enable-languages=c \
326                 $(GCC_BUILD_FLAGS);
327         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
328         touch $@
329
330 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
331         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
332         make -j $(MAKE_JOBS) all-gcc;
333
334 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
335         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
336         make -j $(MAKE_JOBS) install-gcc;
337
338 #################################
339 ########## GCC Stage 2 ##########
340 #################################
341 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
342         rm -rf $@
343         mkdir -p $@
344
345 .$(BINARY_PREFIX)gcc-stage2-configure: 
346         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
347         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
348         CFLAGS="-O2 -g -pipe" \
349         CXXFLAGS="-O2 -g -pipe" \
350         LDFLAGS="-lstdc++ -lm" \
351         ../gcc-$(GCC_VERSION)/configure \
352                 --target=$(ARCH)-ucb-akaros \
353                 --prefix=$(INSTDIR) \
354                 --with-local-prefix=$(SYSROOT) \
355                 --disable-mudflap \
356                 --with-sysroot=$(SYSROOT) \
357                 --with-newlib \
358                 --enable-threads=no \
359                 --enable-tls \
360                 --disable-shared \
361                 --with-pkgversion="akaros-repo" \
362                 --disable-__cxa_atexit \
363                 --with-ppl=no \
364                 --with-sil=no \
365                 --with-cloog=no \
366                 --with-libelf=no \
367                 --disable-lto \
368                 --disable-libgomp \
369                 --disable-libmudflap \
370                 --disable-nls \
371                 --enable-languages=c,c++,fortran \
372                 --disable-multilib \
373                 $(GCC_BUILD_FLAGS);
374         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
375         touch $@
376
377 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
378         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
379         make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
380                              all-gcc \
381                              all-target-libgcc;
382
383 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
384         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
385         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
386
387 ####################################
388 ######### AKAROS Headers ###########
389 ####################################
390 .$(BINARY_PREFIX)akaros-headers-install: $(ROSDIR)
391         rm -rf $(SYSROOT)/usr/include/*
392         mkdir -p $(SYSROOT)/usr/include
393         cp -r $(ROSDIR)/kern/include/ros \
394             $(SYSROOT)/usr/include/
395         rm -f $(SYSROOT)/usr/include/ros/arch
396         mkdir $(SYSROOT)/usr/include/ros/arch
397         cp -r $(ROSDIR)/kern/arch/$(ROS_ARCH_DIR)/ros/* \
398             $(SYSROOT)/usr/include/ros/arch/
399         cp -r $(ROSDIR)/user/parlib/include/* \
400             $(SYSROOT)/usr/include/
401         cp -r $(ROSDIR)/user/pthread/*.h \
402             $(SYSROOT)/usr/include/
403         rm -rf $(SYSROOT)/usr/include/arch
404         ln -s $(ROS_ARCH_DIR) $(SYSROOT)/usr/include/arch
405
406 #################################
407 ###### Dummy Libs Install #######
408 #################################
409 .$(BINARY_PREFIX)dummy-libs-install:
410         rm -rf $(SYSROOT)/usr/lib/libparlib.a
411         mkdir -p $(SYSROOT)/usr/lib
412         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
413
414 #################################
415 ######### Glibc Stage 1 #########
416 #################################
417 .glibc-akaros-patch:
418         -cd glibc-$(GLIBC_VERSION); \
419         diff -ruB --unidirectional-new-file \
420              ../glibc-$(GLIBC_VERSION) \
421              ../glibc-$(GLIBC_VERSION)-akaros \
422              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
423              > ../.glibc-$(GLIBC_VERSION)-akaros.patch; \
424              patch -p2 < ../.glibc-$(GLIBC_VERSION)-akaros.patch
425
426 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
427 # parlib's pthread.h.
428 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
429         rm -rf glibc-$(GLIBC_VERSION)
430         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
431         rm glibc-$(GLIBC_VERSION)/include/pthread.h
432         $(MAKE) .glibc-akaros-patch
433         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
434
435 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
436         rm -rf $@
437         mkdir -p $@
438
439 .$(BINARY_PREFIX)glibc-stage1-configure: 
440         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
441         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
442         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
443         CXXFLAGS="-fpermissive" \
444         CC=$(ARCH)-ucb-akaros-gcc \
445         AR=$(ARCH)-ucb-akaros-ar \
446         RANLIB=$(ARCH)-ucb-akaros-ranlib \
447         ../glibc-$(GLIBC_VERSION)/configure \
448                 --prefix=/usr \
449                 --host=$(ARCH)-ucb-akaros \
450                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
451                 --without-cvs \
452                 --disable-profile \
453                 --without-gd \
454                 --with-headers=$(SYSROOT)/usr/include \
455                 --disable-debug \
456                 --disable-sanity-checks \
457                 --enable-kernel= \
458                 --with-__thread \
459                 --with-tls \
460                 --without-nptl \
461                 --enable-shared \
462                 --enable-add-ons=no \
463                 --with-pkgversion="akaros-repo" \
464                 --with-elf \
465                 --enable-hacker-mode \
466                 --enable-static-nss \
467                 --enable-obsolete-rpc \
468                 --disable-build-nscd \
469                 --disable-nscd \
470                 $(GLIBC_CONFIGURE_FLAGS);
471         touch $@
472
473 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
474         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
475         make -j $(MAKE_JOBS) \
476                 install_root=$(SYSROOT) \
477                 install-bootstrap-headers=yes \
478                 install-headers; \
479         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
480         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
481         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
482         make -j $(MAKE_JOBS) csu/subdir_lib;
483
484 ####################################
485 ########## Glibc Stage 2  ##########
486 ####################################
487 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
488         rm -rf $@
489         mkdir -p $@
490
491 .$(BINARY_PREFIX)glibc-stage2-configure: 
492         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
493         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
494         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
495         CXXFLAGS="-fpermissive" \
496         CC=x86_64-ucb-akaros-gcc \
497         AR=x86_64-ucb-akaros-ar \
498         RANLIB=x86_64-ucb-akaros-ranlib \
499         ../glibc-$(GLIBC_VERSION)/configure \
500                 --prefix=/usr \
501                 --host=$(ARCH)-ucb-akaros \
502                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
503                 --without-cvs \
504                 --disable-profile \
505                 --without-gd \
506                 --with-headers=$(SYSROOT)/usr/include \
507                 --disable-debug \
508                 --disable-sanity-checks \
509                 --enable-kernel= \
510                 --with-__thread \
511                 --with-tls \
512                 --without-nptl \
513                 --enable-shared \
514                 --enable-add-ons=no \
515                 --with-pkgversion="akaros-repo" \
516                 --with-elf \
517                 --enable-hacker-mode \
518                 --enable-static-nss \
519                 --enable-obsolete-rpc \
520                 --disable-build-nscd \
521                 --disable-nscd \
522                 $(GLIBC_CONFIGURE_FLAGS);
523         touch $@
524
525 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
526         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
527         make -j $(MAKE_JOBS)
528
529 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
530         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
531         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
532
533 ###################################
534 ####### AKAROS Libs Install #######
535 ###################################
536 .$(BINARY_PREFIX)akaros-libs-install:
537         cd $(ROSDIR); \
538         make ARCH=$(ROS_ARCH_DIR) userclean; \
539         make ARCH=$(ROS_ARCH_DIR) -j $(MAKE_JOBS) install-libs
540
541 ##################################
542 ########### Gcc Stage 3 ##########
543 ##################################
544 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
545         rm -rf $@
546         mkdir -p $@
547
548 native-gcc-stage3-prep:
549         mkdir -p $(INSTDIR)/usr; \
550
551 native-gcc-stage3-configure: native-gcc-stage3-prep
552         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
553         ../gcc-$(GCC_VERSION)/configure \
554                 --target=$(ARCH)-ucb-akaros \
555                 --host=$(ARCH)-ucb-akaros \
556                 --prefix=$(INSTDIR) \
557                 --with-gmp=$(CXXROOT) \
558                 --with-mpfr=$(CXXROOT) \
559                 --with-mpc=$(CXXROOT) \
560                 --enable-languages=c,c++,fortran \
561                 --with-pkgversion="akaros-repo" \
562                 --disable-__cxa_atexit \
563                 --disable-mudflap \
564                 --enable-libgomp \
565                 --disable-libssp \
566                 --disable-libquadmath \
567                 --disable-libquadmath-support \
568                 --with-ppl=no \
569                 --with-isl=no \
570                 --with-cloog=no \
571                 --with-libelf=no \
572                 --enable-threads=no \
573                 --enable-tls \
574                 --disable-nls \
575                 --disable-multilib \
576                 --enable-c99 \
577                 --enable-long-long \
578                 --enable-shared \
579                 $(GCC_BUILD_FLAGS);
580
581 cross-gcc-stage3-configure:
582         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
583         CFLAGS="-O2 -g -pipe" \
584         CXXFLAGS="-O2 -g -pipe" \
585         LDFLAGS="-lstdc++ -lm" \
586         ../gcc-$(GCC_VERSION)/configure \
587                 --target=$(ARCH)-ucb-akaros \
588                 --prefix=$(INSTDIR) \
589                 --with-sysroot=$(SYSROOT) \
590                 --enable-languages=c,c++,fortran \
591                 --with-pkgversion="akaros-repo" \
592                 --disable-__cxa_atexit \
593                 --disable-mudflap \
594                 --enable-libgomp \
595                 --disable-libssp \
596                 --disable-libquadmath \
597                 --disable-libquadmath-support \
598                 --with-ppl=no \
599                 --with-isl=no \
600                 --with-cloog=no \
601                 --with-libelf=no \
602                 --enable-threads=no \
603                 --disable-nls \
604                 --disable-multilib \
605                 --with-local-prefix=$(SYSROOT) \
606                 --enable-c99 \
607                 --enable-long-long \
608                 --enable-shared \
609                 $(GCC_BUILD_FLAGS);
610
611 .$(BINARY_PREFIX)gcc-stage3-configure:
612         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
613         if [ "$(NATIVE_BUILD)" = "true" ]; then \
614                 $(MAKE) native-gcc-stage3-configure; \
615         else \
616                 $(MAKE) cross-gcc-stage3-configure; \
617         fi
618         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
619         touch $@
620
621 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
622         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
623         make -j $(MAKE_JOBS)
624
625 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
626         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
627         make -j $(MAKE_JOBS) install
628
629 ##################################
630 ######### GMP, MPFR, MPC #########
631 ##################################
632 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
633         rm -rf gmp-$(GMP_VERSION)
634         tar -jxf gmp-$(GMP_VERSION).tar.bz2
635         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
636
637 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
638         rm -rf mpfr-$(MPFR_VERSION)
639         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
640         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
641
642 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
643         rm -rf mpc-$(MPC_VERSION)
644         tar -zxf mpc-$(MPC_VERSION).tar.gz
645         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
646
647 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
648         rm -rf $@
649         mkdir -p $@
650
651 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
652         rm -rf $@
653         mkdir -p $@
654
655 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
656         rm -rf $@
657         mkdir -p $@
658
659 .$(BINARY_PREFIX)gmp-configure:
660         $(MAKE) $(BINARY_PREFIX)gmp-builddir
661         cd $(BINARY_PREFIX)gmp-builddir; \
662         ../gmp-$(GMP_VERSION)/configure \
663             --disable-static \
664             --prefix=$(INSTDIR) \
665             --host=$(ARCH)-ucb-akaros
666         touch $@
667
668 .$(BINARY_PREFIX)mpfr-configure:
669         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
670         cd $(BINARY_PREFIX)mpfr-builddir; \
671         ../mpfr-$(MPFR_VERSION)/configure \
672             --disable-static \
673             --prefix=$(INSTDIR) \
674             --with-gmp=$(INSTDIR) \
675             --host=$(ARCH)-ucb-akaros
676         touch $@
677
678 .$(BINARY_PREFIX)mpc-configure:
679         $(MAKE) $(BINARY_PREFIX)mpc-builddir
680         cd $(BINARY_PREFIX)mpc-builddir; \
681         ../mpc-$(MPC_VERSION)/configure \
682             --disable-static \
683             --prefix=$(INSTDIR) \
684             --with-gmp=$(INSTDIR) \
685             --with-mpfr=$(INSTDIR) \
686             --host=$(ARCH)-ucb-akaros
687         touch $@
688
689 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
690         cd $(BINARY_PREFIX)gmp-builddir; \
691         make -j $(MAKE_JOBS)
692
693 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
694         cd $(BINARY_PREFIX)mpfr-builddir; \
695         make -j $(MAKE_JOBS)
696
697 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
698         cd $(BINARY_PREFIX)mpc-builddir; \
699         make -j $(MAKE_JOBS)
700
701 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
702         cd $(BINARY_PREFIX)gmp-builddir; \
703         make -j $(MAKE_JOBS) install
704
705 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
706         cd $(BINARY_PREFIX)mpfr-builddir; \
707         make -j $(MAKE_JOBS) install
708
709 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
710         cd $(BINARY_PREFIX)mpc-builddir; \
711         make -j $(MAKE_JOBS) install
712
713 ##################################
714 ######## Clean it all up! ########
715 ##################################
716 clean:
717         @rm -rf binutils-$(BINUTILS_VERSION)
718         @rm -rf gcc-$(GCC_VERSION)
719         @rm -rf glibc-$(GLIBC_VERSION)
720         @rm -rf gmp-$(GMP_VERSION)
721         @rm -rf mpfr-$(MPFR_VERSION)
722         @rm -rf mpc-$(MPC_VERSION)
723         @rm -rf *-builddir
724         @rm -rf .*-configure
725         @rm -rf *$(BINARY_PREFIX)install.bak
726         @rm -rf .glibc-$(GLIBC_VERSION)-akaros.patch
727         @rm -rf .gcc-$(GCC_VERSION)-akaros.patch
728         @echo "Removed configs, build dirs, and extracted sources"
729
730 inst-clean: clean riscv-uninstall x86_64-uninstall x86_64-native-uninstall