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 2e14b4b
Showing 1 changed file with 30 additions and 4 deletions.
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 2e14b4b

Please sign in to comment.