#/bin/bash -e

# 1. create Debian build control files depending on the available kernel packages
make -f debian/rules genfiles

# 2. adapt debian/changelog if necessary
if [ -z "${EXPORT}" ] || [ "${EXPORT}" = "null" ]]; then
    DCH_VERSION=$(dpkg-parsechangelog -n 1 -S Version | tr -d '\n')
    VERSION=${VERSION:-${DCH_VERSION}~${TIMESTAMP}}
    sed -i "1s/(.*)/(${VERSION})/" debian/changelog
fi

# 3 .now we have debian/control -> get build dependencies
sudo mk-build-deps --tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes' --install debian/control --remove
