-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrules.mk
More file actions
36 lines (27 loc) · 1.59 KB
/
rules.mk
File metadata and controls
36 lines (27 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
MAKEFLAGS += -r
Dependency_file = $(addprefix target/dependencies/,$(addsuffix .mk,$(subst /,.,$(basename $(1)))))
Object_file = $(addprefix target/object_files/,$(addsuffix .o,$(subst /,.,$(basename $(1)))))
Executable_file = $(addprefix target/bin/,$(addsuffix ,$(subst /,.,$(basename $(1)))))
Manpage = $(addprefix target/manpages/,$(1))
clean:
@rm -rfv target
target target/object_files target/dependencies target/bin target/coverage target/manpages:
@mkdir -p $@
define Variable_rule # target_file, string_value
$(1): force | target
@echo '$(2)' | cmp -s - $$@ || echo '$(2)' > $$@
endef
$(eval $(call Variable_rule,target/compile_flags,$$(CXX) $$(CXXFLAGS)))
$(eval $(call Variable_rule,target/link_flags,$$(CXX) $$(LDFLAGS) $$(LDLIBS)))
target/manpages/%: manpages/%.adoc
asciidoctor -b manpage -D target/manpages $<
# $(call Object_file,%) $(call Dependency_file,%)&: src/%.cpp target/compile_flags | target/object_files target/dependencies
$(call Object_file,%): src/%.cpp target/compile_flags | target/object_files target/dependencies
$(CXX) $(CXXFLAGS) -MMD -MP -MF $(call Dependency_file,$(<F)) -MT $(call Object_file,$(<F)) -c -o $(call Object_file,$(<F)) $(addprefix src/,$(<F))
$(call Executable_file,%): target/link_flags | target/bin
$(CXX) -o $@ $(LDFLAGS) $(wordlist 2,$(words $^),$^) $(LDLIBS)
coverage: CXXFLAGS += --coverage -fno-elide-constructors -fno-default-inline
coverage: LDFLAGS += --coverage
coverage: test | target/coverage
@lcov --output-file target/coverage.info --directory target/object_files --capture --exclude '/usr/include/*'
@genhtml -o target/coverage target/coverage.info