#! /bin/sh

base=tc

# --no-external was introduced in lcov 1.10.
if lcov --no-external --version; then
  no_external=--no-external
fi

# g++-4.8 -> gcov-4.8.
gcov=$(echo "$CXX" | perl -ne '/(?:clang|g)\+\+(-[\d.]+)?/ and print "gcov$1\n";')

lcov --capture                                  \
     --base-directory $DIR_SOURCE               \
     --directory .                              \
     --gcov-tool "$gcov"                        \
     $no_external                               \
     --output $base.info.tmp

# There are files we really don't care about (e.g., generated parsers
# and scanners) that pollute our statistics.  Note that we care about
# the coverage of their sources (e.g., parse.yy), but not about the
# coverage of the Bison infrastructure.
#
# FIXME: we should be able to check coverage of parsetiger.yy.
#
# The problem with prelude.cc (why parse/?) is weird.  We should also
# be able to find the *.brg and the prologue.hh files rather than
# ignoring them.
lcov --remove $base.info.tmp -o $base.info      \
   '*/parse/location.hh'                        \
   '*/parse/parsetiger.cc'                      \
   '*/parse/parsetiger.hh'                      \
   '*/parse/parsetiger.yy'                      \
   '*/parse/position.hh'                        \
   '*/parse/prelude.cc'                         \
   '*/parse/scantiger.cc'                       \
   '*/parse/stack.hh'                           \
   '*/target/*/*.brg'                           \
   '*/target/*/epilogue.cc'                     \
   '*/target/*/prologue.hh'                     \
   '*/target/*/runtime*.cc'                     \
   '*/target/*/runtime*.hh'                     \
   '*/llvmtranslate/runtime.cc'

genhtml --legend --demangle-cpp                 \
     --output-directory $base.cov.html          \
     $base.info
