$(V)$(VERBOSE).SILENT:
# When cross-compiling from linux to windows,
-# you might need to specify this as "Windows."
-# Fedora build fails without it.
-#
-# Note: mingw-w64 build from linux to windows
-# does not fail on other tested distros (ubuntu, debian)
-# even without manually specifying the TARGET_SYSTEM.
+# one might need to specify TARGET_SYSTEM as "Windows."
+# Building from Fedora fails without it.
+# (but Ubuntu and Debian don't need to set anything)
TARGET_SYSTEM ?= $(OS)
# Version numbers
VERSION?= $(LIBVER)
CCVER := $(shell $(CC) --version)
-# This is a helper variable that configures a bunch of other variables to new,
-# space-optimized defaults.
+# ZSTD_LIB_MINIFY is a helper variable that
+# configures a bunch of other variables to space-optimized defaults.
ZSTD_LIB_MINIFY ?= 0
ifneq ($(ZSTD_LIB_MINIFY), 0)
HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
UNAME := $(shell uname)
-BUILD_DIR ?= 0
-
-ifeq ($(BUILD_DIR),0)
+ifndef BUILD_DIR
ifeq ($(UNAME), Darwin)
HASH ?= md5
else ifeq ($(UNAME), FreeBSD)
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
BUILD_DIR := obj/generic_noconf
endif
-endif # $(BUILD_DIR) == 0
+endif # BUILD_DIR
# macOS linker doesn't support -soname, and use different extension
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
endif
+SET_CACHE_DIRECTORY = \
+ $(MAKE) --no-print-directory $@ \
+ BUILD_DIR=obj/$(HASH_DIR) \
+ CPPFLAGS="$(CPPFLAGS)" \
+ CFLAGS="$(CFLAGS)" \
+ LDFLAGS="$(LDFLAGS)"
-.PHONY: lib-all all clean install uninstall
-default: lib-release
+.PHONY: lib-all all clean install uninstall
# alias
lib-all: all
all: lib
-ifeq ($(BUILD_DIR),0)
-# determine a BUILD_DIR
+.PHONY: libzstd.a # must be run every time
+
+ifndef BUILD_DIR
+# determine BUILD_DIR from compilation flags
-.PHONY: libzstd.a # not the actual recipe
libzstd.a:
- $(MAKE) --no-print-directory $@ \
- BUILD_DIR=obj/$(HASH_DIR) \
- CPPFLAGS="$(CPPFLAGS)"
+ $(SET_CACHE_DIRECTORY)
else
-# $(BUILD_DIR) is defined
+# BUILD_DIR is defined
ZSTD_STATLIB_DIR := $(BUILD_DIR)/static
ZSTD_STATLIB := $(ZSTD_STATLIB_DIR)/libzstd.a
@echo compiling static library
$(AR) $(ARFLAGS) $@ $^
-.PHONY: libzstd.a # must be run every time
libzstd.a: $(ZSTD_STATLIB)
ln -sf $< $@
@echo compiling dynamic library $(LIBVER)
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
-else
+else # not Windows
LIBZSTD = libzstd.$(SHARED_EXT_VER)
+.PHONY: $(LIBZSTD) # must be run every time
$(LIBZSTD): CFLAGS += -fPIC
$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
-ifeq ($(BUILD_DIR),0)
-# determine a BUILD_DIR
+ifndef BUILD_DIR
+# determine BUILD_DIR from compilation flags
-.PHONY: $(LIBZSTD) # not the actual recipe
$(LIBZSTD):
- $(MAKE) --no-print-directory $@ \
- BUILD_DIR=obj/$(HASH_DIR) \
- CPPFLAGS="$(CPPFLAGS)" \
- CFLAGS="$(CFLAGS)" \
- LDFLAGS="$(LDFLAGS)"
+ $(SET_CACHE_DIRECTORY)
else
-# $(BUILD_DIR) is defined
+# BUILD_DIR is defined
ZSTD_DYNLIB_DIR := $(BUILD_DIR)/dynamic
ZSTD_DYNLIB := $(ZSTD_DYNLIB_DIR)/$(LIBZSTD)
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
ln -sf $@ libzstd.$(SHARED_EXT)
-.PHONY: $(LIBZSTD) # must be run every time
$(LIBZSTD): $(ZSTD_DYNLIB)
ln -sf $< $@
-endif # if BUILD_DIR
+endif # ifndef BUILD_DIR
endif # if windows
.PHONY: libzstd
ZSTD_ALL_OBJ := $(ZSTD_ALL_SRC:.c=.o)
UNAME := $(shell uname)
-BUILD_DIR ?= 0
-ifeq ($(BUILD_DIR),0)
+ifndef BUILD_DIR
ifeq ($(UNAME), Darwin)
HASH ?= md5
else ifeq ($(UNAME), FreeBSD)
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
BUILD_DIR := obj/generic_noconf
endif
-endif # $(BUILD_DIR) == 0
+endif # BUILD_DIR
# Define *.exe as extension for Windows systems
ifneq (,$(filter Windows%,$(OS)))
endif
endif
+SET_CACHE_DIRECTORY = \
+ $(MAKE) --no-print-directory $@ \
+ BUILD_DIR=obj/$(HASH_DIR) \
+ CPPFLAGS="$(CPPFLAGS)" \
+ CFLAGS="$(CFLAGS)" \
+ LDFLAGS="$(LDFLAGS)"
+
.PHONY: all
all: zstd
.PHONY: allVariants
allVariants: zstd zstd-compress zstd-decompress zstd-small zstd-nolegacy zstd-dictBuilder
-ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ))
-$(BUILD_DIR)/zstd : $(ZSTD_OBJ)
- @echo "$(THREAD_MSG)"
- @echo "$(ZLIB_MSG)"
- @echo "$(LZMA_MSG)"
- @echo "$(LZ4_MSG)"
- @echo LINK $@
- $(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS)
-
.PHONY: zstd # must always be run
zstd : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP)
zstd : LDFLAGS += $(THREAD_LD) $(ZLIBLD) $(LZMALD) $(LZ4LD) $(DEBUGFLAGS_LD)
zstd : $(RES_FILE)
endif
-ifeq ($(BUILD_DIR),0)
-# generate a BUILD_DIR from flags
+ifndef BUILD_DIR
+# generate BUILD_DIR from flags
zstd:
- $(MAKE) --no-print-directory $@ \
- BUILD_DIR=obj/$(HASH_DIR) \
- CPPFLAGS="$(CPPFLAGS)" \
- CFLAGS="$(CFLAGS)" \
- LDFLAGS="$(LDFLAGS)"
+ $(SET_CACHE_DIRECTORY)
else
# BUILD_DIR is defined
+ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ))
+$(BUILD_DIR)/zstd : $(ZSTD_OBJ)
+ @echo "$(THREAD_MSG)"
+ @echo "$(ZLIB_MSG)"
+ @echo "$(LZMA_MSG)"
+ @echo "$(LZ4_MSG)"
+ @echo LINK $@
+ $(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS)
+
zstd : $(BUILD_DIR)/zstd
ln -sf $< $@
@echo zstd build completed
-endif
+endif # BUILD_DIR
.PHONY: zstd-release