#!/bin/sh
# must be executed in project root folder
if [ -z $GCOV ]; then
  GCOV=gcov
fi

LCOV_VERSION="1.13"
LCOV_DIR="lcov-${LCOV_VERSION}"

if [ ! -e $LCOV_DIR ]; then
  wget -O - https://github.com/linux-test-project/lcov/releases/download/v${LCOV_VERSION}/lcov-${LCOV_VERSION}.tar.gz | tar zxf -
fi

# LCOV="$LCOV_EXE --gcov-tool=${GCOV} --rc lcov_branch_coverage=1"
LCOV="${LCOV_DIR}/bin/lcov --gcov-tool=${GCOV}" # no branch coverage

# collect raw data
$LCOV --base-directory `pwd` \
  --directory `pwd` \
  --capture --output-file coverage.info

# remove uninteresting entries
$LCOV --extract coverage.info "*/corsika/*" --output-file coverage.info

if [ $CI ]; then
  echo "Coverage report on CI currently disabled"
  # upload if on CI
  # curl -s https://codecov.io/bash | bash -s - -f coverage.info -X gcov -x $GCOV
else
  # otherwise just print
  $LCOV_DIR/bin/genhtml coverage.info -o coverage-report
fi
