#!/bin/sh

. config/options

KLIBC_ARCH=$TARGET_ARCH
[ $TARGET_ARCH = powerpc ] && KLIBC_ARCH=ppc

do_klibc () {
  if [ "$1" = build ]; then
    target=all
  elif [ "$1" = install ]; then
    rm -rf .install
    mkdir .install
    target=install
  else
    return 1
  fi

  make $target \
    V=1 \
    ARCH=$KLIBC_ARCH \
    HOSTCC="$HOST_CC" \
    CROSS_COMPILE="${TARGET_PREFIX}"\
    KLIBCKERNELSRC="$(kernel_path)" \
    INSTALLROOT=.install
}

cd $BUILD/$1*
do_klibc build
do_klibc install
