#!/bin/sh

. config/options $1

rm -rf $FAKEROOT_SCRIPT   # remove $FAKEROOT_SCRIPT if it exist
touch $FAKEROOT_SCRIPT    # create an empty $FAKEROOT_SCRIPT
chmod +x $FAKEROOT_SCRIPT # make $FAKEROOT_SCRIPT executable

$SCRIPTS/image
$SCRIPTS/build squashfs
$SCRIPTS/build fakeroot

get_version

mkdir -p $TARGET_IMG
  rm -rf $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.kernel
  cp -PR $BUILD/linux-*/arch/x86/boot/bzImage $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.kernel

  echo "rm -rf $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.system" >> $FAKEROOT_SCRIPT
#  echo "$ROOT/$TOOLCHAIN/bin/mksquashfs $BUILD/image/system $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.system -noappend -comp lzma" >> $FAKEROOT_SCRIPT
  echo "$ROOT/$TOOLCHAIN/bin/mksquashfs $BUILD/image/system $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.system -noappend" >> $FAKEROOT_SCRIPT
  $ROOT/$TOOLCHAIN/bin/fakeroot -- $FAKEROOT_SCRIPT
  chmod 0644 $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.system
  rm -rf $FAKEROOT_SCRIPT
