#!/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-linux-$SYSTEMPROC-$VERSION
LIBUSB_PATH=$(readlink -f $(ldconfig -p | grep libusb-1.0.so.0 | tr ' ' '\n' | grep / | grep -v 32))

rm $BINARYDIR/packaged/$ZIPNAME.zip || true
cd $BINARYDIR
install -d $RELDIRECTORY
cp libeismultiplexer.so $RELDIRECTORY
cp libeismultiplexer_static.a $RELDIRECTORY
cp $LIBUSB_PATH $RELDIRECTORY/libusb-1.0.so.0
cp eismultiplexer_cli $RELDIRECTORY
mkdir $RELDIRECTORY/include || true
cp $SRCDIR/eismultiplexer.h $RELDIRECTORY/include
cp $SRCDIR/gpl-3.0.txt $SRCDIR/lgpl-3.0.txt $RELDIRECTORY
cp $SRCDIR/README.md $RELDIRECTORY
cd $RELDIRECTORY/..
rm $BINARYDIR/packaged/$ZIPNAME.zip || true
zip -r $BINARYDIR/packaged/$ZIPNAME.zip release
