#! /bin/sh

# --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 vcsn.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.
#
# Actually, I fail to be able to generate the coverage information for
# all our generated sources: genhtml fails to find them.  So also skip
# algos.cc etc. which are generated.
lcov --remove vcsn.info.tmp -o vcsn.info                \
     'lib/plugins/*'                                    \
     'lib/vcsn/*/parse.cc'                              \
     'lib/vcsn/*/parse.hh'                              \
     'lib/vcsn/*/scan.cc'                               \
     'lib/vcsn/*/stack.hh'                              \
     'lib/vcsn/algos/algos.cc'                          \
     'lib/vcsn/dot/stack.hh'                            \
     'lib/vcsn/dyn/context-printer-header-algo.cc'      \
     'lib/vcsn/odyn/odyn.cc'                            \
     'lib/vcsn/rat/location.hh'                         \
     'lib/vcsn/rat/position.hh'                         \
     'libexec/vcsn-tools-algos.cc'                      \
     'vcsn/odyn/odyn.hh'

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