# Contributor: GunsNRose <zlbgps AT gmail.com>>
_gitname=tools
_gitroot=' https://github.com/olegk0/tools.git'
pkgname=rk${_gitname}-git
pkgver=20130929
pkgrel=1
pkgdesc="rockchip utils tool"
arch=('i686' 'x86_64')
url="http://linux-rockchip.info/mw/index.php?title=Building_Kernel_for_Linux_Distribution"
license=('GPL')
#depends=('python')
makedepends=('git')
provides=(rk${_gitname})
install=rk${_gitname}.install
build() {
  cd "$srcdir"
  if [ ! -d "$srcdir/${_gitname}" ] ; then
      git clone --depth=1 ${_gitroot}
  else
      cd "$srcdir/${_gitname}" || return 1
      git pull
  fi
  if [  -d "$srcdir/${_gitname}-build" ] ; then
      rm -rf "$srcdir/${_gitname}-build"
  fi
  if [ ! -d "$srcdir/${_gitname}-build" ] ; then
      cp -a "$srcdir/${_gitname}" "$srcdir"/${_gitname}-build || return 1
  fi
  cd "$srcdir"/${_gitname}-build
  mkdir libmincrypt
  touch libmincrypt/libmincrypt.a
  echo "all:libmincrypt.a" > libmincrypt/Makefile
  make
}
package() {
  cd "$srcdir"/${_gitname}-build
  #make DESTDIR=${pkgdir} install
  install -d -m755 ${pkgdir}/usr/bin
  install -Dm755 mkbootimg ${pkgdir}/usr/bin/mkbootimg
  install -Dm755 unpackbootimg ${pkgdir}/usr/bin/unpackbootimg
  #rkdir=${pkgdir}/opt/rockchip/rktools
  #install -d -m755 ${rkdir}
  echo "./mkbootimg --kernel Image --ramdisk ramdisk.gz --base 60400000 --pagesize 16384 --ramdiskaddr 62000000 -o recovery.img"
  echo "mkbootimg --kernel rk3x_kernel_3.0.36/arch/arm/boot/Image --ramdisk initramfs/fakeramdisk.gz --base 60400000 --pagesize 16384 --ramdiskaddr 62000000 -o recovery.img"
}
post_install() {
  echo "./mkbootimg --kernel Image --ramdisk ramdisk.gz --base 60400000 --pagesize 16384 --ramdiskaddr 62000000 -o recovery.img"
  echo "mkbootimg --kernel rk3x_kernel_3.0.36/arch/arm/boot/Image --ramdisk initramfs/fakeramdisk.gz --base 60400000 --pagesize 16384 --ramdiskaddr 62000000 -o recovery.img"
}
post_upgrade() {
    post_install
}