]> git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/contrib/pzstd/Makefile
import 15.2.0 Octopus source
[ceph.git] / ceph / src / zstd / contrib / pzstd / Makefile
1 # ################################################################
2 # Copyright (c) 2016-present, Facebook, Inc.
3 # All rights reserved.
4 #
5 # This source code is licensed under both the BSD-style license (found in the
6 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 # in the COPYING file in the root directory of this source tree).
8 # ################################################################
9
10 # Standard variables for installation
11 DESTDIR ?=
12 PREFIX ?= /usr/local
13 BINDIR := $(DESTDIR)$(PREFIX)/bin
14
15 ZSTDDIR = ../../lib
16 PROGDIR = ../../programs
17
18 # External program to use to run tests, e.g. qemu or valgrind
19 TESTPROG ?=
20 # Flags to pass to the tests
21 TESTFLAGS ?=
22
23 # We use gcc/clang to generate the header dependencies of files
24 DEPFLAGS = -MMD -MP -MF $*.Td
25 POSTCOMPILE = mv -f $*.Td $*.d
26
27 # CFLAGS, CXXFLAGS, CPPFLAGS, and LDFLAGS are for the users to override
28 CFLAGS ?= -O3 -Wall -Wextra
29 CXXFLAGS ?= -O3 -Wall -Wextra -pedantic
30 CPPFLAGS ?=
31 LDFLAGS ?=
32
33 # Include flags
34 PZSTD_INC = -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(PROGDIR) -I.
35 GTEST_INC = -isystem googletest/googletest/include
36
37 PZSTD_CPPFLAGS = $(PZSTD_INC)
38 PZSTD_CCXXFLAGS =
39 PZSTD_CFLAGS = $(PZSTD_CCXXFLAGS)
40 PZSTD_CXXFLAGS = $(PZSTD_CCXXFLAGS) -std=c++11
41 PZSTD_LDFLAGS =
42 EXTRA_FLAGS =
43 ALL_CFLAGS = $(EXTRA_FLAGS) $(CPPFLAGS) $(PZSTD_CPPFLAGS) $(CFLAGS) $(PZSTD_CFLAGS)
44 ALL_CXXFLAGS = $(EXTRA_FLAGS) $(CPPFLAGS) $(PZSTD_CPPFLAGS) $(CXXFLAGS) $(PZSTD_CXXFLAGS)
45 ALL_LDFLAGS = $(EXTRA_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(PZSTD_LDFLAGS)
46
47
48 # gtest libraries need to go before "-lpthread" because they depend on it.
49 GTEST_LIB = -L googletest/build/googlemock/gtest
50 LIBS =
51
52 # Compilation commands
53 LD_COMMAND = $(CXX) $^ $(ALL_LDFLAGS) $(LIBS) -pthread -o $@
54 CC_COMMAND = $(CC) $(DEPFLAGS) $(ALL_CFLAGS) -c $< -o $@
55 CXX_COMMAND = $(CXX) $(DEPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
56
57 # Get a list of all zstd files so we rebuild the static library when we need to
58 ZSTDCOMMON_FILES := $(wildcard $(ZSTDDIR)/common/*.c) \
59 $(wildcard $(ZSTDDIR)/common/*.h)
60 ZSTDCOMP_FILES := $(wildcard $(ZSTDDIR)/compress/*.c) \
61 $(wildcard $(ZSTDDIR)/compress/*.h)
62 ZSTDDECOMP_FILES := $(wildcard $(ZSTDDIR)/decompress/*.c) \
63 $(wildcard $(ZSTDDIR)/decompress/*.h)
64 ZSTDPROG_FILES := $(wildcard $(PROGDIR)/*.c) \
65 $(wildcard $(PROGDIR)/*.h)
66 ZSTD_FILES := $(wildcard $(ZSTDDIR)/*.h) \
67 $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) \
68 $(ZSTDPROG_FILES)
69
70 # List all the pzstd source files so we can determine their dependencies
71 PZSTD_SRCS := $(wildcard *.cpp)
72 PZSTD_TESTS := $(wildcard test/*.cpp)
73 UTILS_TESTS := $(wildcard utils/test/*.cpp)
74 ALL_SRCS := $(PZSTD_SRCS) $(PZSTD_TESTS) $(UTILS_TESTS)
75
76
77 # Define *.exe as extension for Windows systems
78 ifneq (,$(filter Windows%,$(OS)))
79 EXT =.exe
80 else
81 EXT =
82 endif
83
84 # Standard targets
85 .PHONY: default
86 default: all
87
88 .PHONY: test-pzstd
89 test-pzstd: TESTFLAGS=--gtest_filter=-*ExtremelyLarge*
90 test-pzstd: clean googletest pzstd tests check
91
92 .PHONY: test-pzstd32
93 test-pzstd32: clean googletest32 all32 check
94
95 .PHONY: test-pzstd-tsan
96 test-pzstd-tsan: LDFLAGS=-fuse-ld=gold
97 test-pzstd-tsan: TESTFLAGS=--gtest_filter=-*ExtremelyLarge*
98 test-pzstd-tsan: clean googletest tsan check
99
100 .PHONY: test-pzstd-asan
101 test-pzstd-asan: LDFLAGS=-fuse-ld=gold
102 test-pzstd-asan: TESTFLAGS=--gtest_filter=-*ExtremelyLarge*
103 test-pzstd-asan: clean asan check
104
105 .PHONY: check
106 check:
107 $(TESTPROG) ./utils/test/BufferTest$(EXT) $(TESTFLAGS)
108 $(TESTPROG) ./utils/test/RangeTest$(EXT) $(TESTFLAGS)
109 $(TESTPROG) ./utils/test/ResourcePoolTest$(EXT) $(TESTFLAGS)
110 $(TESTPROG) ./utils/test/ScopeGuardTest$(EXT) $(TESTFLAGS)
111 $(TESTPROG) ./utils/test/ThreadPoolTest$(EXT) $(TESTFLAGS)
112 $(TESTPROG) ./utils/test/WorkQueueTest$(EXT) $(TESTFLAGS)
113 $(TESTPROG) ./test/OptionsTest$(EXT) $(TESTFLAGS)
114 $(TESTPROG) ./test/PzstdTest$(EXT) $(TESTFLAGS)
115
116 .PHONY: install
117 install: PZSTD_CPPFLAGS += -DNDEBUG
118 install: pzstd$(EXT)
119 install -d -m 755 $(BINDIR)/
120 install -m 755 pzstd$(EXT) $(BINDIR)/pzstd$(EXT)
121
122 .PHONY: uninstall
123 uninstall:
124 $(RM) $(BINDIR)/pzstd$(EXT)
125
126 # Targets for many different builds
127 .PHONY: all
128 all: PZSTD_CPPFLAGS += -DNDEBUG
129 all: pzstd$(EXT)
130
131 .PHONY: debug
132 debug: EXTRA_FLAGS += -g
133 debug: pzstd$(EXT) tests roundtrip
134
135 .PHONY: tsan
136 tsan: PZSTD_CCXXFLAGS += -fsanitize=thread -fPIC
137 tsan: PZSTD_LDFLAGS += -fsanitize=thread
138 tsan: debug
139
140 .PHONY: asan
141 asan: EXTRA_FLAGS += -fsanitize=address
142 asan: debug
143
144 .PHONY: ubsan
145 ubsan: EXTRA_FLAGS += -fsanitize=undefined
146 ubsan: debug
147
148 .PHONY: all32
149 all32: EXTRA_FLAGS += -m32
150 all32: all tests roundtrip
151
152 .PHONY: debug32
153 debug32: EXTRA_FLAGS += -m32
154 debug32: debug
155
156 .PHONY: asan32
157 asan32: EXTRA_FLAGS += -m32
158 asan32: asan
159
160 .PHONY: tsan32
161 tsan32: EXTRA_FLAGS += -m32
162 tsan32: tsan
163
164 .PHONY: ubsan32
165 ubsan32: EXTRA_FLAGS += -m32
166 ubsan32: ubsan
167
168 # Run long round trip tests
169 .PHONY: roundtripcheck
170 roundtripcheck: roundtrip check
171 $(TESTPROG) ./test/RoundTripTest$(EXT) $(TESTFLAGS)
172
173 # Build the main binary
174 pzstd$(EXT): main.o $(PROGDIR)/util.o Options.o Pzstd.o SkippableFrame.o $(ZSTDDIR)/libzstd.a
175 $(LD_COMMAND)
176
177 # Target that depends on all the tests
178 .PHONY: tests
179 tests: EXTRA_FLAGS += -Wno-deprecated-declarations
180 tests: $(patsubst %,%$(EXT),$(basename $(PZSTD_TESTS) $(UTILS_TESTS)))
181
182 # Build the round trip tests
183 .PHONY: roundtrip
184 roundtrip: EXTRA_FLAGS += -Wno-deprecated-declarations
185 roundtrip: test/RoundTripTest$(EXT)
186
187 # Use the static library that zstd builds for simplicity and
188 # so we get the compiler options correct
189 $(ZSTDDIR)/libzstd.a: $(ZSTD_FILES)
190 CFLAGS="$(ALL_CFLAGS)" LDFLAGS="$(ALL_LDFLAGS)" $(MAKE) -C $(ZSTDDIR) libzstd.a
191
192 # Rules to build the tests
193 test/RoundTripTest$(EXT): test/RoundTripTest.o $(PROGDIR)/datagen.o \
194 $(PROGDIR)/util.o Options.o \
195 Pzstd.o SkippableFrame.o $(ZSTDDIR)/libzstd.a
196 $(LD_COMMAND)
197
198 test/%Test$(EXT): PZSTD_LDFLAGS += $(GTEST_LIB)
199 test/%Test$(EXT): LIBS += -lgtest -lgtest_main
200 test/%Test$(EXT): test/%Test.o $(PROGDIR)/datagen.o \
201 $(PROGDIR)/util.o Options.o Pzstd.o \
202 SkippableFrame.o $(ZSTDDIR)/libzstd.a
203 $(LD_COMMAND)
204
205 utils/test/%Test$(EXT): PZSTD_LDFLAGS += $(GTEST_LIB)
206 utils/test/%Test$(EXT): LIBS += -lgtest -lgtest_main
207 utils/test/%Test$(EXT): utils/test/%Test.o
208 $(LD_COMMAND)
209
210
211 GTEST_CMAKEFLAGS =
212
213 # Install googletest
214 .PHONY: googletest
215 googletest: PZSTD_CCXXFLAGS += -fPIC
216 googletest:
217 @$(RM) -rf googletest
218 @git clone https://github.com/google/googletest
219 @mkdir -p googletest/build
220 @cd googletest/build && cmake $(GTEST_CMAKEFLAGS) -DCMAKE_CXX_FLAGS="$(ALL_CXXFLAGS)" .. && $(MAKE)
221
222 .PHONY: googletest32
223 googletest32: PZSTD_CCXXFLAGS += -m32
224 googletest32: googletest
225
226 .PHONY: googletest-mingw64
227 googletest-mingw64: GTEST_CMAKEFLAGS += -G "MSYS Makefiles"
228 googletest-mingw64: googletest
229
230 .PHONY: clean
231 clean:
232 $(RM) -f *.o pzstd$(EXT) *.Td *.d
233 $(RM) -f test/*.o test/*Test$(EXT) test/*.Td test/*.d
234 $(RM) -f utils/test/*.o utils/test/*Test$(EXT) utils/test/*.Td utils/test/*.d
235 $(RM) -f $(PROGDIR)/*.o $(PROGDIR)/*.Td $(PROGDIR)/*.d
236 $(MAKE) -C $(ZSTDDIR) clean
237 @echo Cleaning completed
238
239
240 # Cancel implicit rules
241 %.o: %.c
242 %.o: %.cpp
243
244 # Object file rules
245 %.o: %.c
246 $(CC_COMMAND)
247 $(POSTCOMPILE)
248
249 $(PROGDIR)/%.o: $(PROGDIR)/%.c
250 $(CC_COMMAND)
251 $(POSTCOMPILE)
252
253 %.o: %.cpp
254 $(CXX_COMMAND)
255 $(POSTCOMPILE)
256
257 test/%.o: PZSTD_CPPFLAGS += $(GTEST_INC)
258 test/%.o: test/%.cpp
259 $(CXX_COMMAND)
260 $(POSTCOMPILE)
261
262 utils/test/%.o: PZSTD_CPPFLAGS += $(GTEST_INC)
263 utils/test/%.o: utils/test/%.cpp
264 $(CXX_COMMAND)
265 $(POSTCOMPILE)
266
267 # Dependency file stuff
268 .PRECIOUS: %.d test/%.d utils/test/%.d
269
270 # Include rules that specify header file dependencies
271 -include $(patsubst %,%.d,$(basename $(ALL_SRCS)))