#!/bin/sh

dir=$(dirname $0)

olddir=$(pwd)
cd $dir
git pull origin master

echo -e "\nCompiling and Stripping"
./build -static -no-pie || exit 1

echo -e "\nPackaging"
folder="oppai-$(./oppai -version)-"
folder="${folder}$(gcc -dumpmachine)"

mkdir -p "$folder"
mv ./oppai $folder/oppai
git archive HEAD --prefix=src/ -o "$folder"/src.tar
cd "$folder"
tar xf src.tar
cd ..

rm "$folder".tar.xz
tar -cvJf "$folder".tar.xz \
    "$folder"/oppai \
    "$folder"/src

echo -e "\nResult:"
tar tf "$folder".tar.xz

readelf --dynamic "$folder"/oppai
ldd "$folder"/oppai

rm -rf "$folder"
cd $olddir

