3 ###############################################################################
5 # This builds xz with special CFLAGS for measuring code coverage and
6 # uses lcov and genhtml to create coverage reports.
8 # The current directory is used as the build directory so out-of-tree
9 # builds are possible. The coverage reports are written to the directory
10 # "coverage" under the current directory.
12 # Any options passed to this script are passed to "make" so to get
13 # faster builds use, for example, "-j4" as an argument to this script.
17 # This file has been put into the public domain.
18 # You can do whatever you want with this file.
20 ###############################################################################
24 COVERAGE_DIR
="coverage"
26 # Test if lcov is installed
27 if ! command -v lcov
> /dev
/null
29 echo "Error: lcov not installed"
33 # Test if genhtml is installed
34 if ! command -v genhtml
> /dev
/null
36 echo "Error: genhtml not installed"
40 top_srcdir
=$
(cd -- "$(dirname -- "$0")" && cd ..
&& pwd)
42 # Run the autogen.sh script if the configure script has not been generated
43 if ! test -f "$top_srcdir/configure"
45 ( cd "$top_srcdir" && .
/autogen.sh
)
48 # Execute the configure script if the Makefile is not present
49 if ! test -f "Makefile"
51 "$top_srcdir/configure" \
56 --enable-silent-rules \
57 CFLAGS
="$CFLAGS --coverage --no-inline -O0"
63 # Re-create the coverage directory
64 rm -rf "$COVERAGE_DIR"
65 mkdir
-p "$COVERAGE_DIR/liblzma"
66 mkdir
-p "$COVERAGE_DIR/xz"
68 # Run lcov with src/liblzma as the input directory and write the
69 # results out to the coverage directory
70 lcov
-c -d "src/liblzma" -o "$COVERAGE_DIR/liblzma/liblzma.cov"
71 lcov
-c -d "src/xz" -o "$COVERAGE_DIR/xz/xz.cov"
73 # Generate the reports
74 genhtml
"$COVERAGE_DIR/liblzma/liblzma.cov" -o "$COVERAGE_DIR/liblzma"
75 genhtml
"$COVERAGE_DIR/xz/xz.cov" -o "$COVERAGE_DIR/xz"
78 echo "file://$PWD/$COVERAGE_DIR/liblzma/index.html"
79 echo "file://$PWD/$COVERAGE_DIR/xz/index.html"