commit: 6991be830faad0945010750fd3231dfa99f8ee7e
parent fd73fc35696b2a2d087abff6578b6d8bf201c1cb
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 9 Feb 2022 03:33:49 +0100
Add `make coverage` via gcov(1)
Diffstat:
3 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -18,6 +18,10 @@ install:
cd bin ; $(MAKE) install
cd sbin ; $(MAKE) install
+coverage:
+ cd bin ; $(MAKE) coverage
+ cd sbin ; $(MAKE) coverage
+
C_SOURCES = bin/*.c sbin/*.c
format: $(C_SOURCES)
clang-format -style=file -assume-filename=.clang-format -i $(C_SOURCES)
diff --git a/Makefile.common b/Makefile.common
@@ -6,6 +6,11 @@ all: $(EXE)
.c.o:
$(CC) -std=c99 $(CFLAGS) -c -o $@ $<
+.PHONY: coverage
+coverage:
+ $(GCOV) -b $(EXE)
+
.PHONY: clean
clean:
rm -fr $(EXE)
+ rm -fr ${EXE:=.c.gcov} ${EXE:=.gcda} ${EXE:=.gcno}
diff --git a/configure b/configure
@@ -18,6 +18,7 @@ Variables:
MAKE=BIN
MANDOC=BIN
SHELLCHECK=BIN
+ GCOV=BIN
CFLAGS=OPTIONS
LDFLAGS=OPTIONS
@@ -86,6 +87,7 @@ PKGCONFIG="${PKGCONFIG:-pkg-config}"
MSGFMT="${MSGFMT:-msgfmt}"
CC="${CC:-cc}"
MAKE="${MAKE:-make}"
+GCOV="${GCOV:-gcov}"
CFLAGS="${CFLAGS:--g -O2 -pie -fPIE}"
LDFLAGS="${LDFLAGS:--Wl,--as-needed}"
MANDOC="${MANDOC:-mandoc}"
@@ -135,6 +137,7 @@ rm -f config.mk bin/config.mk sbin/config.mk \
check_cmd PKGCONFIG "$PKGCONFIG" || exit 1
check_cmd CC "$CC" || exit 1
check_cmd MAKE "$MAKE" || exit 1
+check_cmd GCOV "$GCOV" || exit 1
if check_cmd MANDOC "$MANDOC"
then
@@ -195,6 +198,7 @@ MANDOC = ${MANDOC}
SHELLCHECK = ${SHELLCHECK}
MSGFMT = ${MSGFMT}
DBG = ${DBG}
+GCOV = ${GCOV}
CFLAGS = ${CFLAGS}
LDFLAGS = ${LDFLAGS}