]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/zstd/contrib/pzstd/Makefile
Update to Zstandard 1.3.8
[FreeBSD/FreeBSD.git] / sys / contrib / 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 Options.o \
194                           Pzstd.o SkippableFrame.o $(ZSTDDIR)/libzstd.a
195         $(LD_COMMAND)
196
197 test/%Test$(EXT): PZSTD_LDFLAGS += $(GTEST_LIB)
198 test/%Test$(EXT): LIBS += -lgtest -lgtest_main
199 test/%Test$(EXT): test/%Test.o $(PROGDIR)/datagen.o Options.o Pzstd.o  \
200                   SkippableFrame.o $(ZSTDDIR)/libzstd.a
201         $(LD_COMMAND)
202
203 utils/test/%Test$(EXT): PZSTD_LDFLAGS += $(GTEST_LIB)
204 utils/test/%Test$(EXT): LIBS += -lgtest -lgtest_main
205 utils/test/%Test$(EXT): utils/test/%Test.o
206         $(LD_COMMAND)
207
208
209 GTEST_CMAKEFLAGS =
210
211 # Install googletest
212 .PHONY: googletest
213 googletest: PZSTD_CCXXFLAGS += -fPIC
214 googletest:
215         @$(RM) -rf googletest
216         @git clone https://github.com/google/googletest
217         @mkdir -p googletest/build
218         @cd googletest/build && cmake $(GTEST_CMAKEFLAGS) -DCMAKE_CXX_FLAGS="$(ALL_CXXFLAGS)" .. && $(MAKE)
219
220 .PHONY: googletest32
221 googletest32: PZSTD_CCXXFLAGS  += -m32
222 googletest32: googletest
223
224 .PHONY: googletest-mingw64
225 googletest-mingw64: GTEST_CMAKEFLAGS += -G "MSYS Makefiles"
226 googletest-mingw64: googletest
227
228 .PHONY: clean
229 clean:
230         $(RM) -f *.o pzstd$(EXT) *.Td *.d
231         $(RM) -f test/*.o test/*Test$(EXT) test/*.Td test/*.d
232         $(RM) -f utils/test/*.o utils/test/*Test$(EXT) utils/test/*.Td utils/test/*.d
233         $(RM) -f $(PROGDIR)/*.o $(PROGDIR)/*.Td $(PROGDIR)/*.d
234         $(MAKE) -C $(ZSTDDIR) clean
235         @echo Cleaning completed
236
237
238 # Cancel implicit rules
239 %.o: %.c
240 %.o: %.cpp
241
242 # Object file rules
243 %.o: %.c
244         $(CC_COMMAND)
245         $(POSTCOMPILE)
246
247 $(PROGDIR)/%.o: $(PROGDIR)/%.c
248         $(CC_COMMAND)
249         $(POSTCOMPILE)
250
251 %.o: %.cpp
252         $(CXX_COMMAND)
253         $(POSTCOMPILE)
254
255 test/%.o: PZSTD_CPPFLAGS += $(GTEST_INC)
256 test/%.o: test/%.cpp
257         $(CXX_COMMAND)
258         $(POSTCOMPILE)
259
260 utils/test/%.o: PZSTD_CPPFLAGS += $(GTEST_INC)
261 utils/test/%.o: utils/test/%.cpp
262         $(CXX_COMMAND)
263         $(POSTCOMPILE)
264
265 # Dependency file stuff
266 .PRECIOUS: %.d test/%.d utils/test/%.d
267
268 # Include rules that specify header file dependencies
269 -include $(patsubst %,%.d,$(basename $(ALL_SRCS)))