2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
6 # This builds xz with special CFLAGS for measuring code coverage and
7 # uses lcov and genhtml to create coverage reports.
9 # The current directory is used as the build directory so out-of-tree
10 # builds are possible. The coverage reports are written to the directory
11 # "coverage" under the current directory.
13 # Any options passed to this script are passed to "make" so to get
14 # faster builds use, for example, "-j4" as an argument to this script.
18 ###############################################################################
22 COVERAGE_DIR
="coverage"
24 # Test if lcov is installed
25 if ! command -v lcov
> /dev
/null
27 echo "Error: lcov not installed"
31 # Test if genhtml is installed
32 if ! command -v genhtml
> /dev
/null
34 echo "Error: genhtml not installed"
38 top_srcdir
=$
(cd -- "$(dirname -- "$0")" && cd ..
&& pwd)
40 # Run the autogen.sh script if the configure script has not been generated
41 if ! test -f "$top_srcdir/configure"
43 ( cd "$top_srcdir" && .
/autogen.sh
)
46 # Execute the configure script if the Makefile is not present
47 if ! test -f "Makefile"
49 "$top_srcdir/configure" \
54 --enable-silent-rules \
55 CFLAGS
="$CFLAGS --coverage --no-inline -O0"
61 # Re-create the coverage directory
62 rm -rf "$COVERAGE_DIR"
63 mkdir
-p "$COVERAGE_DIR/liblzma"
64 mkdir
-p "$COVERAGE_DIR/xz"
66 # Run lcov with src/liblzma as the input directory and write the
67 # results out to the coverage directory
68 lcov
-c -d "src/liblzma" -o "$COVERAGE_DIR/liblzma/liblzma.cov"
69 lcov
-c -d "src/xz" -o "$COVERAGE_DIR/xz/xz.cov"
71 # Generate the reports
72 genhtml
"$COVERAGE_DIR/liblzma/liblzma.cov" -o "$COVERAGE_DIR/liblzma"
73 genhtml
"$COVERAGE_DIR/xz/xz.cov" -o "$COVERAGE_DIR/xz"
76 echo "file://$PWD/$COVERAGE_DIR/liblzma/index.html"
77 echo "file://$PWD/$COVERAGE_DIR/xz/index.html"