#!/bin/sh

. config/options

$SCRIPTS/build toolchain
$SCRIPTS/unpack busybox

# busybox fails to compile using the gold linker
  CFLAGS=`echo $CFLAGS | sed -e "s|-fuse-linker-plugin||" -e "s|-fuse-ld=gold||"`
  LDFLAGS=`echo $LDFLAGS | sed -e "s|-fuse-linker-plugin||" -e "s|-fuse-ld=gold||"`

PKG_DIR=`find $PACKAGES -type d -name $1`

if [ -f $PROJECT_DIR/$PROJECT/busybox/$1.conf ]; then
  BUSYBOX_CFG_FILE=$PROJECT_DIR/$PROJECT/busybox/$1.conf
else
  BUSYBOX_CFG_FILE=$ROOT/$PKG_DIR/config/$1.conf
fi

cd $BUILD/busybox*

# Build Busybox for initramfs
  make distclean
  cp $BUSYBOX_CFG_FILE .config
  make oldconfig

  ARCH=$TARGET_ARCH make install
