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