Skip to content

Commit 7deb0f1

Browse files
Update Makefile for Codecov
1 parent 921f6d1 commit 7deb0f1

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

Makefile

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Update 2025-08-12:
2+
# o Add flags for codecov
3+
14
#
25
# Update 2020-01-29:
36
# o Uses required argument of serial, omp, or mpi.
@@ -15,13 +18,13 @@
1518
# -- a bit cleaner Kent [email protected]
1619
#
1720
# TODO: use function to create VPATH
18-
# TODO: Fix MPI after learning purpose
1921
# TODO: Make rules for *.hpp's
2022
#
2123
# Set terminal width to 220 to avoid viewing wrapped lines in output. A width of 200 avoids most wrapping.
2224

2325

2426
# LDFLAGS = -larmadillo
27+
# -- armadillo is not a dependency any more. (changed 2022)
2528

2629
VPATH = \
2730
src/ \
@@ -45,11 +48,34 @@ SDIR = src
4548
EPDIR = EXE_PAR
4649
ECDIR = EXE_CLUSTER
4750

51+
# Add test to path if enabled
4852
ifeq (test,$(MAKECMDGOALS))
4953
VPATH += tests
5054
SDIR += tests
5155
endif
5256

57+
# Enable coverage for "coverage" and "test" targets
58+
# --- Coverage toggle (OFF by default)
59+
COVERAGE ?= 0
60+
61+
# GCC/g++ coverage (works on Linux easily)
62+
ifeq ($(COVERAGE),1)
63+
CFLAGS += -O0 -g --coverage
64+
CXXFLAGS += -O0 -g --coverage
65+
LDFLAGS += --coverage
66+
# Optional: ensure gcov is linked explicitly
67+
# LIBS += -lgcov
68+
endif
69+
70+
# (Optional) If you use Clang/LLVM for coverage instead of GCC,
71+
# use COVERAGE=llvm and uncomment this block:
72+
ifeq ($(COVERAGE),llvm)
73+
CFLAGS += -O0 -g -fprofile-instr-generate -fcoverage-mapping
74+
CXXFLAGS += -O0 -g -fprofile-instr-generate -fcoverage-mapping
75+
LDFLAGS += -fprofile-instr-generate
76+
endif
77+
78+
5379
PROF =
5480

5581
.PHONY: any
@@ -184,16 +210,17 @@ $(MAKECMDGOALS):$(EXEC)
184210

185211
$(EXEC): $(OBJS) $(TEST_OBJ)
186212
@echo "Compiling $(EDIR)/$(@F).cpp"
187-
$(CC) $(CFLAGS) $(CXXFLAGS) $(INCS) $(PROF) -o $@ $(EDIR)/$(@F).cpp $(OBJS) $(LIBS) $(PLANG)
213+
$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCS) $(PROF) $(LDFLAGS) -o $@ $(EDIR)/$(@F).cpp $(OBJS) $(LIBS) $(PLANG)
188214
@echo "------------"
189215

190216
obj/%.o: %.cpp
191217
@echo "Compiling $< at $(<F) $(<D)"
192-
$(CC) $(CFLAGS) $(CXXFLAGS) $(INCS) $(PROF) -c $< -o $@ $(PLANG) $(DEFS)
218+
$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCS) $(PROF) $(LDFLAGS) -c $< -o $@ $(PLANG) $(DEFS)
193219
@echo "------------"
194220

195221
clean:
196222
rm -rf $(ODIR) bin
223+
rm -rf *.gcno *.gcda *.gcov coverage/ coverage.info
197224

198225
# Reference: https://www.gnu.org/software/make/manual/html_node/Quick-Reference.html
199226
# https://www.gnu.org/software/make/

0 commit comments

Comments
 (0)