This project includes a Makefile that helps automate the compilation, testing, and debugging of multiple C++ projects.
This Makefile defines several targets:
- all: Builds all the executables:
LFServer,PServer, andtests.
make all-
LFServer: Compiles the leader-follower server executable, using the source files fromNetwork/src,Algorithms/src,DataStructures/src, andDesignPatterns/src, along withLfserverDemo.cpp.make LFServer
-
PServer: Compiles the pipeline server executable, using similar source files but withPipelineServerDemo.cpp.make PServer
-
tests: Compiles the test executable, usingTestsMain.cppandTests/src/Tests.cpp.make tests
The Makefile uses the following compilation options:
-
CXX: The compiler used is
g++. -
CXXFLAGS: Common compiler flags include:
-Wall: Enables all compiler warnings.-g: Includes debugging information.-std=c++20: Uses the C++20 standard.-pthread: Enables multithreading with pthreads.-fprofile-arcs -ftest-coverage: Enables code coverage generation.
Run the commands to build the executables:
make LFServer
make PServer
make testsValgrind is used to analyze memory usage, detect race conditions, and perform profiling:
-
Memory Leak Check: Run Valgrind’s
memchecktool to detect memory leaks and invalid memory accesses:make valgrind-memcheck_LF make valgrind-memcheck_P
-
Race Condition Check: Use Valgrind’s
helgrindtool to detect race conditions:make valgrind-helgrind_LF make valgrind-helgrind_P
-
Performance Profiling: Run Valgrind’s
callgrindtool to collect profiling data for performance analysis:make valgrind-callgrind_LF make valgrind-callgrind_P
Use kcachegrind to visualize the callgrind output for performance analysis.
The Makefile supports code coverage analysis using gcov and lcov. To generate a coverage report:
- Compile the project with coverage flags and run tests.
- Generate a coverage report:
make coverage
The code coverage report will be saved as gcov_report.txt, and an HTML version will be generated in the coverage_html/ directory.
The clean target removes compiled object files, executables, and coverage data:
make cleanThis also removes .gcda and .gcno files from the source directories, ensuring a fresh build.
To compile the LFServer, run a memory check, and generate a coverage report:
make LFServer
make valgrind-memcheck_LF
make coverageTo visualize performance with kcachegrind after running callgrind:
make valgrind-callgrind_LF
kcachegrind callgrind.out.<pid>This Makefile provides an efficient development workflow with debugging, testing, and performance analysis tools.