#! /bin/bash
# Pack source code for distribution

proj_name="tbplas-cpp"
proj_dir=$HOME/proj/$proj_name
items=$(ls $proj_dir)  # It must be placed here!
top_dir=$(pwd)

# Clean build
cd $top_dir/build
../tools/clean_build.sh

# Copy items to destination
cd $top_dir
test -d tmp/$proj_name && rm -rf tmp/$proj_name
mkdir -p tmp/$proj_name
for item in $items; do
    cp -r $proj_dir/$item tmp/$proj_name
done

# # Remove unnecessary files
cd $top_dir/tmp/$proj_name/build
rm -rf *
# for kind in pyc so; do
#     find . -name "*.$kind" | xargs rm -rf
# done
# for kind in __pycache__ sim_data build; do
#     find . -name "$kind" | xargs rm -rf
# done

# Compress
cd $top_dir/tmp
tar -cjf $proj_name.tar.bz2 $proj_name
mv $proj_name.tar.bz2 ..

# Clean
cd $top_dir
rm -rf tmp
