-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
Makefile
146 lines (112 loc) · 4.8 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
CXX ?= clang++
CABIN_TIDY ?= clang-tidy
PREFIX ?= /usr/local
INSTALL ?= install
COMMIT_HASH ?= $(shell git rev-parse HEAD)
COMMIT_SHORT_HASH ?= $(shell git rev-parse --short=8 HEAD)
COMMIT_DATE ?= $(shell git show -s --date=format-local:'%Y-%m-%d' --format=%cd)
DEBUG_FLAGS := -g -O0 -DDEBUG
RELEASE_FLAGS := -O3 -DNDEBUG -flto
CXXFLAGS := -std=c++20 -fdiagnostics-color -pedantic-errors -Wall -Wextra -Wpedantic
ifeq ($(RELEASE), 1)
CXXFLAGS += $(RELEASE_FLAGS)
else
CXXFLAGS += $(DEBUG_FLAGS)
endif
O := build
PROJECT := $(O)/cabin
VERSION := $(shell grep -m1 version cabin.toml | cut -f 2 -d'"')
MKDIR_P := @mkdir -p
LIBGIT2_VERREQ := libgit2 >= 1.7.0, libgit2 < 1.10.0
LIBCURL_VERREQ := libcurl >= 7.79.1, libcurl < 9.0.0
NLOHMANN_JSON_VERREQ := nlohmann_json >= 3.10.5, nlohmann_json < 4.0.0
TBB_VERREQ := tbb >= 2021.5.0, tbb < 2023.0.0
FMT_VERREQ := fmt >= 8.1.1, fmt < 12.0.0
DEFINES := -DCABIN_CABIN_PKG_VERSION='"$(VERSION)"' \
-DCABIN_CABIN_COMMIT_HASH='"$(COMMIT_HASH)"' \
-DCABIN_CABIN_COMMIT_SHORT_HASH='"$(COMMIT_SHORT_HASH)"' \
-DCABIN_CABIN_COMMIT_DATE='"$(COMMIT_DATE)"'
INCLUDES := -isystem $(O)/DEPS/toml11/include \
-isystem $(O)/DEPS/mitama-cpp-result/include \
$(shell pkg-config --cflags '$(LIBGIT2_VERREQ)') \
$(shell pkg-config --cflags '$(LIBCURL_VERREQ)') \
$(shell pkg-config --cflags '$(NLOHMANN_JSON_VERREQ)') \
$(shell pkg-config --cflags '$(TBB_VERREQ)') \
$(shell pkg-config --cflags '$(FMT_VERREQ)')
LIBS := $(shell pkg-config --libs '$(LIBGIT2_VERREQ)') \
$(shell pkg-config --libs '$(LIBCURL_VERREQ)') \
$(shell pkg-config --libs '$(TBB_VERREQ)') \
$(shell pkg-config --libs '$(FMT_VERREQ)')
SRCS := $(shell find src -name '*.cc')
OBJS := $(patsubst src/%,$(O)/%,$(SRCS:.cc=.o))
DEPS := $(OBJS:.o=.d)
UNITTEST_SRCS := src/BuildConfig.cc src/Algos.cc src/Semver.cc src/VersionReq.cc src/Manifest.cc
UNITTEST_OBJS := $(patsubst src/%,$(O)/tests/test_%,$(UNITTEST_SRCS:.cc=.o))
UNITTEST_BINS := $(UNITTEST_OBJS:.o=)
UNITTEST_DEPS := $(UNITTEST_OBJS:.o=.d)
TIDY_TARGETS := $(patsubst src/%,tidy_%,$(SRCS))
GIT_DEPS := $(O)/DEPS/toml11 $(O)/DEPS/mitama-cpp-result
.PHONY: all clean install test versions tidy $(TIDY_TARGETS)
all: check_deps $(PROJECT)
check_deps:
@pkg-config '$(LIBGIT2_VERREQ)' || (echo "Error: $(LIBGIT2_VERREQ) not found" && exit 1)
@pkg-config '$(LIBCURL_VERREQ)' || (echo "Error: $(LIBCURL_VERREQ) not found" && exit 1)
@pkg-config '$(NLOHMANN_JSON_VERREQ)' || (echo "Error: $(NLOHMANN_JSON_VERREQ) not found" && exit 1)
@pkg-config '$(TBB_VERREQ)' || (echo "Error: $(TBB_VERREQ) not found" && exit 1)
@pkg-config '$(FMT_VERREQ)' || (echo "Error: $(FMT_VERREQ) not found" && exit 1)
$(PROJECT): $(OBJS)
$(CXX) $(CXXFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
$(O)/%.o: src/%.cc $(GIT_DEPS)
$(MKDIR_P) $(@D)
$(CXX) $(CXXFLAGS) -MMD $(DEFINES) $(INCLUDES) -c $< -o $@
-include $(DEPS)
test: $(UNITTEST_BINS)
@$(O)/tests/test_BuildConfig
@$(O)/tests/test_Algos
@$(O)/tests/test_Semver
@$(O)/tests/test_VersionReq
@$(O)/tests/test_Manifest
$(O)/tests/test_%.o: src/%.cc $(GIT_DEPS)
$(MKDIR_P) $(@D)
$(CXX) $(CXXFLAGS) -MMD -DCABIN_TEST $(DEFINES) $(INCLUDES) -c $< -o $@
-include $(UNITTEST_DEPS)
$(O)/tests/test_BuildConfig: $(O)/tests/test_BuildConfig.o $(O)/Algos.o \
$(O)/TermColor.o $(O)/Manifest.o $(O)/Parallelism.o $(O)/Semver.o \
$(O)/VersionReq.o $(O)/Git2/Repository.o $(O)/Git2/Object.o $(O)/Git2/Oid.o \
$(O)/Git2/Global.o $(O)/Git2/Config.o $(O)/Git2/Exception.o $(O)/Git2/Time.o \
$(O)/Git2/Commit.o $(O)/Command.o
$(CXX) $(CXXFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
$(O)/tests/test_Algos: $(O)/tests/test_Algos.o $(O)/TermColor.o $(O)/Command.o
$(CXX) $(CXXFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
$(O)/tests/test_Semver: $(O)/tests/test_Semver.o $(O)/TermColor.o
$(CXX) $(CXXFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
$(O)/tests/test_VersionReq: $(O)/tests/test_VersionReq.o $(O)/TermColor.o \
$(O)/Semver.o
$(CXX) $(CXXFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
$(O)/tests/test_Manifest: $(O)/tests/test_Manifest.o $(O)/TermColor.o \
$(O)/Semver.o $(O)/VersionReq.o $(O)/Algos.o $(O)/Git2/Repository.o \
$(O)/Git2/Global.o $(O)/Git2/Oid.o $(O)/Git2/Config.o $(O)/Git2/Exception.o \
$(O)/Git2/Object.o $(O)/Command.o
$(CXX) $(CXXFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
tidy: $(TIDY_TARGETS)
$(TIDY_TARGETS): tidy_%: src/% $(GIT_DEPS)
$(CABIN_TIDY) $(CABIN_TIDY_FLAGS) $< -- $(CXXFLAGS) $(DEFINES) -DCABIN_TEST $(INCLUDES)
install: all
$(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -m 0755 $(PROJECT) $(DESTDIR)$(PREFIX)/bin
clean:
-rm -rf $(O)
versions:
$(MAKE) -v
$(CXX) --version
#
# Git dependencies
#
$(O)/DEPS/toml11:
$(MKDIR_P) $(@D)
git clone https://github.com/ToruNiina/toml11.git $@
git -C $@ reset --hard v4.2.0
$(O)/DEPS/mitama-cpp-result:
$(MKDIR_P) $(@D)
git clone https://github.com/loliGothicK/mitama-cpp-result.git $@
git -C $@ reset --hard v10.0.2