#!/bin/sh

# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)

echo "getting sources..."
  if [ ! -d libretro-ppsspp.git ]; then
    git clone --depth=1 https://github.com/hrydgard/ppsspp libretro-ppsspp.git
    cd libretro-ppsspp.git
      git submodule init
      git submodule deinit -f ffmpeg
      git submodule deinit -f dx9sdk
      git submodule deinit -f pspautotests
      git submodule update
      cd ..
  fi

  cd libretro-ppsspp.git
    git pull
    GIT_REV=`git log -n1 --format=%H`
  cd ..

echo "copying sources..."
  rm -rf libretro-ppsspp-$GIT_REV
  cp -R libretro-ppsspp.git libretro-ppsspp-$GIT_REV

echo "cleaning sources..."
  rm -rf libretro-ppsspp-$GIT_REV/.git

echo "packing sources..."
  tar cvJf libretro-ppsspp-$GIT_REV.tar.xz libretro-ppsspp-$GIT_REV
  echo "SHA256: $(sha256sum libretro-ppsspp-$GIT_REV.tar.xz)"

echo "remove temporary sourcedir..."
  rm -rf libretro-ppsspp-$GIT_REV
