a: b c commandmeans
a: b c
, make
first recursively
builds b
b: d e f command to (re)build bin the file. Make checks to see if d, e, or f are newer than b. If any one of them is, then the command to rebuild b is executed. If b is newer than all of those, the command is not executed.
make
displays an error and halts.
make
exits with a message like "cannot build b".
make
moves on to the next dependency (in this case, c
)
make
now compares the
last modification dates of those files against the last modification date
of file a
; if either is newer, it executes the command that
rebuilds a
.
make
: this one simple rule - check dependencies
and rebuild them, then rebuild the target if any dependency is newer -
covers a very wide variety of build steps.
make
works for any compiler/programming
language as well as any tool
that requires rebuilding files when other files change
CPPFLAGS=-std=c++14 -Wall --coverage cube_test.o: cube.h cube_test.cpp g++ $(CPPFLAGS) -c cube_test.cpp
stack.o: stack.h list.h stack.cppAutomatically executes
$(CXX) -c $(CPPFLAGS)on the files (so the choice CPPFLAGS above was not accidental!), giving the command
g++ -c -std=c++14 -Wall --coverage stack.cpp
# makefile for cube code CPPFLAGS=-std=c++14 -Wall --coverage all: cube cube_test cube.o: cube.h cube.cpp cube_test.o: cube.h cube_test.cpp main.o: cube.h main.cpp cube: cube.o main.o cube_test: cube.o cube_test.o g++ -pthread $(CPPFLAGS) cube.o cube_test.o -lgtest_main -lgtest -lpthread -o cube_test coverage: cube_test mkdir -p code_coverage_report ./cube_test lcov --directory ./ --capture --output-file ./code_coverage.info -rc lcov_branch_coverage=1 genhtml code_coverage.info --branch-coverage --output-directory ./code_coverage_report/ clean: rm -f *.o *.gcda *.gcno code_coverage.info cube cube_test rm -rf code_coverage_report