#!/bin/bash

if [ x"$1" == "xuboot" ] || [ x"$1" == "xu" ] || [ x"$1" == "x" ] ;then
  echo "Start build uboot"
	cd longan/brandy/brandy-2.0 && ./build.sh -p sun50iw10p1 && cd -
  if [ $? -eq 0 ]; then
    echo "Build uboot ok!"
  else
    echo "Build uboot failed!"
    exit 1
  fi
fi

if [ x"$1" == "xkernel" ] || [ x"$1" == "xk" ] || [ x"$1" == "x" ] ;then
  echo "Start build kernel"
	cd longan && ./build.sh autoconfig -o android -i a133 -b c3 && ./build.sh && cd -
  if [ $? -eq 0 ]; then
    echo "Build kernel ok!"
  else
    echo "Build kernel failed!"
    exit 1
  fi
fi

# android envsetup
cd android
. ./build/envsetup.sh
lunch ceres_c3-userdebug
extract-bsp
cd -

if [ x"$1" == "xandroid" ] || [ x"$1" == "xa" ] || [ x"$1" == "x" ] ;then	
  echo "Start build Android"
  cd android
	make installclean
	make BUILD_NUMBER=ido-a133 -j32
  cd -
fi

# pack image
echo "Start pack image"
cd android
pack
cd -


