-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (192 loc) · 7.86 KB
/
Copy pathMakefile
File metadata and controls
251 lines (192 loc) · 7.86 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Copyright 2021 Google LLC
# Copyright 2008-2021 Alexander Galanin <al@galanin.nnov.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
PROJECT = mount-zip
PKG_CONFIG ?= pkg-config
FUSE_MAJOR_VERSION ?= 3
ifeq ($(FUSE_MAJOR_VERSION), 3)
DEPS = fuse3
FUSE_CXXFLAGS = -DFUSE_USE_VERSION=30
else ifeq ($(FUSE_MAJOR_VERSION), 2)
DEPS = fuse
FUSE_CXXFLAGS = -DFUSE_USE_VERSION=26
endif
DEPS += libzip
ifeq ($(CHROME_ICU), 1)
PKG_CXXFLAGS += -DCHROME_ICU
PKG_CXXFLAGS += -I"$(SYSROOT)/usr/include/icu-chrome/common"
PKG_CXXFLAGS += -I"$(SYSROOT)/usr/include/icu-chrome/i18n"
PKG_LDFLAGS += -licui18n-chrome -licuuc-chrome
else
DEPS += icu-uc icu-i18n
endif
UNIT_TEST_DEPS = gtest gtest_main
# On macOS, icu4c is keg-only (not symlinked into the default search
# path). Wire the Homebrew path into PKG_CONFIG_PATH so every pkg-config call
# in this Makefile resolves the correct version regardless of shell environment.
ifeq ($(shell uname -s),Darwin)
COMMON_CXXFLAGS += -std=gnu++23
BREW_PREFIX := $(shell brew --prefix 2>/dev/null)
ifneq ($(BREW_PREFIX),)
PKG_CONFIG = env PKG_CONFIG_PATH="$(BREW_PREFIX)/opt/icu4c/lib/pkgconfig" pkg-config
COMMON_CXXFLAGS += -I$(BREW_PREFIX)/opt/boost/include
# macFUSE enables Darwin-extended operation signatures by default
# (fuse_darwin_attr*, struct statfs*, 5-arg getxattr, fuse_darwin_fill_dir_t).
# mount-zip uses standard POSIX signatures, so opt out of the extensions.
FUSE_CXXFLAGS += -DFUSE_DARWIN_ENABLE_EXTENSIONS=0
endif
else
COMMON_CXXFLAGS += -std=c++23
endif
PKG_CXXFLAGS += $(shell $(PKG_CONFIG) --cflags $(DEPS) 2>/dev/null)
PKG_LDFLAGS += $(shell $(PKG_CONFIG) --libs $(DEPS) 2>/dev/null)
HAS_GTEST := $(shell $(PKG_CONFIG) --exists $(UNIT_TEST_DEPS) 2>/dev/null && echo yes || echo no)
ifeq ($(HAS_GTEST), yes)
UNIT_TEST_PKG_CXXFLAGS := $(shell $(PKG_CONFIG) --cflags $(UNIT_TEST_DEPS) 2>/dev/null)
UNIT_TEST_PKG_LDFLAGS := $(shell $(PKG_CONFIG) --libs $(UNIT_TEST_DEPS) 2>/dev/null)
endif
COMMON_CXXFLAGS += -Wall -Wextra -Wno-nullability-extension \
-Wno-sign-compare -Wno-missing-field-initializers \
-I. -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $(FUSE_CXXFLAGS)
ifeq ($(DEBUG), 1)
COMMON_CXXFLAGS += -O0 -g
else
COMMON_CXXFLAGS += -O2 -DNDEBUG
endif
ifeq ($(ASAN), 1)
COMMON_CXXFLAGS += -fsanitize=address
PKG_LDFLAGS += -fsanitize=address
endif
ifeq ($(UBSAN), 1)
COMMON_CXXFLAGS += -fsanitize=undefined
PKG_LDFLAGS += -fsanitize=undefined
endif
ifeq ($(COVERAGE), 1)
COMMON_CXXFLAGS += -fprofile-arcs -ftest-coverage
LDFLAGS += --coverage
endif
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man/man1
MAN = $(PROJECT).1
INSTALL = install
OUT = out
all: $(OUT)/$(PROJECT)
# ---- Formatting
FORMAT = clang-format
CC_FILES = $(wildcard *.cc lib/*.cc tests/*.cc utils/*.cpp)
H_FILES = $(wildcard lib/*.h tests/*.h)
ALL_CXX_FILES = $(CC_FILES) $(H_FILES)
format:
$(FORMAT) -i -style=file $(ALL_CXX_FILES)
check-format:
$(FORMAT) --dry-run -Werror -style=file $(ALL_CXX_FILES)
# ---- Library
LIB_DIR = lib
LIB_OUT = $(OUT)/$(LIB_DIR)
LIB_SOURCES = $(wildcard $(LIB_DIR)/*.cc)
LIB_OBJECTS = $(addprefix $(OUT)/,$(LIB_SOURCES:.cc=.o))
LIB_ARCHIVE = $(OUT)/lib$(PROJECT).a
$(LIB_ARCHIVE): $(LIB_OBJECTS)
$(AR) $(ARFLAGS) $@ $(LIB_OBJECTS)
$(OUT)/$(LIB_DIR)/%.o: $(LIB_DIR)/%.cc
@mkdir -p $(dir $@)
$(CXX) -c $(COMMON_CXXFLAGS) $(PKG_CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< -o $@ -MMD -MP -MF $(@:.o=.d)
# ---- Binaries
$(OUT)/$(PROJECT): $(PROJECT).cc $(LIB_ARCHIVE)
mkdir -p $(OUT)
$(CXX) $(COMMON_CXXFLAGS) -Ilib $(PKG_CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< $(LIB_ARCHIVE) $(PKG_LDFLAGS) $(LDFLAGS) -o $@
# ---- Utilities
UTILS_DIR = utils
UTILS_SOURCES = $(wildcard $(UTILS_DIR)/*.cpp)
UTILS_BINARIES = $(addprefix $(OUT)/,$(UTILS_SOURCES:.cpp=))
$(OUT)/$(UTILS_DIR)/%: $(UTILS_DIR)/%.cpp $(LIB_ARCHIVE)
@mkdir -p $(dir $@)
$(CXX) $(COMMON_CXXFLAGS) -I. $(PKG_CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< $(LIB_ARCHIVE) $(PKG_LDFLAGS) $(LDFLAGS) -o $@
utils: $(UTILS_BINARIES)
# ---- Unit Tests
UNIT_TEST = unit_tests
UNIT_TEST_SOURCES = $(wildcard tests/*.cc)
UNIT_TEST_OBJECTS = $(addprefix $(OUT)/,$(UNIT_TEST_SOURCES:.cc=.o))
ifeq ($(HAS_GTEST), yes)
$(OUT)/$(UNIT_TEST): $(UNIT_TEST_OBJECTS) $(LIB_ARCHIVE)
$(CXX) $(COMMON_CXXFLAGS) $(PKG_CXXFLAGS) $(UNIT_TEST_PKG_CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS) $^ $(PKG_LDFLAGS) $(UNIT_TEST_PKG_LDFLAGS) $(LDFLAGS) -o $@
$(OUT)/tests/%.o: tests/%.cc
@mkdir -p $(dir $@)
$(CXX) -Ilib -c $(COMMON_CXXFLAGS) $(PKG_CXXFLAGS) $(UNIT_TEST_PKG_CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< -o $@ -MMD -MP -MF $(@:.o=.d)
UNIT_TEST_BIN = $(OUT)/$(UNIT_TEST)
else
UNIT_TEST_BIN =
endif
# ---- Standard targets
check: $(OUT)/$(PROJECT) $(UNIT_TEST_BIN) tests/data/big.zip tests/data/collisions.zip tests/data/deep.zip tests/data/many_nodes.zip
$(if $(UNIT_TEST_BIN),$(UNIT_TEST_BIN))
python3 tests/test.py
check-fast: $(OUT)/$(PROJECT) $(UNIT_TEST_BIN)
$(if $(UNIT_TEST_BIN),$(UNIT_TEST_BIN))
python3 tests/test.py --fast
valgrind: $(OUT)/$(PROJECT) $(UNIT_TEST_BIN)
$(if $(UNIT_TEST_BIN),valgrind -q --leak-check=full --track-origins=yes --error-exitcode=33 $(UNIT_TEST_BIN))
MOUNT_WRAPPER="valgrind -q --leak-check=full --error-exitcode=33" python3 tests/test.py --fast
TEST_TARGET ?= check-fast
coverage:
$(MAKE) clean
$(MAKE) DEBUG=1 COVERAGE=1 $(TEST_TARGET)
lcov --capture --directory $(OUT) --output-file $(OUT)/coverage.info --ignore-errors mismatch,inconsistent
lcov --remove $(OUT)/coverage.info '/usr/include/*' '/usr/lib/*' 'tests/*' --output-file $(OUT)/coverage.info --ignore-errors unused,inconsistent
genhtml $(OUT)/coverage.info --output-directory $(OUT)/coverage --ignore-errors inconsistent
@echo "Coverage report generated at $(OUT)/coverage/index.html"
test: check
unit_tests: $(UNIT_TEST_BIN)
$(if $(UNIT_TEST_BIN),$(UNIT_TEST_BIN),@echo "Google Test not found; cannot run unit tests.")
clean:
rm -rf $(OUT)
clean-data:
rm -f tests/data/big.zip tests/data/collisions.zip tests/data/deep.zip tests/data/many_nodes.zip
doc: $(MAN)
@if [ -z "$(QUIET)" ]; then man -l $(MAN); fi
release:
python3 release.py $(VERSION)
$(MAN): README.md
pandoc $< -s -t man | \
sed -e 's/^\.IP \\\[bu\]/.PD 0\n.IP \\\[bu\]/g' \
-e 's/^\.SH/.PD\n.SH/g' \
-e 's/^\.SS/.PD\n.SS/g' \
-e 's/^\.PP/.PD\n.PP/g' \
-e 's/^\.TP/.PD\n.TP/g' > $@
ifneq ($(filter clean%,$(MAKECMDGOALS)),)
else
-include $(LIB_OBJECTS:.o=.d)
-include $(UNIT_TEST_OBJECTS:.o=.d)
endif
install: $(OUT)/$(PROJECT)
mkdir -p "$(DESTDIR)$(BINDIR)" "$(DESTDIR)$(MANDIR)"
$(INSTALL) "$(OUT)/$(PROJECT)" "$(DESTDIR)$(BINDIR)/$(PROJECT)"
$(INSTALL) -m 644 $(MAN) "$(DESTDIR)$(MANDIR)/$(MAN)"
install-strip: $(OUT)/$(PROJECT)
mkdir -p "$(DESTDIR)$(BINDIR)" "$(DESTDIR)$(MANDIR)"
$(INSTALL) -s "$(OUT)/$(PROJECT)" "$(DESTDIR)$(BINDIR)/$(PROJECT)"
$(INSTALL) -m 644 $(MAN) "$(DESTDIR)$(MANDIR)/$(MAN)"
uninstall:
rm -f "$(DESTDIR)$(BINDIR)/$(PROJECT)" "$(DESTDIR)$(MANDIR)/$(MAN)"
tests/data/big.zip: tests/make_big_zip.py
python3 tests/make_big_zip.py
tests/data/collisions.zip: tests/make_collisions.py
python3 tests/make_collisions.py
tests/data/deep.zip: tests/make_deep.py
python3 tests/make_deep.py
tests/data/many_nodes.zip: tests/make_many_nodes.py
python3 tests/make_many_nodes.py
.PHONY: all check check-fast check-format clean clean-data doc format install install-strip release test uninstall unit_tests utils valgrind