Fix binutils-2.30 port (XCC)
[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.30
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
288 $(BINARY_PREFIX)binutils-builddir: binutils-$(BINUTILS_VERSION)
289         rm -rf $@
290         mkdir -p $@
291
292 native-binutils-configure:
293         cd $(BINARY_PREFIX)binutils-builddir; \
294         CFLAGS="-O2 -g -pipe" \
295         CXXFLAGS="-O2 -g -pipe" \
296         LDFLAGS="" \
297         ../binutils-$(BINUTILS_VERSION)/configure \
298                 --target=$(ARCH)-ucb-akaros \
299                 --host=$(ARCH)-ucb-akaros \
300                 --prefix=$(INSTDIR) \
301                 --disable-werror \
302                 --enable-ld=yes \
303                 --enable-gold=yes \
304                 --enable-plugins=yes \
305                 --with-pkgversion="akaros-repo" \
306                 --disable-multilib \
307                 --disable-nls
308
309 cross-binutils-configure:
310         cd $(BINARY_PREFIX)binutils-builddir; \
311         CFLAGS="-O2 -g -pipe" \
312         CXXFLAGS="-O2 -g -pipe" \
313         LDFLAGS="" \
314         ../binutils-$(BINUTILS_VERSION)/configure \
315                 --target=$(ARCH)-ucb-akaros \
316                 --prefix=$(INSTDIR) \
317                 --disable-werror \
318                 --enable-ld=yes \
319                 --enable-gold=yes \
320                 --enable-plugins=yes \
321                 --with-pkgversion="akaros-repo" \
322                 --disable-multilib \
323                 --disable-nls \
324                 --with-sysroot=$(SYSROOT)
325
326 .$(BINARY_PREFIX)binutils-configure:
327         $(MAKE) $(BINARY_PREFIX)binutils-builddir
328         if [ "$(CONFIG)" = "native" ]; then \
329                 $(MAKE) native-binutils-configure; \
330         else \
331                 $(MAKE) cross-binutils-configure; \
332         fi
333         echo "MAKEINFO = :" >> $(BINARY_PREFIX)binutils-builddir/Makefile;
334         touch $@
335
336 .$(BINARY_PREFIX)binutils-make: .$(BINARY_PREFIX)binutils-configure
337         cd $(BINARY_PREFIX)binutils-builddir; \
338         make -j $(MAKE_JOBS)
339
340 .$(BINARY_PREFIX)binutils-install: .$(BINARY_PREFIX)binutils-make
341         cd $(BINARY_PREFIX)binutils-builddir; \
342         make -j $(MAKE_JOBS) install
343
344 binutils-clean:
345         cd $(BINARY_PREFIX)binutils-builddir; \
346         make clean
347
348 #################################
349 ########## GCC Stage 1 ##########
350 #################################
351 .gcc-akaros-directory-patch:
352         -cd gcc-$(GCC_VERSION); \
353         diff -ruB --unidirectional-new-file \
354              ../gcc-$(GCC_VERSION) \
355              ../gcc-$(GCC_VERSION)-akaros \
356              | grep -v "Only in ../gcc-$(GCC_VERSION)" \
357              > ../.gcc-$(GCC_VERSION)-akaros-directory.patch; \
358              patch -p2 < ../.gcc-$(GCC_VERSION)-akaros-directory.patch
359
360 gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2 \
361                     gmp-$(GMP_VERSION) \
362                     mpfr-$(MPFR_VERSION) \
363                     mpc-$(MPC_VERSION)
364         rm -rf gcc-$(GCC_VERSION)
365         tar -jxf gcc-$(GCC_VERSION).tar.bz2
366         $(MAKE) .gcc-akaros-directory-patch
367         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-r233572.patch
368         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-riscv.patch
369         patch --no-backup-if-mismatch -p0 < gcc-$(GCC_VERSION)-existing.patch
370         (cd gcc-$(GCC_VERSION) && \
371          ln -s ../gmp-$(GMP_VERSION) gmp && \
372          ln -s ../mpfr-$(MPFR_VERSION) mpfr && \
373          ln -s ../mpc-$(MPC_VERSION) mpc)
374
375 $(BINARY_PREFIX)gcc-stage1-builddir: gcc-$(GCC_VERSION)
376         rm -rf $@
377         mkdir -p $@
378
379 .$(BINARY_PREFIX)gcc-stage1-configure:
380         $(MAKE) $(BINARY_PREFIX)gcc-stage1-builddir
381         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
382         CFLAGS="-O2 -g -pipe" \
383         CXXFLAGS="-O2 -g -pipe" \
384         LDFLAGS="-lstdc++ -lm" \
385         ../gcc-$(GCC_VERSION)/configure \
386                 --target=$(ARCH)-ucb-akaros \
387                 --prefix=$(INSTDIR) \
388                 --with-local-prefix=$(SYSROOT) \
389                 --disable-mudflap \
390                 --with-sysroot=$(SYSROOT) \
391                 --with-newlib \
392                 --enable-threads=no \
393                 --enable-tls \
394                 --disable-shared \
395                 --with-pkgversion="akaros-repo" \
396                 --disable-__cxa_atexit \
397                 --with-ppl=no \
398                 --with-isl=no \
399                 --with-cloog=no \
400                 --with-libelf=no \
401                 --disable-lto \
402                 --disable-libgomp \
403                 --disable-mudflap \
404                 --disable-nls \
405                 --disable-multilib \
406                 --enable-languages=c \
407                 --enable-linker-build-id \
408                 $(GCC_BUILD_FLAGS);
409         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage1-builddir/Makefile;
410         touch $@
411
412 .$(BINARY_PREFIX)gcc-stage1-make: .$(BINARY_PREFIX)gcc-stage1-configure
413         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
414         make -j $(MAKE_JOBS) all-gcc;
415
416 .$(BINARY_PREFIX)gcc-stage1-install: .$(BINARY_PREFIX)gcc-stage1-make
417         cd $(BINARY_PREFIX)gcc-stage1-builddir; \
418         make -j $(MAKE_JOBS) install-gcc;
419
420 #################################
421 ########## GCC Stage 2 ##########
422 #################################
423 $(BINARY_PREFIX)gcc-stage2-builddir: gcc-$(GCC_VERSION)
424         rm -rf $@
425         mkdir -p $@
426
427 .$(BINARY_PREFIX)gcc-stage2-configure:
428         $(MAKE) $(BINARY_PREFIX)gcc-stage2-builddir
429         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
430         CFLAGS="-O2 -g -pipe" \
431         CXXFLAGS="-O2 -g -pipe" \
432         LDFLAGS="-lstdc++ -lm" \
433         ../gcc-$(GCC_VERSION)/configure \
434                 --target=$(ARCH)-ucb-akaros \
435                 --prefix=$(INSTDIR) \
436                 --with-local-prefix=$(SYSROOT) \
437                 --disable-mudflap \
438                 --with-sysroot=$(SYSROOT) \
439                 --with-newlib \
440                 --enable-threads=no \
441                 --enable-tls \
442                 --disable-shared \
443                 --with-pkgversion="akaros-repo" \
444                 --disable-__cxa_atexit \
445                 --with-ppl=no \
446                 --with-sil=no \
447                 --with-cloog=no \
448                 --with-libelf=no \
449                 --disable-lto \
450                 --disable-libgomp \
451                 --disable-libmudflap \
452                 --disable-nls \
453                 --enable-languages=c,c++,fortran \
454                 --disable-multilib \
455                 --enable-linker-build-id \
456                 $(GCC_BUILD_FLAGS);
457         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage2-builddir/Makefile;
458         touch $@
459
460 .$(BINARY_PREFIX)gcc-stage2-make: .$(BINARY_PREFIX)gcc-stage2-configure
461         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
462         make -j $(MAKE_JOBS) gcc_cv_libc_provides_ssp=yes \
463                              all-gcc \
464                              all-target-libgcc;
465
466 .$(BINARY_PREFIX)gcc-stage2-install: .$(BINARY_PREFIX)gcc-stage2-make
467         cd $(BINARY_PREFIX)gcc-stage2-builddir; \
468         make -j $(MAKE_JOBS) install-gcc install-target-libgcc;
469
470 #################################
471 ############ Headers ############
472 #################################
473 .$(BINARY_PREFIX)headers-clean:
474         rm -rf $(SYSROOT)/usr/include/*
475
476 .$(BINARY_PREFIX)akaros-headers-install: $(AKAROSDIR)
477         mkdir -p $(SYSROOT)/usr/include
478         rm -rf $(SYSROOT)/usr/include/ros
479         cp -r $(AKAROSDIR)/kern/include/ros \
480             $(SYSROOT)/usr/include/
481         rm -rf $(SYSROOT)/usr/include/ros/arch
482         mkdir -p $(SYSROOT)/usr/include/ros/arch
483         cp -r $(AKAROSDIR)/kern/arch/$(AKAROS_ARCH_DIR)/ros/* \
484             $(SYSROOT)/usr/include/ros/arch/
485         cp -r $(AKAROSDIR)/user/parlib/include/* \
486             $(SYSROOT)/usr/include/
487         cp -r $(AKAROSDIR)/user/pthread/*.h \
488             $(SYSROOT)/usr/include/
489
490 #################################
491 ###### Dummy Libs Install #######
492 #################################
493 .$(BINARY_PREFIX)dummy-libs-install:
494         rm -rf $(SYSROOT)/usr/lib/libparlib.a
495         mkdir -p $(SYSROOT)/usr/lib
496         $(ARCH)-ucb-akaros-ar cr $(SYSROOT)/usr/lib/libparlib.a
497
498 #################################
499 ######### Glibc Stage 1 #########
500 #################################
501 .glibc-akaros-directory-patch:
502         -cd glibc-$(GLIBC_VERSION); \
503         diff -ruB --unidirectional-new-file \
504              ../glibc-$(GLIBC_VERSION) \
505              ../glibc-$(GLIBC_VERSION)-akaros \
506              | grep -v "Only in ../glibc-$(GLIBC_VERSION)" \
507              > ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch; \
508              patch -p2 < ../.glibc-$(GLIBC_VERSION)-akaros-directory.patch
509
510 # On occasion, include/pthread.h was getting installed in stage 2, clobbering
511 # parlib's pthread.h.
512 glibc-$(GLIBC_VERSION): glibc-$(GLIBC_VERSION).tar.bz2
513         rm -rf glibc-$(GLIBC_VERSION)
514         tar -jxf glibc-$(GLIBC_VERSION).tar.bz2
515         rm glibc-$(GLIBC_VERSION)/include/pthread.h
516         $(MAKE) .glibc-akaros-directory-patch
517         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-riscv.patch
518         patch --no-backup-if-mismatch -p0 < glibc-$(GLIBC_VERSION)-existing.patch
519
520 $(BINARY_PREFIX)glibc-stage1-builddir: glibc-$(GLIBC_VERSION)
521         rm -rf $@
522         mkdir -p $@
523
524 .$(BINARY_PREFIX)glibc-stage1-configure:
525         $(MAKE) $(BINARY_PREFIX)glibc-stage1-builddir;
526         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
527         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
528         CXXFLAGS="-fpermissive" \
529         CC=$(ARCH)-ucb-akaros-gcc \
530         AR=$(ARCH)-ucb-akaros-ar \
531         RANLIB=$(ARCH)-ucb-akaros-ranlib \
532         ../glibc-$(GLIBC_VERSION)/configure \
533                 --prefix=/usr \
534                 --host=$(ARCH)-ucb-akaros \
535                 --cache-file=$(BINARY_PREFIX)glibc-stage1-builddir/config.cache \
536                 --without-cvs \
537                 --disable-profile \
538                 --without-gd \
539                 --with-headers=$(SYSROOT)/usr/include \
540                 --disable-debug \
541                 --disable-sanity-checks \
542                 --enable-kernel= \
543                 --with-__thread \
544                 --with-tls \
545                 --without-nptl \
546                 --enable-shared \
547                 --enable-add-ons=no \
548                 --with-pkgversion="akaros-repo" \
549                 --with-elf \
550                 --enable-hacker-mode \
551                 --enable-static-nss \
552                 --enable-obsolete-rpc \
553                 --disable-build-nscd \
554                 --disable-nscd \
555                 $(GLIBC_CONFIGURE_FLAGS);
556         touch $@
557
558 .$(BINARY_PREFIX)glibc-stage1-install: .$(BINARY_PREFIX)glibc-stage1-configure
559         cd $(BINARY_PREFIX)glibc-stage1-builddir; \
560         make -j $(MAKE_JOBS) \
561                 install_root=$(SYSROOT) \
562                 install-bootstrap-headers=yes \
563                 install-headers; \
564         touch $(SYSROOT)/usr/include/gnu/stubs.h; \
565         cp glibc-$(GLIBC_VERSION)/include/features.h $(SYSROOT)/usr/include/features.h; \
566         cp bits/stdio_lim.h $(SYSROOT)/usr/include/bits/stdio_lim.h; \
567         make -j $(MAKE_JOBS) csu/subdir_lib;
568
569 ####################################
570 ########## Glibc Stage 2  ##########
571 ####################################
572 $(BINARY_PREFIX)glibc-stage2-builddir: glibc-$(GLIBC_VERSION)
573         rm -rf $@
574         mkdir -p $@
575
576 .$(BINARY_PREFIX)glibc-stage2-configure:
577         $(MAKE) $(BINARY_PREFIX)glibc-stage2-builddir
578         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
579         CFLAGS="$(ARCH_CFLAGS) -U_FORTIFY_SOURCE -g -O2 -pipe" \
580         CXXFLAGS="-fpermissive" \
581         CC=x86_64-ucb-akaros-gcc \
582         AR=x86_64-ucb-akaros-ar \
583         RANLIB=x86_64-ucb-akaros-ranlib \
584         ../glibc-$(GLIBC_VERSION)/configure \
585                 --prefix=/usr \
586                 --host=$(ARCH)-ucb-akaros \
587                 --cache-file=$(BINARY_PREFIX)glibc-stage2-builddir/config.cache \
588                 --without-cvs \
589                 --disable-profile \
590                 --without-gd \
591                 --with-headers=$(SYSROOT)/usr/include \
592                 --disable-debug \
593                 --disable-sanity-checks \
594                 --enable-kernel= \
595                 --with-__thread \
596                 --with-tls \
597                 --without-nptl \
598                 --enable-shared \
599                 --enable-add-ons=no \
600                 --with-pkgversion="akaros-repo" \
601                 --with-elf \
602                 --enable-hacker-mode \
603                 --enable-static-nss \
604                 --enable-obsolete-rpc \
605                 --disable-build-nscd \
606                 --disable-nscd \
607                 $(GLIBC_CONFIGURE_FLAGS);
608         touch $@
609
610 .$(BINARY_PREFIX)glibc-stage2-make: .$(BINARY_PREFIX)glibc-stage2-configure
611         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
612         make -j $(MAKE_JOBS)
613
614 .$(BINARY_PREFIX)glibc-stage2-install: .$(BINARY_PREFIX)glibc-stage2-make
615         cd $(BINARY_PREFIX)glibc-stage2-builddir; \
616         make -j $(MAKE_JOBS) install_root=$(SYSROOT) install
617
618 ###################################
619 ####### AKAROS Libs Install #######
620 ###################################
621 .$(BINARY_PREFIX)akaros-libs-install:
622         cd $(AKAROSDIR); \
623         make ARCH=$(AKAROS_ARCH_DIR) userclean; \
624         make ARCH=$(AKAROS_ARCH_DIR) -j $(MAKE_JOBS) install-base-libs
625
626 ##################################
627 ########### Gcc Stage 3 ##########
628 ##################################
629 $(BINARY_PREFIX)gcc-stage3-builddir: gcc-$(GCC_VERSION)
630         rm -rf $@
631         mkdir -p $@
632
633 native-gcc-stage3-prep:
634         mkdir -p $(INSTDIR)/usr; \
635
636 native-gcc-stage3-configure: native-gcc-stage3-prep
637         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
638         ../gcc-$(GCC_VERSION)/configure \
639                 --target=$(ARCH)-ucb-akaros \
640                 --host=$(ARCH)-ucb-akaros \
641                 --prefix=$(INSTDIR) \
642                 --with-gmp=$(XCCROOT) \
643                 --with-mpfr=$(XCCROOT) \
644                 --with-mpc=$(XCCROOT) \
645                 --enable-languages=c,c++,fortran \
646                 --with-pkgversion="akaros-repo" \
647                 --disable-__cxa_atexit \
648                 --disable-mudflap \
649                 --enable-libgomp \
650                 --disable-libssp \
651                 --disable-libquadmath \
652                 --disable-libquadmath-support \
653                 --with-ppl=no \
654                 --with-isl=no \
655                 --with-cloog=no \
656                 --with-libelf=no \
657                 --enable-threads=akaros \
658                 --enable-tls \
659                 --disable-nls \
660                 --disable-multilib \
661                 --enable-c99 \
662                 --enable-long-long \
663                 --enable-shared \
664                 --disable-canonical-prefixes \
665                 --disable-canonical-system-headers \
666                 --enable-linker-build-id \
667                 $(GCC_BUILD_FLAGS);
668
669 cross-gcc-stage3-configure:
670         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
671         CFLAGS="-O2 -g -pipe" \
672         CXXFLAGS="-O2 -g -pipe" \
673         LDFLAGS="-lstdc++ -lm" \
674         ../gcc-$(GCC_VERSION)/configure \
675                 --target=$(ARCH)-ucb-akaros \
676                 --prefix=$(INSTDIR) \
677                 --with-sysroot=$(SYSROOT) \
678                 --enable-languages=c,c++,fortran \
679                 --with-pkgversion="akaros-repo" \
680                 --disable-__cxa_atexit \
681                 --disable-mudflap \
682                 --enable-libgomp \
683                 --disable-libssp \
684                 --disable-libquadmath \
685                 --disable-libquadmath-support \
686                 --with-ppl=no \
687                 --with-isl=no \
688                 --with-cloog=no \
689                 --with-libelf=no \
690                 --enable-threads=akaros \
691                 --disable-nls \
692                 --disable-multilib \
693                 --with-local-prefix=$(SYSROOT) \
694                 --enable-c99 \
695                 --enable-long-long \
696                 --enable-shared \
697                 --disable-canonical-prefixes \
698                 --disable-canonical-system-headers \
699                 --enable-linker-build-id \
700                 $(GCC_BUILD_FLAGS);
701
702 .$(BINARY_PREFIX)gcc-stage3-configure:
703         $(MAKE) $(BINARY_PREFIX)gcc-stage3-builddir
704         if [ "$(CONFIG)" = "native" ]; then \
705                 $(MAKE) native-gcc-stage3-configure; \
706         else \
707                 $(MAKE) cross-gcc-stage3-configure; \
708         fi
709         echo "MAKEINFO = :" >> $(BINARY_PREFIX)gcc-stage3-builddir/Makefile;
710         touch $@
711
712 .$(BINARY_PREFIX)gcc-stage3-make: .$(BINARY_PREFIX)gcc-stage3-configure
713         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
714         make -j $(MAKE_JOBS)
715
716 .$(BINARY_PREFIX)gcc-stage3-install: .$(BINARY_PREFIX)gcc-stage3-make
717         cd $(BINARY_PREFIX)gcc-stage3-builddir; \
718         make -j $(MAKE_JOBS) install
719
720 ##################################
721 ######### GMP, MPFR, MPC #########
722 ##################################
723 gmp-$(GMP_VERSION): gmp-$(GMP_VERSION).tar.bz2
724         rm -rf gmp-$(GMP_VERSION)
725         tar -jxf gmp-$(GMP_VERSION).tar.bz2
726         patch -p0 < gmp-$(GMP_VERSION)-akaros.patch
727
728 mpfr-$(MPFR_VERSION): mpfr-$(MPFR_VERSION).tar.bz2
729         rm -rf mpfr-$(MPFR_VERSION)
730         tar -jxf mpfr-$(MPFR_VERSION).tar.bz2
731         patch -p0 < mpfr-$(MPFR_VERSION)-akaros.patch
732
733 mpc-$(MPC_VERSION): mpc-$(MPC_VERSION).tar.gz
734         rm -rf mpc-$(MPC_VERSION)
735         tar -zxf mpc-$(MPC_VERSION).tar.gz
736         patch -p0 < mpc-$(MPC_VERSION)-akaros.patch
737
738 $(BINARY_PREFIX)gmp-builddir: gmp-$(GMP_VERSION)
739         rm -rf $@
740         mkdir -p $@
741
742 $(BINARY_PREFIX)mpfr-builddir: mpfr-$(MPFR_VERSION)
743         rm -rf $@
744         mkdir -p $@
745
746 $(BINARY_PREFIX)mpc-builddir: mpc-$(MPC_VERSION)
747         rm -rf $@
748         mkdir -p $@
749
750 .$(BINARY_PREFIX)gmp-configure:
751         $(MAKE) $(BINARY_PREFIX)gmp-builddir
752         cd $(BINARY_PREFIX)gmp-builddir; \
753         ../gmp-$(GMP_VERSION)/configure \
754             --disable-static \
755             --prefix=$(INSTDIR) \
756             --host=$(ARCH)-ucb-akaros
757         touch $@
758
759 .$(BINARY_PREFIX)mpfr-configure:
760         $(MAKE) $(BINARY_PREFIX)mpfr-builddir
761         cd $(BINARY_PREFIX)mpfr-builddir; \
762         ../mpfr-$(MPFR_VERSION)/configure \
763             --disable-static \
764             --prefix=$(INSTDIR) \
765             --with-gmp=$(INSTDIR) \
766             --host=$(ARCH)-ucb-akaros
767         touch $@
768
769 .$(BINARY_PREFIX)mpc-configure:
770         $(MAKE) $(BINARY_PREFIX)mpc-builddir
771         cd $(BINARY_PREFIX)mpc-builddir; \
772         ../mpc-$(MPC_VERSION)/configure \
773             --disable-static \
774             --prefix=$(INSTDIR) \
775             --with-gmp=$(INSTDIR) \
776             --with-mpfr=$(INSTDIR) \
777             --host=$(ARCH)-ucb-akaros
778         touch $@
779
780 .$(BINARY_PREFIX)gmp-make: .$(BINARY_PREFIX)gmp-configure
781         cd $(BINARY_PREFIX)gmp-builddir; \
782         make -j $(MAKE_JOBS)
783
784 .$(BINARY_PREFIX)mpfr-make: .$(BINARY_PREFIX)mpfr-configure
785         cd $(BINARY_PREFIX)mpfr-builddir; \
786         make -j $(MAKE_JOBS)
787
788 .$(BINARY_PREFIX)mpc-make: .$(BINARY_PREFIX)mpc-configure
789         cd $(BINARY_PREFIX)mpc-builddir; \
790         make -j $(MAKE_JOBS)
791
792 .$(BINARY_PREFIX)gmp-install: .$(BINARY_PREFIX)gmp-make
793         cd $(BINARY_PREFIX)gmp-builddir; \
794         make -j $(MAKE_JOBS) install
795
796 .$(BINARY_PREFIX)mpfr-install: .$(BINARY_PREFIX)mpfr-make
797         cd $(BINARY_PREFIX)mpfr-builddir; \
798         make -j $(MAKE_JOBS) install
799
800 .$(BINARY_PREFIX)mpc-install: .$(BINARY_PREFIX)mpc-make
801         cd $(BINARY_PREFIX)mpc-builddir; \
802         make -j $(MAKE_JOBS) install
803
804 endif # BUILD_ERROR
805 endif # AKAROS_COMPILER_REAL_BUILD