minor Makefile refactor
hopefully improving readability
This commit is contained in:
parent
59ab4dcd32
commit
f6ecf1568f
61
lib/Makefile
61
lib/Makefile
@ -15,12 +15,9 @@ default: lib-release
|
|||||||
$(V)$(VERBOSE).SILENT:
|
$(V)$(VERBOSE).SILENT:
|
||||||
|
|
||||||
# When cross-compiling from linux to windows,
|
# When cross-compiling from linux to windows,
|
||||||
# you might need to specify this as "Windows."
|
# one might need to specify TARGET_SYSTEM as "Windows."
|
||||||
# Fedora build fails without it.
|
# Building from Fedora fails without it.
|
||||||
#
|
# (but Ubuntu and Debian don't need to set anything)
|
||||||
# Note: mingw-w64 build from linux to windows
|
|
||||||
# does not fail on other tested distros (ubuntu, debian)
|
|
||||||
# even without manually specifying the TARGET_SYSTEM.
|
|
||||||
TARGET_SYSTEM ?= $(OS)
|
TARGET_SYSTEM ?= $(OS)
|
||||||
|
|
||||||
# Version numbers
|
# Version numbers
|
||||||
@ -35,8 +32,8 @@ LIBVER := $(shell echo $(LIBVER_SCRIPT))
|
|||||||
VERSION?= $(LIBVER)
|
VERSION?= $(LIBVER)
|
||||||
CCVER := $(shell $(CC) --version)
|
CCVER := $(shell $(CC) --version)
|
||||||
|
|
||||||
# This is a helper variable that configures a bunch of other variables to new,
|
# ZSTD_LIB_MINIFY is a helper variable that
|
||||||
# space-optimized defaults.
|
# configures a bunch of other variables to space-optimized defaults.
|
||||||
ZSTD_LIB_MINIFY ?= 0
|
ZSTD_LIB_MINIFY ?= 0
|
||||||
ifneq ($(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)
|
HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
|
||||||
@ -177,9 +174,7 @@ vpath %.c $(ZSTD_SUBDIR)
|
|||||||
|
|
||||||
UNAME := $(shell uname)
|
UNAME := $(shell uname)
|
||||||
|
|
||||||
BUILD_DIR ?= 0
|
ifndef BUILD_DIR
|
||||||
|
|
||||||
ifeq ($(BUILD_DIR),0)
|
|
||||||
ifeq ($(UNAME), Darwin)
|
ifeq ($(UNAME), Darwin)
|
||||||
HASH ?= md5
|
HASH ?= md5
|
||||||
else ifeq ($(UNAME), FreeBSD)
|
else ifeq ($(UNAME), FreeBSD)
|
||||||
@ -195,7 +190,7 @@ ifeq ($(HAVE_HASH),0)
|
|||||||
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
|
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
|
||||||
BUILD_DIR := obj/generic_noconf
|
BUILD_DIR := obj/generic_noconf
|
||||||
endif
|
endif
|
||||||
endif # $(BUILD_DIR) == 0
|
endif # BUILD_DIR
|
||||||
|
|
||||||
|
|
||||||
# macOS linker doesn't support -soname, and use different extension
|
# macOS linker doesn't support -soname, and use different extension
|
||||||
@ -212,27 +207,31 @@ else
|
|||||||
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
|
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
|
||||||
endif
|
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
|
.PHONY: lib-all all clean install uninstall
|
||||||
|
|
||||||
default: lib-release
|
|
||||||
|
|
||||||
# alias
|
# alias
|
||||||
lib-all: all
|
lib-all: all
|
||||||
|
|
||||||
all: lib
|
all: lib
|
||||||
|
|
||||||
ifeq ($(BUILD_DIR),0)
|
.PHONY: libzstd.a # must be run every time
|
||||||
# determine a BUILD_DIR
|
|
||||||
|
ifndef BUILD_DIR
|
||||||
|
# determine BUILD_DIR from compilation flags
|
||||||
|
|
||||||
.PHONY: libzstd.a # not the actual recipe
|
|
||||||
libzstd.a:
|
libzstd.a:
|
||||||
$(MAKE) --no-print-directory $@ \
|
$(SET_CACHE_DIRECTORY)
|
||||||
BUILD_DIR=obj/$(HASH_DIR) \
|
|
||||||
CPPFLAGS="$(CPPFLAGS)"
|
|
||||||
|
|
||||||
else
|
else
|
||||||
# $(BUILD_DIR) is defined
|
# BUILD_DIR is defined
|
||||||
|
|
||||||
ZSTD_STATLIB_DIR := $(BUILD_DIR)/static
|
ZSTD_STATLIB_DIR := $(BUILD_DIR)/static
|
||||||
ZSTD_STATLIB := $(ZSTD_STATLIB_DIR)/libzstd.a
|
ZSTD_STATLIB := $(ZSTD_STATLIB_DIR)/libzstd.a
|
||||||
@ -243,7 +242,6 @@ $(ZSTD_STATLIB): $(ZSTD_STATLIB_OBJ)
|
|||||||
@echo compiling static library
|
@echo compiling static library
|
||||||
$(AR) $(ARFLAGS) $@ $^
|
$(AR) $(ARFLAGS) $@ $^
|
||||||
|
|
||||||
.PHONY: libzstd.a # must be run every time
|
|
||||||
libzstd.a: $(ZSTD_STATLIB)
|
libzstd.a: $(ZSTD_STATLIB)
|
||||||
ln -sf $< $@
|
ln -sf $< $@
|
||||||
|
|
||||||
@ -256,25 +254,21 @@ $(LIBZSTD): $(ZSTD_FILES)
|
|||||||
@echo compiling dynamic library $(LIBVER)
|
@echo compiling dynamic library $(LIBVER)
|
||||||
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
|
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
|
||||||
|
|
||||||
else
|
else # not Windows
|
||||||
|
|
||||||
LIBZSTD = libzstd.$(SHARED_EXT_VER)
|
LIBZSTD = libzstd.$(SHARED_EXT_VER)
|
||||||
|
.PHONY: $(LIBZSTD) # must be run every time
|
||||||
$(LIBZSTD): CFLAGS += -fPIC
|
$(LIBZSTD): CFLAGS += -fPIC
|
||||||
$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
|
$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
|
||||||
|
|
||||||
ifeq ($(BUILD_DIR),0)
|
ifndef BUILD_DIR
|
||||||
# determine a BUILD_DIR
|
# determine BUILD_DIR from compilation flags
|
||||||
|
|
||||||
.PHONY: $(LIBZSTD) # not the actual recipe
|
|
||||||
$(LIBZSTD):
|
$(LIBZSTD):
|
||||||
$(MAKE) --no-print-directory $@ \
|
$(SET_CACHE_DIRECTORY)
|
||||||
BUILD_DIR=obj/$(HASH_DIR) \
|
|
||||||
CPPFLAGS="$(CPPFLAGS)" \
|
|
||||||
CFLAGS="$(CFLAGS)" \
|
|
||||||
LDFLAGS="$(LDFLAGS)"
|
|
||||||
|
|
||||||
else
|
else
|
||||||
# $(BUILD_DIR) is defined
|
# BUILD_DIR is defined
|
||||||
|
|
||||||
ZSTD_DYNLIB_DIR := $(BUILD_DIR)/dynamic
|
ZSTD_DYNLIB_DIR := $(BUILD_DIR)/dynamic
|
||||||
ZSTD_DYNLIB := $(ZSTD_DYNLIB_DIR)/$(LIBZSTD)
|
ZSTD_DYNLIB := $(ZSTD_DYNLIB_DIR)/$(LIBZSTD)
|
||||||
@ -288,11 +282,10 @@ $(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ)
|
|||||||
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
|
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
|
||||||
ln -sf $@ libzstd.$(SHARED_EXT)
|
ln -sf $@ libzstd.$(SHARED_EXT)
|
||||||
|
|
||||||
.PHONY: $(LIBZSTD) # must be run every time
|
|
||||||
$(LIBZSTD): $(ZSTD_DYNLIB)
|
$(LIBZSTD): $(ZSTD_DYNLIB)
|
||||||
ln -sf $< $@
|
ln -sf $< $@
|
||||||
|
|
||||||
endif # if BUILD_DIR
|
endif # ifndef BUILD_DIR
|
||||||
endif # if windows
|
endif # if windows
|
||||||
|
|
||||||
.PHONY: libzstd
|
.PHONY: libzstd
|
||||||
|
@ -98,9 +98,8 @@ ZSTD_ALL_SRC := $(ZSTDLIB_LOCAL_SRC) $(ZSTD_CLI_SRC)
|
|||||||
ZSTD_ALL_OBJ := $(ZSTD_ALL_SRC:.c=.o)
|
ZSTD_ALL_OBJ := $(ZSTD_ALL_SRC:.c=.o)
|
||||||
|
|
||||||
UNAME := $(shell uname)
|
UNAME := $(shell uname)
|
||||||
BUILD_DIR ?= 0
|
|
||||||
|
|
||||||
ifeq ($(BUILD_DIR),0)
|
ifndef BUILD_DIR
|
||||||
ifeq ($(UNAME), Darwin)
|
ifeq ($(UNAME), Darwin)
|
||||||
HASH ?= md5
|
HASH ?= md5
|
||||||
else ifeq ($(UNAME), FreeBSD)
|
else ifeq ($(UNAME), FreeBSD)
|
||||||
@ -116,7 +115,7 @@ ifeq ($(HAVE_HASH),0)
|
|||||||
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
|
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
|
||||||
BUILD_DIR := obj/generic_noconf
|
BUILD_DIR := obj/generic_noconf
|
||||||
endif
|
endif
|
||||||
endif # $(BUILD_DIR) == 0
|
endif # BUILD_DIR
|
||||||
|
|
||||||
# Define *.exe as extension for Windows systems
|
# Define *.exe as extension for Windows systems
|
||||||
ifneq (,$(filter Windows%,$(OS)))
|
ifneq (,$(filter Windows%,$(OS)))
|
||||||
@ -193,6 +192,13 @@ ifeq ($(BACKTRACE), 1)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
SET_CACHE_DIRECTORY = \
|
||||||
|
$(MAKE) --no-print-directory $@ \
|
||||||
|
BUILD_DIR=obj/$(HASH_DIR) \
|
||||||
|
CPPFLAGS="$(CPPFLAGS)" \
|
||||||
|
CFLAGS="$(CFLAGS)" \
|
||||||
|
LDFLAGS="$(LDFLAGS)"
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: zstd
|
all: zstd
|
||||||
@ -200,6 +206,23 @@ all: zstd
|
|||||||
.PHONY: allVariants
|
.PHONY: allVariants
|
||||||
allVariants: zstd zstd-compress zstd-decompress zstd-small zstd-nolegacy zstd-dictBuilder
|
allVariants: zstd zstd-compress zstd-decompress zstd-small zstd-nolegacy zstd-dictBuilder
|
||||||
|
|
||||||
|
.PHONY: zstd # must always be run
|
||||||
|
zstd : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP)
|
||||||
|
zstd : LDFLAGS += $(THREAD_LD) $(ZLIBLD) $(LZMALD) $(LZ4LD) $(DEBUGFLAGS_LD)
|
||||||
|
zstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
||||||
|
ifneq (,$(filter Windows%,$(OS)))
|
||||||
|
zstd : $(RES_FILE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifndef BUILD_DIR
|
||||||
|
# generate BUILD_DIR from flags
|
||||||
|
|
||||||
|
zstd:
|
||||||
|
$(SET_CACHE_DIRECTORY)
|
||||||
|
|
||||||
|
else
|
||||||
|
# BUILD_DIR is defined
|
||||||
|
|
||||||
ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ))
|
ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ))
|
||||||
$(BUILD_DIR)/zstd : $(ZSTD_OBJ)
|
$(BUILD_DIR)/zstd : $(ZSTD_OBJ)
|
||||||
@echo "$(THREAD_MSG)"
|
@echo "$(THREAD_MSG)"
|
||||||
@ -209,32 +232,11 @@ $(BUILD_DIR)/zstd : $(ZSTD_OBJ)
|
|||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
$(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS)
|
$(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 : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
|
||||||
ifneq (,$(filter Windows%,$(OS)))
|
|
||||||
zstd : $(RES_FILE)
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(BUILD_DIR),0)
|
|
||||||
# generate a BUILD_DIR from flags
|
|
||||||
|
|
||||||
zstd:
|
|
||||||
$(MAKE) --no-print-directory $@ \
|
|
||||||
BUILD_DIR=obj/$(HASH_DIR) \
|
|
||||||
CPPFLAGS="$(CPPFLAGS)" \
|
|
||||||
CFLAGS="$(CFLAGS)" \
|
|
||||||
LDFLAGS="$(LDFLAGS)"
|
|
||||||
|
|
||||||
else
|
|
||||||
# BUILD_DIR is defined
|
|
||||||
|
|
||||||
zstd : $(BUILD_DIR)/zstd
|
zstd : $(BUILD_DIR)/zstd
|
||||||
ln -sf $< $@
|
ln -sf $< $@
|
||||||
@echo zstd build completed
|
@echo zstd build completed
|
||||||
|
|
||||||
endif
|
endif # BUILD_DIR
|
||||||
|
|
||||||
|
|
||||||
.PHONY: zstd-release
|
.PHONY: zstd-release
|
||||||
|
Loading…
x
Reference in New Issue
Block a user