Skip to content

Commit

Permalink
Enable multithreading in lib build by default
Browse files Browse the repository at this point in the history
  • Loading branch information
senhuang42 committed Apr 26, 2021
1 parent 12c045f commit 401d767
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ clean:
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT Haiku))

HOST_OS = POSIX
CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON -DCMAKE_BUILD_TYPE=Release

HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
EGREP_OPTIONS ?=
Expand Down Expand Up @@ -357,6 +356,8 @@ lz4install:
endif


CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON -DZSTD_MULTITHREAD_SUPPORT:BOOL=ON -DCMAKE_BUILD_TYPE=Release

ifneq (,$(filter MSYS%,$(shell uname)))
HOST_OS = MSYS
CMAKE_PARAMS = -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
Expand Down
4 changes: 4 additions & 0 deletions contrib/largeNbDicts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
-Wredundant-decls
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)

ifneq ($(ZSTD_NO_MULTITHREAD), 1)
CPPFLAGS += -DZSTD_MULTITHREAD
LDFLAGS += -pthread
endif

default: largeNbDicts

Expand Down
5 changes: 5 additions & 0 deletions contrib/seekable_format/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ CPPFLAGS += -I../ -I../../../lib -I../../../lib/common
CFLAGS ?= -O3
CFLAGS += -g

ifneq ($(ZSTD_NO_MULTITHREAD), 1)
CPPFLAGS += -DZSTD_MULTITHREAD
LDFLAGS += -pthread
endif

SEEKABLE_OBJS = ../zstdseek_compress.c ../zstdseek_decompress.c $(ZSTDLIB)

.PHONY: default all clean test
Expand Down
5 changes: 5 additions & 0 deletions contrib/seekable_format/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ CFLAGS ?= -O3
CFLAGS += -g -Wall -Wextra -Wcast-qual -Wcast-align -Wconversion \
-Wformat=2 -Wstrict-aliasing=1

ifneq ($(ZSTD_NO_MULTITHREAD), 1)
CPPFLAGS += -DZSTD_MULTITHREAD
LDFLAGS += -pthread
endif

SEEKABLE_OBJS = ../zstdseek_compress.c ../zstdseek_decompress.c $(ZSTDLIB)

.PHONY: default clean test
Expand Down
29 changes: 21 additions & 8 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ LIBVER := $(shell echo $(LIBVER_SCRIPT))
VERSION?= $(LIBVER)
CCVER := $(shell $(CC) --version)

# Multithreading can be forcibly disabled
ZSTD_NO_MULTITHREAD ?= 0

# ZSTD_LIB_MINIFY is a helper variable that
# configures a bunch of other variables to space-optimized defaults.
ZSTD_LIB_MINIFY ?= 0
Expand Down Expand Up @@ -287,21 +290,29 @@ $(LIBZSTD): $(ZSTD_DYNLIB)
endif # ifndef BUILD_DIR
endif # if windows

ZSTD_MULTITHREAD_MSG = multithreading enabled
ifeq ($(ZSTD_NO_MULTITHREAD), 1)
ZSTD_MULTITHREAD_MSG = multithreading disabled
endif

.PHONY: libzstd
libzstd : $(LIBZSTD)

.PHONY: lib
lib : libzstd.a libzstd
@echo $(ZSTD_MULTITHREAD_MSG)

%-mt : % # kept for compatibility
@echo -mt is redundant, multithreading is enabled by default with 1.5.0

# note : do not define lib-mt or lib-release as .PHONY
# make does not consider implicit pattern rule for .PHONY target

%-mt : CPPFLAGS += -DZSTD_MULTITHREAD
%-mt : LDFLAGS += -pthread
%-mt : %
@echo multi-threading build completed
# multithreading enabled by default unless otherwise specified
ifneq ($(ZSTD_NO_MULTITHREAD), 1)
CPPFLAGS += -DZSTD_MULTITHREAD
LDFLAGS += -pthread
endif

# note : do not define lib-release as .PHONY
# make does not consider implicit pattern rule for .PHONY target
%-release : DEBUGFLAGS :=
%-release : %
@echo release build completed
Expand Down Expand Up @@ -332,11 +343,13 @@ include $(wildcard $(DEPFILES))
# Special case : building library in single-thread mode _and_ without zstdmt_compress.c
ZSTDMT_FILES = compress/zstdmt_compress.c
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
ZSTD_NOMT_FLAGS = $(filter-out -DZSTD_MULTITHREAD,$(FLAGS))
ZSTD_NOMT_LDFLAGS = $(filter-out -pthread,$(LDFLAGS))
libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
libzstd-nomt: $(ZSTD_NOMT_FILES)
@echo compiling single-thread dynamic library $(LIBVER)
@echo files : $(ZSTD_NOMT_FILES)
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
$(CC) $(ZSTD_NOMT_FLAGS) $^ $(ZSTD_NOMT_LDFLAGS) $(SONAME_FLAGS) -o $@

.PHONY: clean
clean:
Expand Down
5 changes: 5 additions & 0 deletions zlibWrapper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ TEST_FILE = ../doc/zstd_compression_format.md

vpath %.c $(PROGRAMS_PATH) $(EXAMPLE_PATH) $(ZLIBWRAPPER_PATH)

ZSTD_NO_MULTITHREAD ?= 0
ifneq ($(ZSTD_NO_MULTITHREAD), 1)
CPPFLAGS += -DZSTD_MULTITHREAD
LDFLAGS += -pthread
endif

CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -I$(ZLIB_PATH) -I$(PROGRAMS_PATH) \
-I$(ZSTDLIBDIR) -I$(ZSTDLIBDIR)/common -I$(ZLIBWRAPPER_PATH)
Expand Down

0 comments on commit 401d767

Please sign in to comment.