Skip to content

Commit

Permalink
Update lib Makefile to have new targets
Browse files Browse the repository at this point in the history
  • Loading branch information
senhuang42 committed Apr 28, 2021
1 parent 333dd60 commit d9df6b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions 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,12 +356,13 @@ 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 -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
endif


#------------------------------------------------------------------------
# target specific tests
#------------------------------------------------------------------------
Expand Down
34 changes: 30 additions & 4 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# You may select, at your option, one of the above-listed licenses.
# ################################################################

# Note: by default, the dynamic library is built single-threaded and static library is built
# multi-threaded. It is possible to force multi or single threaded builds by appending
# -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
.PHONY: default
default: lib-release

Expand Down Expand Up @@ -166,6 +169,14 @@ endif
endif
CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)

CPPFLAGS_MT := $(CPPFLAGS) -DZSTD_MULTITHREAD
CPPFLAGS_NOMT := $(CPPFLAGS)
CPPFLAGS_DYNLIB := $(CPPFLAGS_MT) # dynamic library build defaults to multithreading

LDFLAGS_MT := $(LDFLAGS) -pthread
LDFLAGS_NOMT := $(LDFLAGS)
LDFLAGS_DYNLIB := $(LDFLAGS_MT)

ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES))
ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o)

Expand Down Expand Up @@ -238,7 +249,11 @@ ZSTD_STATLIB_OBJ := $(addprefix $(ZSTD_STATLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
$(ZSTD_STATLIB): ARFLAGS = rcs
$(ZSTD_STATLIB): | $(ZSTD_STATLIB_DIR)
$(ZSTD_STATLIB): $(ZSTD_STATLIB_OBJ)
@echo compiling static library
ifneq (,$(findstring -DZSTD_MULTITHREAD,$(CPPFLAGS)))
@echo compiling multi-threaded static library $(LIBVER)
else
@echo compiling single-threaded static library $(LIBVER)
endif
$(AR) $(ARFLAGS) $@ $^

libzstd.a: $(ZSTD_STATLIB)
Expand All @@ -257,7 +272,9 @@ else # not Windows

LIBZSTD = libzstd.$(SHARED_EXT_VER)
.PHONY: $(LIBZSTD) # must be run every time
$(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
$(LIBZSTD): CPPFLAGS = $(CPPFLAGS_DYNLIB)
$(LIBZSTD): LDFLAGS = $(LDFLAGS_DYNLIB)
$(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
$(LIBZSTD): LDFLAGS += -shared

ifndef BUILD_DIR
Expand All @@ -275,7 +292,11 @@ ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/,$(ZSTD_LOCAL_OBJ))

$(ZSTD_DYNLIB): | $(ZSTD_DYNLIB_DIR)
$(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ)
@echo compiling dynamic library $(LIBVER)
ifneq (,$(findstring -DZSTD_MULTITHREAD,$(CPPFLAGS)))
@echo compiling multi-threaded dynamic library $(LIBVER)
else
@echo compiling single-threaded dynamic library $(LIBVER)
endif
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
@echo creating versioned links
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
Expand All @@ -300,7 +321,12 @@ lib : libzstd.a libzstd
%-mt : CPPFLAGS += -DZSTD_MULTITHREAD
%-mt : LDFLAGS += -pthread
%-mt : %
@echo multi-threading build completed
@echo multi-threaded build completed

%-nomt : CPPFLAGS_DYNLIB := $(CPPFLAGS_NOMT)
%-nomt : LDFLAGS_DYNLIB := $(LDFLAGS_NOMT)
%-nomt : %
@echo single-threaded build completed

%-release : DEBUGFLAGS :=
%-release : %
Expand Down

0 comments on commit d9df6b4

Please sign in to comment.