1 # ################################################################
2 # Copyright (c) 2016-present, Facebook, Inc.
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 # ################################################################
10 # Standard variables for installation
13 BINDIR
:= $(DESTDIR
)$(PREFIX
)/bin
16 PROGDIR
= ..
/..
/programs
18 # External program to use to run tests, e.g. qemu or valgrind
20 # Flags to pass to the tests
23 # We use gcc/clang to generate the header dependencies of files
24 DEPFLAGS
= -MMD
-MP
-MF
$*.Td
25 POSTCOMPILE
= mv
-f
$*.Td
$*.d
27 # CFLAGS, CXXFLAGS, CPPFLAGS, and LDFLAGS are for the users to override
28 CFLAGS ?
= -O3
-Wall
-Wextra
29 CXXFLAGS ?
= -O3
-Wall
-Wextra
-pedantic
34 PZSTD_INC
= -I
$(ZSTDDIR
) -I
$(ZSTDDIR
)/common
-I
$(PROGDIR
) -I.
35 GTEST_INC
= -isystem googletest
/googletest
/include
37 PZSTD_CPPFLAGS
= $(PZSTD_INC
)
39 PZSTD_CFLAGS
= $(PZSTD_CCXXFLAGS
)
40 PZSTD_CXXFLAGS
= $(PZSTD_CCXXFLAGS
) -std
=c
++11
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
)
48 # gtest libraries need to go before "-lpthread" because they depend on it.
49 GTEST_LIB
= -L googletest
/build
/googlemock
/gtest
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
$@
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
) \
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
)
77 # Define *.exe as extension for Windows systems
78 ifneq (,$(filter Windows
%,$(OS
)))
89 test-pzstd
: TESTFLAGS
=--gtest_filter
=-*ExtremelyLarge
*
90 test-pzstd
: clean googletest pzstd tests
check
93 test-pzstd32
: clean googletest32 all32
check
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
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
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
)
117 install: PZSTD_CPPFLAGS
+= -DNDEBUG
119 install -d
-m
755 $(BINDIR
)/
120 install -m
755 pzstd
$(EXT
) $(BINDIR
)/pzstd
$(EXT
)
124 $(RM
) $(BINDIR
)/pzstd
$(EXT
)
126 # Targets for many different builds
128 all: PZSTD_CPPFLAGS
+= -DNDEBUG
132 debug
: EXTRA_FLAGS
+= -g
133 debug
: pzstd
$(EXT
) tests roundtrip
136 tsan
: PZSTD_CCXXFLAGS
+= -fsanitize
=thread
-fPIC
137 tsan
: PZSTD_LDFLAGS
+= -fsanitize
=thread
141 asan
: EXTRA_FLAGS
+= -fsanitize
=address
145 ubsan
: EXTRA_FLAGS
+= -fsanitize
=undefined
149 all32
: EXTRA_FLAGS
+= -m32
150 all32
: all tests roundtrip
153 debug32
: EXTRA_FLAGS
+= -m32
157 asan32
: EXTRA_FLAGS
+= -m32
161 tsan32
: EXTRA_FLAGS
+= -m32
165 ubsan32
: EXTRA_FLAGS
+= -m32
168 # Run long round trip tests
169 .PHONY
: roundtripcheck
170 roundtripcheck
: roundtrip
check
171 $(TESTPROG
) .
/test/RoundTripTest
$(EXT
) $(TESTFLAGS
)
173 # Build the main binary
174 pzstd
$(EXT
): main.o
$(PROGDIR
)/util.o Options.o Pzstd.o SkippableFrame.o
$(ZSTDDIR
)/libzstd.a
177 # Target that depends on all the tests
179 tests
: EXTRA_FLAGS
+= -Wno-deprecated-declarations
180 tests
: $(patsubst %,%$(EXT
),$(basename $(PZSTD_TESTS
) $(UTILS_TESTS
)))
182 # Build the round trip tests
184 roundtrip
: EXTRA_FLAGS
+= -Wno-deprecated-declarations
185 roundtrip
: test/RoundTripTest
$(EXT
)
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
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
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
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
215 googletest
: PZSTD_CCXXFLAGS
+= -fPIC
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
)
223 googletest32
: PZSTD_CCXXFLAGS
+= -m32
224 googletest32
: googletest
226 .PHONY
: googletest-mingw64
227 googletest-mingw64
: GTEST_CMAKEFLAGS
+= -G
"MSYS Makefiles"
228 googletest-mingw64
: googletest
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
240 # Cancel implicit rules
249 $(PROGDIR
)/%.o
: $(PROGDIR
)/%.c
257 test/%.o
: PZSTD_CPPFLAGS
+= $(GTEST_INC
)
262 utils
/test/%.o
: PZSTD_CPPFLAGS
+= $(GTEST_INC
)
263 utils
/test/%.o
: utils
/test/%.
cpp
267 # Dependency file stuff
268 .PRECIOUS
: %.d
test/%.d utils
/test/%.d
270 # Include rules that specify header file dependencies
271 -include $(patsubst %,%.d
,$(basename $(ALL_SRCS
)))