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 20, 2021
1 parent 12c045f commit ee5e17e
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 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 @@ -292,16 +295,20 @@ libzstd : $(LIBZSTD)

.PHONY: lib
lib : libzstd.a libzstd
@if [ $(ZSTD_NO_MULTITHREAD) = 1 ]; then \
echo "multithreading disabled"; \
else \
echo "multithreading enabled"; \
fi

# multithreading enabled by default unless otherwise specified
ifneq ($(ZSTD_NO_MULTITHREAD), 1)
CPPFLAGS += -DZSTD_MULTITHREAD
LDFLAGS += -pthread
endif


# note : do not define lib-mt or lib-release as .PHONY
# note : do not define 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

%-release : DEBUGFLAGS :=
%-release : %
@echo release build completed
Expand Down Expand Up @@ -332,11 +339,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

0 comments on commit ee5e17e

Please sign in to comment.