#!/bin/bash -e
#
# libkissinference - an inference libary for kiss networks
# Copyright (C) 2024 Carl Philipp Klemm <carl@uvos.xyz>
#
# This file is part of libkissinference.
#
# libkissinference is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# libkissinference is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with libkissinference.  If not, see <http://www.gnu.org/licenses/>.
#

PROJECTNAME=@PROJECT_NAME@
SYSTEMPROC=@CMAKE_SYSTEM_PROCESSOR@
ROOTPATH=@CMAKE_FIND_ROOT_PATH@
VERSION="@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@.@CMAKE_PROJECT_VERSION_PATCH@"
BINARYDIR="@CMAKE_CURRENT_BINARY_DIR@"
SRCDIR="@CMAKE_CURRENT_SOURCE_DIR@"
RELDIRECTORY="$BINARYDIR/packaged/$VERSION/release"
ZIPNAME=$PROJECTNAME-$SYSTEMPROC-$VERSION

rm $BINARYDIR/packaged/$ZIPNAME.zip || true
cd $BINARYDIR
install -d $RELDIRECTORY
cp eismultiplexer-qt.exe $RELDIRECTORY
cp $ROOTPATH/bin/libwinpthread-1.dll $RELDIRECTORY
cp $ROOTPATH/bin/libusb-1.0.dll $RELDIRECTORY
cp $ROOTPATH/bin/libssp-0.dll $RELDIRECTORY
cp $ROOTPATH/bin/libgcc_s_seh-1.dll $RELDIRECTORY
cp $ROOTPATH/bin/libstdc++-6.dll $RELDIRECTORY
cp $ROOTPATH/bin/Qt6Core.dll $RELDIRECTORY
cp $ROOTPATH/bin/Qt6Gui.dll $RELDIRECTORY
cp $ROOTPATH/bin/Qt6Widgets.dll $RELDIRECTORY
cp -r $ROOTPATH/lib/qt6/plugins/platforms $RELDIRECTORY
cp -r $ROOTPATH/lib/qt6/plugins/styles $RELDIRECTORY
cp $ROOTPATH/lib/libeismultiplexer.dll $RELDIRECTORY
cp $ROOTPATH/bin/libpcre2-*-0.dll $RELDIRECTORY
cp $ROOTPATH/bin/zlib1.dll $RELDIRECTORY
cp $ROOTPATH/bin/libfreetype-6.dll $RELDIRECTORY
cp $ROOTPATH/bin/libpng16-16.dll $RELDIRECTORY
cp $ROOTPATH/bin/libzstd.dll $RELDIRECTORY
cp $ROOTPATH/bin/libharfbuzz-0.dll $RELDIRECTORY
cp $ROOTPATH/bin/libintl-8.dll $RELDIRECTORY
cp $ROOTPATH/bin/libgraphite2.dll $RELDIRECTORY
cp $ROOTPATH/bin/libglib-2.0-0.dll $RELDIRECTORY
cp $ROOTPATH/bin/libbz2-1.dll $RELDIRECTORY
cp $ROOTPATH/bin/libbrotlidec.dll $RELDIRECTORY
cp $ROOTPATH/bin/libbrotlicommon.dll $RELDIRECTORY
cp $ROOTPATH/bin/libiconv-2.dll $RELDIRECTORY
#cp $SRCDIR/README.md $RELDIRECTORY
cd $RELDIRECTORY/..
rm $BINARYDIR/packaged/$ZIPNAME.zip || true
zip -r $BINARYDIR/packaged/$ZIPNAME.zip release
