-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
74 lines (56 loc) · 1.85 KB
/
Makefile
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# The Art of C++
# Copyright (c) 2015-2020 Daniel Frey
# Please see LICENSE for license or visit https://github.com/taocpp/tuple/
.SUFFIXES:
.SECONDARY:
ifeq ($(OS),Windows_NT)
UNAME_S := $(OS)
else
UNAME_S := $(shell uname -s)
endif
# For Darwin (Mac OS X) we assume that the default compiler
# clang++ is used; when $(CXX) is some version of g++, then
# $(CXXSTD) has to be set to -std=c++11 (or newer) so
# that -stdlib=libc++ is not automatically added.
ifeq ($(CXXSTD),)
CXXSTD := -std=c++11
ifeq ($(UNAME_S),Darwin)
CXXSTD += -stdlib=libc++
endif
endif
# Ensure strict standard compliance and no warnings, can be
# changed if desired.
CPPFLAGS ?= -pedantic
CXXFLAGS ?= -Wall -Wextra -Wshadow -Werror -O3
CLANG_TIDY ?= clang-tidy
HEADERS := $(shell find include -name '*.hpp')
SOURCES := $(shell find src -name '*.cpp')
DEPENDS := $(SOURCES:%.cpp=build/%.d)
BINARIES := $(SOURCES:%.cpp=build/%)
UNIT_TESTS := $(filter build/src/test/%,$(BINARIES))
.PHONY: all
all: compile check
.PHONY: compile
compile: $(BINARIES)
.PHONY: check
check: $(UNIT_TESTS)
@set -e; for T in $(UNIT_TESTS); do echo $$T; $$T > /dev/null; done
.PHONY: clean
clean:
@rm -rf build
@find . -name '*~' -delete
build/%.d: %.cpp Makefile
@mkdir -p $(@D)
$(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) -MM -MQ $@ $< -o $@
build/%: %.cpp build/%.d
$(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) $< -o $@
build/%.clang-tidy: %
$(CLANG_TIDY) -extra-arg "-Iinclude" -extra-arg "-std=c++11" -checks=*,-fuchsia-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-misc-macro-parentheses,-hicpp-no-array-decay -warnings-as-errors=* $< 2>/dev/null
@mkdir -p $(@D)
@touch $@
.PHONY: clang-tidy
clang-tidy: $(HEADERS:%=build/%.clang-tidy) $(SOURCES:%=build/%.clang-tidy)
@echo "All $(words $(HEADERS) $(SOURCES)) clang-tidy tests passed."
ifeq ($(findstring $(MAKECMDGOALS),clean),)
-include $(DEPENDS)
endif