Reduce verbosity of some make commands
[akaros.git] / tools / compilers / gcc-glibc / Makefile
1 # Number of make jobs to spawn.  Define it in Makelocal
2 MAKE_JOBS ?= $(shell expr `cat /proc/cpuinfo | grep processor | wc -l` - 1)
3
4 BINUTILS_VERSION := 2.24
5 GCC_VERSION := 4.9.2
6 GLIBC_VERSION := 2.19
7 GMP_VERSION := 5.1.3
8 MPFR_VERSION := 3.1.2
9 MPC_VERSION := 1.0.2
10
11 # Defines where to install the toolchain
12 -include Makelocal
13
14 define print-usage
15         @echo "Usage: make <arch> [ <config> ] [ <subcmd> ] "
16         @echo "    Valid archs are: 'x86_64', 'riscv'"
17         @echo "    Valid configs are: 'cross', 'native'"
18         @echo "    Valid subcommands are: 'build', 'uninstall', check-env' 'install-headers'"
19         @echo "    If no config is specified, the 'cross' config is assumed by default."
20         @echo "    If no subcommand is specified, the 'build' subcommand is assumed by default."
21         @echo ""
22         @echo "Additional pseudo targets exist for:"
23         @echo "    make clean"
24         @echo "        Cleanup the build environment"
25         @echo "    make inst-clean"
26         @echo "        Cleanup the build environment and uninstall all compilers for all archs."
27 endef
28
29 # Make sure the list of targets is sane!
30 ifndef AKAROS_COMPILER_REAL_BUILD
31 VALID_ARCHS := x86_64 riscv
32 VALID_CONFIGS := cross native
33 VALID_SUBCMDS := build uninstall check-env install-headers
34 VALID_CLEANS := clean inst-clean
35 VALID_TARGETS := $(VALID_ARCHS) $(VALID_CONFIGS) \
36                  $(VALID_SUBCMDS) $(VALID_CLEANS)
37 ARCH := $(filter $(VALID_ARCHS),$(MAKECMDGOALS))
38 CONFIG := $(filter $(VALID_CONFIGS),$(MAKECMDGOALS))
39 SUBCMDS := $(filter $(VALID_SUBCMDS),$(MAKECMDGOALS))
40 CLEANS := $(filter $(VALID_CLEANS),$(MAKECMDGOALS))
41 INVALID_TARGETS := $(filter-out $(VALID_TARGETS),$(MAKECMDGOALS))
42 NONCLEANGOALS := $(filter-out $(CLEANS),$(MAKECMDGOALS))
43 ifeq ($(words $(CONFIG)),0)
44     CONFIG := cross
45 endif
46 ifeq ($(words $(SUBCMDS)),0)
47     SUBCMDS := build
48 endif
49
50 .PHONY: $(VALID_TARGETS)
51
52 OK_TO_BUILD :=
53 ifeq ($(words $(ARCH)),1)
54     ifeq ($(words $(CONFIG)),1)
55         ifeq ($(INVALID_TARGETS),)
56             OK_TO_BUILD := 1
57         endif
58     endif
59 endif
60 ifeq ($(OK_TO_BUILD),)
61 all $(NONCLEANGOALS): make-real
62         @echo "" > /dev/null
63 make-real:
64         $(print-usage)
65 else
66 all $(NONCLEANGOALS): make-real
67         @echo "" > /dev/null
68 make-real:
69         @export AKAROS_COMPILER_REAL_BUILD=true; \
70          export ARCH=$(ARCH); \
71          export CONFIG=$(CONFIG); \
72          $(MAKE) --no-print-directory $(patsubst %, %-real, $(SUBCMDS))
73 endif
74
75 clean:
76         @rm -rf binutils-$(BINUTILS_VERSION)
77         @rm -rf gcc-$(GCC_VERSION)
78         @rm -rf glibc-$(GLIBC_VERSION)
79         @rm -rf gmp-$(GMP_VERSION)
80         @rm -rf mpfr-$(MPFR_VERSION)
81         @rm -rf mpc-$(MPC_VERSION)
82         @rm -rf *-builddir
83         @rm -rf .*-configure
84         @rm -rf .glibc-$(GLIBC_VERSION)-akaros.patch
85         @rm -rf .gcc-$(GCC_VERSION)-akaros.patch
86         @echo "    Removed configs, build dirs, and extracted sources"
87
88 inst-clean: clean
89         @for a in $(VALID_ARCHS); do \
90                 for c in $(VALID_CONFIGS); do \
91                         $(MAKE) --no-print-directory $$a $$c uninstall; \
92                 done \
93         done
94
95 else # AKAROS_COMPILER_REAL_BUILD
96
97 # Set up some global variables to help us through the make based on the
98 # platform we are building for.
99 ifeq ($(ARCH),x86_64)
100     AKAROS_ARCH_DIR := x86
101     ARCH_CFLAGS :=
102     GLIBC_CONFIGURE_FLAGS := "--disable-multi-arch"
103     GCC_BUILD_FLAGS := CFLAGS="-fPIC"
104 endif
105 ifeq ($(ARCH),riscv)
106     AKAROS_ARCH_DIR := riscv
107     ARCH_CFLAGS :=
108     GLIBC_CONFIGURE_FLAGS :=
109     GCC_BUILD_FLAGS :=
110 endif
111 ifeq ($(CONFIG),cross)
112     INSTDIR_STRING := $(shell echo $(ARCH) | tr 'a-z' 'A-Z')_INSTDIR
113 else
114     INSTDIR_STRING := $(shell echo $(ARCH) | tr 'a-z' 'A-Z')_NATIVE_INSTDIR
115     XCCROOT := $(shell dirname $(shell which $(ARCH)-ucb-akaros-gcc) 2>/dev/null)/..
116 endif
117 BUILDDIR ?= $(shell pwd)/
118 AKAROSDIR ?= $(BUILDDIR)/../../../
119 INSTDIR := $($(INSTDIR_STRING))
120 BINARY_PREFIX := $(ARCH)-ucb-akaros-
121 SYSROOT := $(INSTDIR)/$(ARCH)-ucb-akaros/sysroot
122 PATH := /$(INSTDIR)/bin:$(PATH)
123
124 BUILD_ERRORS :=
125 BUILD_ERROR_DELIMITER := <\#\#>
126 define add_error
127 $(BUILD_ERRORS)$(1)$(BUILD_ERROR_DELIMITER)
128 endef
129
130 # Check for additional errors before building
131 AWK := $(shell awk -W version 2>&1 | head -n 1 | awk '{print $$1}')
132 ifneq ($(AWK),GNU)
133 define BUILD_ERROR
134     You need to have 'gawk' installed on your system before proceeding!"
135 endef
136 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
137 endif
138
139 GPPEXISTS := $(shell which g++ > /dev/null 2>&1 ; echo $$?)
140 ifneq ($(GPPEXISTS),0)
141 define BUILD_ERROR
142     You need to have 'g++' installed on your system before proceeding!"
143 endef
144 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
145 endif
146
147 FLEXEXISTS := $(shell which flex > /dev/null 2>&1 ; echo $$?)
148 ifneq ($(FLEXEXISTS),0)
149 define BUILD_ERROR
150     You need to have 'flex' installed on your system before proceeding!"
151 endef
152 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
153 endif
154
155 BISONEXISTS := $(shell which bison > /dev/null 2>&1 ; echo $$?)
156 ifneq ($(BISONEXISTS),0)
157 define BUILD_ERROR
158     You need to have 'bison' installed on your system before proceeding!"
159 endef
160 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
161 endif
162
163 ifeq ($(INSTDIR),)
164 define BUILD_ERROR
165     You need to setup $(INSTDIR_STRING), to point to where you
166     want your compiler installed. The best way to do this is to create
167     a 'Makelocal' file in the current directory and put a definition
168     for this variable in there.
169 endef
170 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
171 endif
172
173 ifeq ($(CONFIG),native)
174 ifeq ($(shell which $(ARCH)-ucb-akaros-gcc 2>/dev/null),)
175 define BUILD_ERROR
176     No $(ARCH) Akaros cross-compiler installed in path. Make sure you have
177     built and installed the $(ARCH) cross-compiler using 'make $(ARCH)'
178     before trying to build the crossed-native compiler.
179 endef
180 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
181 endif
182 endif
183 ifeq ($(ARCH),riscv)
184 ifeq ($(shell grep "CONFIG_RISCV=y" $(AKAROSDIR)/.config),)
185 define BUILD_ERROR
186     Akaros tree not configured for $(ARCH)
187     Make sure you have configured AKAROSDIR for this architecture before proceeding
188     e.g. cd $$AKAROSDIR
189          make ARCH=riscv defconfig
190 endef
191 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
192 endif
193 endif
194
195 ifeq ($(ARCH),x86_64)
196 ifeq ($(shell grep "CONFIG_X86_64=y" $(AKAROSDIR)/.config),)
197 define BUILD_ERROR
198     Akaros tree not configured for x86_64
199     Make sure you have configured AKAROSDIR for this architecture before proceeding
200     e.g. cd $$AKAROSDIR
201          make ARCH=x86 defconfig
202          make ARCH=x86 menuconfig -> Set 64 bit option
203 endef
204 BUILD_ERRORS := $(call add_error, $(BUILD_ERROR))
205 endif
206 endif
207
208 ROBUST_SUBCMDS := uninstall
209 ifeq ($(filter-out $(patsubst %, %-real, $(ROBUST_SUBCMDS)), $(MAKECMDGOALS)),)
210     BUILD_ERRORS :=
211 endif
212
213 ifdef BUILD_ERRORS
214
215 export BUILD_ERRORS
216 $(MAKECMDGOALS): make-real
217         @echo "" > /dev/null
218 make-real:
219         @echo "$${BUILD_ERRORS}" |\
220         awk '\
221                 BEGIN { RS="$(BUILD_ERROR_DELIMITER)"; FS="$(BUILD_ERROR_DELIMITER)"; }\
222                 { str[NR] = $$i; }\
223                 END { for (i = 1; i < NR; i++) {\
224                                 print "Error Detected:";\
225                                 print substr(str[i], 2); }}\
226         '
227         @exit 2
228
229 else # BUILD_ERROR
230
231 # Make sure that LD_LIBRARY_PATH is not set during the build process
232 unexport LD_LIBRARY_PATH
233
234 check-env-real:
235         @echo "    Your environment checks out. Build away!"
236
237 define make_and_log
238         $(MAKE) $(1) > build_logs/$(2).log 2>&1
239         @echo "make $(2) succeeded"
240 endef
241
242 ifeq ($(CONFIG),cross)
243 build-real:
244         $(shell mkdir -p build_logs)
245         $(call make_and_log,.$(BINARY_PREFIX)binutils-install,$(BINARY_PREFIX)binutils-install)
246         $(call make_and_log,.$(BINARY_PREFIX)gcc-stage1-install,$(BINARY_PREFIX)gcc-stage1-install)
247         $(call make_and_log,.$(BINARY_PREFIX)headers-clean,$(BINARY_PREFIX)headers-clean)
248         $(call make_and_log,.$(BINARY_PREFIX)akaros-headers-install,$(BINARY_PREFIX)akaros-headers-install)
249         $(call make_and_log,.$(BINARY_PREFIX)dummy-libs-install,$(BINARY_PREFIX)dummy-libs-install)
250         $(call make_and_log,.$(BINARY_PREFIX)glibc-stage1-install,$(BINARY_PREFIX)glibc-stage1-install)
251         $(call make_and_log,.$(BINARY_PREFIX)gcc-stage2-install,$(BINARY_PREFIX)gcc-stage2-install)
252         $(call make_and_log,.$(BINARY_PREFIX)glibc-stage2-install,$(BINARY_PREFIX)glibc-stage2-install)
253         $(call make_and_log,.$(BINARY_PREFIX)akaros-libs-install,$(BINARY_PREFIX)akaros-libs-install)
254         $(call make_and_log,.$(BINARY_PREFIX)gcc-stage3-install,$(BINARY_PREFIX)gcc-stage3-install)
255         $(call make_and_log,.$(BINARY_PREFIX)gmp-install,$(BINARY_PREFIX)gmp-install)
256         $(call make_and_log,.$(BINARY_PREFIX)mpfr-install,$(BINARY_PREFIX)mpfr-install)
257         $(call make_and_log,.$(BINARY_PREFIX)mpc-install,$(BINARY_PREFIX)mpc-install)
258 else
259 build-real:
260         $(shell mkdir -p build_logs)
261         $(call make_and_log,.$(BINARY_PREFIX)binutils-install,$(BINARY_PREFIX)binutils-install)
262         $(call make_and_log,.$(BINARY_PREFIX)gcc-stage3-install,$(BINARY_PREFIX)gcc-stage3-install)
263 endif
264
265 uninstall-real:
266         @dir=$(INSTDIR);\
267         if [ "$${dir}" != "" ]; then\
268                 rm -rf $${dir};\
269                 echo "    Removed $${dir} ($(ARCH)-$(CONFIG)-inst)";\
270         fi
271
272 install-headers-real: .$(BINARY_PREFIX)akaros-headers-install
273
274 %.tar.bz2:
275         wget http://akaros.cs.berkeley.edu/xcc/$@
276
277 %.tar.gz:
278         wget http://akaros.cs.berkeley.edu/xcc/$@
279
280 #################################
281 ########### BINUTILS ############
282 #################################
283 binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
284         rm -rf binutils-$(BINUTILS_VERSION);
285         tar -jxf binutils-$(BINUTILS_VERSION).tar.bz2
286         patch -p0 < binutils-$(BINUTILS_VERSION)-akaros.patch
287         patch --no-backup-if-mismatch -p0 < binutils-$(BINUTILS_VERSION)-riscv.patch
288
289 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
290         rm -rf $@
291         mkdir -p $@
292
293 native-binutils-configure:
294         cd $(BINARY_PREFIX)binutils-builddir; \
295         CFLAGS="-O2 -g -pipe" \
296         CXXFLAGS="-O2 -g -pipe" \
297         LDFLAGS="" \
298         ../binutils-$(BINUTILS_VERSION)/configure \
299                 --target=$(ARCH)-ucb-akaros \
300                 --host=$(ARCH)-ucb-akaros \
301                 --prefix=$(INSTDIR) \
302                 --disable-werror \
303                 --enable-ld=yes \
304                 --enable-gold=yes \
305                 --enable-plugins=yes \
306                 --with-pkgversion="akaros-repo" \
307                 --disable-multilib \
308                 --disable-nls
309
310 cross-binutils-configure:
311         cd $(BINARY_PREFIX)binutils-builddir; \
312         CFLAGS="-O2 -g -pipe" \
313         CXXFLAGS="-O2 -g -pipe" \
314         LDFLAGS="" \
315         ../binutils-$(BINUTILS_VERSION)/configure \
316                 --target=$(ARCH)-ucb-akaros \
317                 --prefix=$(INSTDIR) \
318                 --disable-werror \
319                 --enable-ld=yes \
320                 --enable-gold=yes \
321                 --enable-plugins=yes \
322                 --with-pkgversion="akaros-repo" \
323                 --disable-multilib \
324                 --disable-nls \
325                 --with-sysroot=$(SYSROOT)
326
327 .$(BINARY_PREFIX)binutils-configure:
328         $(MAKE) $(BINARY_PREFIX)binutils-builddir
329         if [ "$(CONFIG)" = "native" ]; then \
330                 $(MAKE) native-binutils-configure; \
331         else \
332                 $(MAKE) cross-binutils-configure; \
333         fi
334         echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
335         touch $@
336
337 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
338         cd $(BINARY_PREFIX)binutils-builddir; \
339         make -j $(MAKE_JOBS)
340
341 .$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
342         cd $(BINARY_PREFIX)binutils-builddir; \
343         make -j $(MAKE_JOBS) install
344
345 binutils-clean:
346         cd $(BINARY_PREFIX)binutils-builddir; \
347         make clean
348
349 #################################
350 ########## GCC Stage 1 ##########
351 #################################
352 .gcc-akaros-directory-patch:
353         -cd gcc-$(GCC_VERSION); \
354         diff -ruB --unidirectional-new-file \
355              ../gcc-$(GCC_VERSION) \
356              ../gcc-$(GCC_VERSION)-akaros \
357              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
358              > ../.gcc-$(GCC_VERSION)-akaros-directory.patch; \
359              patch -p2 < ../.gcc-$(GCC_VERSION)-akaros-directory.patch
360
361 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2 \
362                     gmp-$(GMP_VERSION) \
363                     mpfr-$(MPFR_VERSION) \
364                     mpc-$(MPC_VERSION)
365         rm -rf gcc-$(GCC_VERSION)
366         tar -jxf gcc-$(GCC_VERSION).tar.bz2
367         $(MAKE) .gcc-akaros-directory-patch
368         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-r233572.patch
369         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
370         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-existing.patch
371         (cd gcc-$(GCC_VERSION) && \
372          ln -s ../gmp-$(GMP_VERSION) gmp && \
373          ln -s ../mpfr-$(MPFR_VERSION) mpfr && \
374          ln -s ../mpc-$(MPC_VERSION) mpc)
375
376 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
377         rm -rf $@
378         mkdir -p $@
379
380 .$(BINARY_PREFIX)gcc-stage1-configure:
381         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
382         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
383         CFLAGS="-O2 -g -pipe" \
384         CXXFLAGS="-O2 -g -pipe" \
385         LDFLAGS="-lstdc++ -lm" \
386         ../gcc-$(GCC_VERSION)/configure \
387                 --target=$(ARCH)-ucb-akaros \
388                 --prefix=$(INSTDIR) \
389                 --with-local-prefix=$(SYSROOT) \
390                 --disable-mudflap \
391                 --with-sysroot=$(SYSROOT) \
392                 --with-newlib \
393                 --enable-threads=no \
394                 --enable-tls \
395                 --disable-shared \
396                 --with-pkgversion="akaros-repo" \
397                 --disable-__cxa_atexit \
398                 --with-ppl=no \
399                 --with-isl=no \
400                 --with-cloog=no \
401                 --with-libelf=no \
402                 --disable-lto \
403                 --disable-libgomp \
404                 --disable-mudflap \
405                 --disable-nls \
406                 --disable-multilib \
407                 --enable-languages=c \
408                 --enable-linker-build-id \
409                 $(GCC_BUILD_FLAGS);
410         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
411         touch $@
412
413 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
414         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
415         make -j $(MAKE_JOBS) all-gcc;
416
417 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
418         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
419         make -j $(MAKE_JOBS) install-gcc;
420
421 #################################
422 ########## GCC Stage 2 ##########
423 #################################
424 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
425         rm -rf $@
426         mkdir -p $@
427
428 .$(BINARY_PREFIX)gcc-stage2-configure:
429         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
430         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
431         CFLAGS="-O2 -g -pipe" \
432         CXXFLAGS="-O2 -g -pipe" \
433         LDFLAGS="-lstdc++ -lm" \
434         ../gcc-$(GCC_VERSION)/configure \
435                 --target=$(ARCH)-ucb-akaros \
436                 --prefix=$(INSTDIR) \
437                 --with-local-prefix=$(SYSROOT) \
438                 --disable-mudflap \
439                 --with-sysroot=$(SYSROOT) \
440                 --with-newlib \
441                 --enable-threads=no \
442                 --enable-tls \
443                 --disable-shared \
444                 --with-pkgversion="akaros-repo" \
445                 --disable-__cxa_atexit \
446                 --with-ppl=no \
447                 --with-sil=no \
448                 --with-cloog=no \
449                 --with-libelf=no \
450                 --disable-lto \
451                 --disable-libgomp \
452                 --disable-libmudflap \
453                 --disable-nls \
454                 --enable-languages=c,c++,fortran \
455                 --disable-multilib \
456                 --enable-linker-build-id \
457                 $(GCC_BUILD_FLAGS);
458         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
459         touch $@
460
461 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
462         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
463         make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
464                              all-gcc \
465                              all-target-libgcc;
466
467 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
468         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
469         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
470
471 #################################
472 ############ Headers ############
473 #################################
474 .$(BINARY_PREFIX)headers-clean:
475         rm -rf $(SYSROOT)/usr/include/*
476
477 .$(BINARY_PREFIX)akaros-headers-install: $(AKAROSDIR)
478         mkdir -p $(SYSROOT)/usr/include
479         rm -rf $(SYSROOT)/usr/include/ros
480         cp -r $(AKAROSDIR)/kern/include/ros \
481             $(SYSROOT)/usr/include/
482         rm -rf $(SYSROOT)/usr/include/ros/arch
483         mkdir -p $(SYSROOT)/usr/include/ros/arch
484         cp -r $(AKAROSDIR)/kern/arch/$(AKAROS_ARCH_DIR)/ros/* \
485             $(SYSROOT)/usr/include/ros/arch/
486         cp -r $(AKAROSDIR)/user/parlib/include/* \
487             $(SYSROOT)/usr/include/
488         cp -r $(AKAROSDIR)/user/pthread/*.h \
489             $(SYSROOT)/usr/include/
490
491 #################################
492 ###### Dummy Libs Install #######
493 #################################
494 .$(BINARY_PREFIX)dummy-libs-install:
495         rm -rf $(SYSROOT)/usr/lib/libparlib.a
496         mkdir -p $(SYSROOT)/usr/lib
497         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
498
499 #################################
500 ######### Glibc Stage 1 #########
501 #################################
502 .glibc-akaros-directory-patch:
503         -cd glibc-$(GLIBC_VERSION); \
504         diff -ruB --unidirectional-new-file \
505              ../glibc-$(GLIBC_VERSION) \
506              ../glibc-$(GLIBC_VERSION)-akaros \
507              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
508              > ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch; \
509              patch -p2 < ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch
510
511 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
512 # parlib's pthread.h.
513 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
514         rm -rf glibc-$(GLIBC_VERSION)
515         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
516         rm glibc-$(GLIBC_VERSION)/include/pthread.h
517         $(MAKE) .glibc-akaros-directory-patch
518         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
519         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-existing.patch
520
521 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
522         rm -rf $@
523         mkdir -p $@
524
525 .$(BINARY_PREFIX)glibc-stage1-configure:
526         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
527         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
528         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
529         CXXFLAGS="-fpermissive" \
530         CC=$(ARCH)-ucb-akaros-gcc \
531         AR=$(ARCH)-ucb-akaros-ar \
532         RANLIB=$(ARCH)-ucb-akaros-ranlib \
533         ../glibc-$(GLIBC_VERSION)/configure \
534                 --prefix=/usr \
535                 --host=$(ARCH)-ucb-akaros \
536                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
537                 --without-cvs \
538                 --disable-profile \
539                 --without-gd \
540                 --with-headers=$(SYSROOT)/usr/include \
541                 --disable-debug \
542                 --disable-sanity-checks \
543                 --enable-kernel= \
544                 --with-__thread \
545                 --with-tls \
546                 --without-nptl \
547                 --enable-shared \
548                 --enable-add-ons=no \
549                 --with-pkgversion="akaros-repo" \
550                 --with-elf \
551                 --enable-hacker-mode \
552                 --enable-static-nss \
553                 --enable-obsolete-rpc \
554                 --disable-build-nscd \
555                 --disable-nscd \
556                 $(GLIBC_CONFIGURE_FLAGS);
557         touch $@
558
559 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
560         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
561         make -j $(MAKE_JOBS) \
562                 install_root=$(SYSROOT) \
563                 install-bootstrap-headers=yes \
564                 install-headers; \
565         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
566         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
567         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
568         make -j $(MAKE_JOBS) csu/subdir_lib;
569
570 ####################################
571 ########## Glibc Stage 2  ##########
572 ####################################
573 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
574         rm -rf $@
575         mkdir -p $@
576
577 .$(BINARY_PREFIX)glibc-stage2-configure:
578         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
579         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
580         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
581         CXXFLAGS="-fpermissive" \
582         CC=x86_64-ucb-akaros-gcc \
583         AR=x86_64-ucb-akaros-ar \
584         RANLIB=x86_64-ucb-akaros-ranlib \
585         ../glibc-$(GLIBC_VERSION)/configure \
586                 --prefix=/usr \
587                 --host=$(ARCH)-ucb-akaros \
588                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
589                 --without-cvs \
590                 --disable-profile \
591                 --without-gd \
592                 --with-headers=$(SYSROOT)/usr/include \
593                 --disable-debug \
594                 --disable-sanity-checks \
595                 --enable-kernel= \
596                 --with-__thread \
597                 --with-tls \
598                 --without-nptl \
599                 --enable-shared \
600                 --enable-add-ons=no \
601                 --with-pkgversion="akaros-repo" \
602                 --with-elf \
603                 --enable-hacker-mode \
604                 --enable-static-nss \
605                 --enable-obsolete-rpc \
606                 --disable-build-nscd \
607                 --disable-nscd \
608                 $(GLIBC_CONFIGURE_FLAGS);
609         touch $@
610
611 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
612         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
613         make -j $(MAKE_JOBS)
614
615 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
616         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
617         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
618
619 ###################################
620 ####### AKAROS Libs Install #######
621 ###################################
622 .$(BINARY_PREFIX)akaros-libs-install:
623         cd $(AKAROSDIR); \
624         make ARCH=$(AKAROS_ARCH_DIR) userclean; \
625         make ARCH=$(AKAROS_ARCH_DIR) -j $(MAKE_JOBS) install-base-libs
626
627 ##################################
628 ########### Gcc Stage 3 ##########
629 ##################################
630 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
631         rm -rf $@
632         mkdir -p $@
633
634 native-gcc-stage3-prep:
635         mkdir -p $(INSTDIR)/usr; \
636
637 native-gcc-stage3-configure: native-gcc-stage3-prep
638         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
639         ../gcc-$(GCC_VERSION)/configure \
640                 --target=$(ARCH)-ucb-akaros \
641                 --host=$(ARCH)-ucb-akaros \
642                 --prefix=$(INSTDIR) \
643                 --with-gmp=$(XCCROOT) \
644                 --with-mpfr=$(XCCROOT) \
645                 --with-mpc=$(XCCROOT) \
646                 --enable-languages=c,c++,fortran \
647                 --with-pkgversion="akaros-repo" \
648                 --disable-__cxa_atexit \
649                 --disable-mudflap \
650                 --enable-libgomp \
651                 --disable-libssp \
652                 --disable-libquadmath \
653                 --disable-libquadmath-support \
654                 --with-ppl=no \
655                 --with-isl=no \
656                 --with-cloog=no \
657                 --with-libelf=no \
658                 --enable-threads=akaros \
659                 --enable-tls \
660                 --disable-nls \
661                 --disable-multilib \
662                 --enable-c99 \
663                 --enable-long-long \
664                 --enable-shared \
665                 --disable-canonical-prefixes \
666                 --disable-canonical-system-headers \
667                 --enable-linker-build-id \
668                 $(GCC_BUILD_FLAGS);
669
670 cross-gcc-stage3-configure:
671         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
672         CFLAGS="-O2 -g -pipe" \
673         CXXFLAGS="-O2 -g -pipe" \
674         LDFLAGS="-lstdc++ -lm" \
675         ../gcc-$(GCC_VERSION)/configure \
676                 --target=$(ARCH)-ucb-akaros \
677                 --prefix=$(INSTDIR) \
678                 --with-sysroot=$(SYSROOT) \
679                 --enable-languages=c,c++,fortran \
680                 --with-pkgversion="akaros-repo" \
681                 --disable-__cxa_atexit \
682                 --disable-mudflap \
683                 --enable-libgomp \
684                 --disable-libssp \
685                 --disable-libquadmath \
686                 --disable-libquadmath-support \
687                 --with-ppl=no \
688                 --with-isl=no \
689                 --with-cloog=no \
690                 --with-libelf=no \
691                 --enable-threads=akaros \
692                 --disable-nls \
693                 --disable-multilib \
694                 --with-local-prefix=$(SYSROOT) \
695                 --enable-c99 \
696                 --enable-long-long \
697                 --enable-shared \
698                 --disable-canonical-prefixes \
699                 --disable-canonical-system-headers \
700                 --enable-linker-build-id \
701                 $(GCC_BUILD_FLAGS);
702
703 .$(BINARY_PREFIX)gcc-stage3-configure:
704         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
705         if [ "$(CONFIG)" = "native" ]; then \
706                 $(MAKE) native-gcc-stage3-configure; \
707         else \
708                 $(MAKE) cross-gcc-stage3-configure; \
709         fi
710         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
711         touch $@
712
713 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
714         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
715         make -j $(MAKE_JOBS)
716
717 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
718         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
719         make -j $(MAKE_JOBS) install
720
721 ##################################
722 ######### GMP, MPFR, MPC #########
723 ##################################
724 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
725         rm -rf gmp-$(GMP_VERSION)
726         tar -jxf gmp-$(GMP_VERSION).tar.bz2
727         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
728
729 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
730         rm -rf mpfr-$(MPFR_VERSION)
731         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
732         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
733
734 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
735         rm -rf mpc-$(MPC_VERSION)
736         tar -zxf mpc-$(MPC_VERSION).tar.gz
737         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
738
739 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
740         rm -rf $@
741         mkdir -p $@
742
743 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
744         rm -rf $@
745         mkdir -p $@
746
747 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
748         rm -rf $@
749         mkdir -p $@
750
751 .$(BINARY_PREFIX)gmp-configure:
752         $(MAKE) $(BINARY_PREFIX)gmp-builddir
753         cd $(BINARY_PREFIX)gmp-builddir; \
754         ../gmp-$(GMP_VERSION)/configure \
755             --disable-static \
756             --prefix=$(INSTDIR) \
757             --host=$(ARCH)-ucb-akaros
758         touch $@
759
760 .$(BINARY_PREFIX)mpfr-configure:
761         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
762         cd $(BINARY_PREFIX)mpfr-builddir; \
763         ../mpfr-$(MPFR_VERSION)/configure \
764             --disable-static \
765             --prefix=$(INSTDIR) \
766             --with-gmp=$(INSTDIR) \
767             --host=$(ARCH)-ucb-akaros
768         touch $@
769
770 .$(BINARY_PREFIX)mpc-configure:
771         $(MAKE) $(BINARY_PREFIX)mpc-builddir
772         cd $(BINARY_PREFIX)mpc-builddir; \
773         ../mpc-$(MPC_VERSION)/configure \
774             --disable-static \
775             --prefix=$(INSTDIR) \
776             --with-gmp=$(INSTDIR) \
777             --with-mpfr=$(INSTDIR) \
778             --host=$(ARCH)-ucb-akaros
779         touch $@
780
781 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
782         cd $(BINARY_PREFIX)gmp-builddir; \
783         make -j $(MAKE_JOBS)
784
785 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
786         cd $(BINARY_PREFIX)mpfr-builddir; \
787         make -j $(MAKE_JOBS)
788
789 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
790         cd $(BINARY_PREFIX)mpc-builddir; \
791         make -j $(MAKE_JOBS)
792
793 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
794         cd $(BINARY_PREFIX)gmp-builddir; \
795         make -j $(MAKE_JOBS) install
796
797 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
798         cd $(BINARY_PREFIX)mpfr-builddir; \
799         make -j $(MAKE_JOBS) install
800
801 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
802         cd $(BINARY_PREFIX)mpc-builddir; \
803         make -j $(MAKE_JOBS) install
804
805 endif # BUILD_ERROR
806 endif # AKAROS_COMPILER_REAL_BUILD