#!/bin/bash
#
# Generate .symbols files from .debs
#
set -e

pushd ..
VERSION=$(dpkg-parsechangelog -S Version | cut -f1 -d-)
DEB_FILE="libumf1_1.1.0-0ubuntu1~ppa1_amd64.deb"
  
echo "Generating symbols from $(basename "$DEB_FILE")..."
dpkg-deb -x "../$DEB_FILE" tmpdir
dpkg-gensymbols -q -v"$VERSION" -plibumf1 -Ptmpdir -Odebian/libumf1.symbols.raw || true
# Add Build-Depends-Package field after the first line
sed -i '1a* Build-Depends-Package: libumf-dev' debian/libumf1.symbols.raw
sed 's/ \(_Z[^ ]*\)\( .*\)/ (c++)"\1"\2/' debian/libumf1.symbols.raw | c++filt > debian/libumf1.symbols
rm -f debian/libumf1.symbols.raw
rm -rf tmpdir

popd
echo "Done! Symbols files generated in debian/"
