#!/bin/bash

set -eux

build_tarball() {
    for dir in vppinfra dpdk svm vlib-api vlib vnet vpp vpp-api-test
    do
        tar -C install-$1/$dir/include -cf - . | tar -C $tmp_dir/include -xf -
    done
    tar -C ../sample-plugin -cf - . \
       | tar -C $tmp_dir/src/sample-plugin -xf -
    cp tools/bin/vppapigen $tmp_dir/tools/bin
    echo Created by `id -u -n` on `hostname` at `date` >		\
		$tmp_dir/toolkit-version-stamp
    cp scripts/vpp-plugin-toolkit-readme $tmp_dir/README
    tar -C $tmp_dir -zcf $PWD/vpp-plugin-toolkit-$1.tar.gz .
}

if [ `basename $PWD` != "build-root" ] ; then
   echo Please run this script from build-root
   exit 1
fi   

echo Pull additional tookit repos
make PLATFORM=vpp sample-plugin-find-source

make PLATFORM=vpp TAG=vpp wipe-all
echo Build vpp forwarder production package
make PLATFORM=vpp TAG=vpp V=0 strip_sumbols=yes install-packages

tmp_dir="`mktemp -d /tmp/plugin-XXXXXX`"
trap "rm -rf $tmp_dir" err 

echo Create vpp forwarder production plugin toolkit tarball
mkdir -p $tmp_dir/tools/bin $tmp_dir/include $tmp_dir/lib64 \
         $tmp_dir/src/sample-plugin
build_tarball vpp-native
rm -rf $tmp_dir

exit 0