#!/bin/bash
# This script is used to inject the Varnish ABI into the RPM Provides.

set -o errexit

if [ -x /usr/lib/rpm/redhat/find-provides ]; then
    /usr/lib/rpm/redhat/find-provides "$@"
elif [ -x /usr/lib/rpm/find-provides ]; then
    /usr/lib/rpm/find-provides "$@"
fi

# We don't install vcs_version.h, so we can't use RPM_BUILD_ROOT directly.
cd /builddir/build/BUILD/varnish* || true
cd ${RPM_BUILD_ROOT}/../../BUILD/varnish* || true

printf '#include "vcs_version.h"\nVCS_Version\n' \
        | cpp - -Iinclude | sed -e '/^"/!d' -e 's/\"//g' -e 's/^/varnishabi-strict-/'

printf '#include "vrt.h"\nvarnishabi- VRT_MAJOR_VERSION . VRT_MINOR_VERSION\n' \
	| cpp - -Iinclude \
	| sed -e '/^varnishabi-/!d' -e 's/U//g' -e 's/ //g'
