2015-01-23 16:58:16 -08:00
|
|
|
# ##########################################################################
|
2017-01-01 18:22:18 -08:00
|
|
|
# Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
|
2016-08-30 13:33:20 -07:00
|
|
|
# All rights reserved.
|
2015-01-23 16:58:16 -08:00
|
|
|
#
|
2017-01-17 03:40:06 -08:00
|
|
|
# This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
|
|
|
|
#
|
2016-08-30 13:33:20 -07:00
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
2015-01-23 16:58:16 -08:00
|
|
|
# ##########################################################################
|
|
|
|
# zstd : Command Line Utility, supporting gzip-like arguments
|
2016-08-18 04:18:11 -07:00
|
|
|
# zstd32 : Same as zstd, but forced to compile in 32-bits mode
|
|
|
|
# zstd_nolegacy : zstd without support of decompression of legacy versions
|
2016-08-25 01:07:20 -07:00
|
|
|
# zstd-small : minimal zstd without dictionary builder and benchmark
|
|
|
|
# zstd-compress : compressor-only version of zstd
|
|
|
|
# zstd-decompress : decompressor-only version of zstd
|
2015-01-23 16:58:16 -08:00
|
|
|
# ##########################################################################
|
|
|
|
|
2016-05-28 16:39:19 -07:00
|
|
|
ZSTDDIR = ../lib
|
|
|
|
|
2017-03-16 15:33:21 -07:00
|
|
|
# Version numbers
|
|
|
|
LIBVER_SRC := $(ZSTDDIR)/zstd.h
|
|
|
|
LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
|
|
|
|
LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
|
|
|
|
LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
|
|
|
|
LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
|
|
|
|
LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
|
|
|
|
LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
|
|
|
|
LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
|
|
|
|
LIBVER := $(shell echo $(LIBVER_SCRIPT))
|
|
|
|
|
|
|
|
ZSTD_VERSION=$(LIBVER)
|
|
|
|
|
2016-07-21 18:36:50 -07:00
|
|
|
ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version "), 1)
|
|
|
|
ALIGN_LOOP = -falign-loops=32
|
|
|
|
else
|
|
|
|
ALIGN_LOOP =
|
|
|
|
endif
|
|
|
|
|
2017-03-01 21:02:06 -08:00
|
|
|
CPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
|
|
|
|
-I$(ZSTDDIR)/dictBuilder \
|
|
|
|
-DXXH_NAMESPACE=ZSTD_ # because xxhash.o already compiled with this macro from library
|
2016-12-02 12:40:57 -08:00
|
|
|
CFLAGS ?= -O3
|
2017-02-02 20:54:14 -08:00
|
|
|
DEBUGFLAGS = -g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
|
|
|
|
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
|
2017-03-05 21:17:32 -08:00
|
|
|
-Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security
|
2017-02-02 20:54:14 -08:00
|
|
|
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
|
2016-12-02 12:40:57 -08:00
|
|
|
FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
|
2015-01-23 16:58:16 -08:00
|
|
|
|
|
|
|
|
2016-05-28 16:39:19 -07:00
|
|
|
ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
|
2016-12-26 22:19:36 -08:00
|
|
|
ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c
|
2017-01-01 18:22:18 -08:00
|
|
|
ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
|
2016-05-28 16:39:19 -07:00
|
|
|
ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
|
|
|
|
ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c
|
2016-08-17 06:59:50 -07:00
|
|
|
ZSTDDECOMP_O = $(ZSTDDIR)/decompress/zstd_decompress.o
|
2015-11-27 07:18:56 -08:00
|
|
|
|
2017-03-13 14:44:08 -07:00
|
|
|
ZSTD_LEGACY_SUPPORT ?= 4
|
2016-05-28 16:39:19 -07:00
|
|
|
ZSTDLEGACY_FILES:=
|
2017-03-13 14:32:30 -07:00
|
|
|
ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
|
|
|
|
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
|
|
|
|
ZSTDLEGACY_FILES += $(shell ls $(ZSTDDIR)/legacy/*.c | grep 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
|
|
|
|
endif
|
|
|
|
CPPFLAGS += -I$(ZSTDDIR)/legacy
|
2015-11-27 07:18:56 -08:00
|
|
|
else
|
|
|
|
endif
|
|
|
|
|
2017-01-01 18:22:18 -08:00
|
|
|
ZSTDLIB_FILES := $(wildcard $(ZSTD_FILES)) $(wildcard $(ZSTDLEGACY_FILES)) $(wildcard $(ZDICT_FILES))
|
|
|
|
ZSTDLIB_OBJ := $(patsubst %.c,%.o,$(ZSTDLIB_FILES))
|
2015-01-23 16:58:16 -08:00
|
|
|
|
|
|
|
# Define *.exe as extension for Windows systems
|
|
|
|
ifneq (,$(filter Windows%,$(OS)))
|
|
|
|
EXT =.exe
|
2016-12-08 01:43:55 -08:00
|
|
|
RES64_FILE = windres/zstd64.res
|
|
|
|
RES32_FILE = windres/zstd32.res
|
2016-09-14 07:16:24 -07:00
|
|
|
ifneq (,$(filter x86_64%,$(shell $(CC) -dumpmachine)))
|
|
|
|
RES_FILE = $(RES64_FILE)
|
|
|
|
else
|
|
|
|
RES_FILE = $(RES32_FILE)
|
|
|
|
endif
|
2015-01-23 16:58:16 -08:00
|
|
|
else
|
|
|
|
EXT =
|
|
|
|
endif
|
|
|
|
|
2017-02-02 16:49:34 -08:00
|
|
|
# zlib detection
|
2017-03-13 18:11:07 -07:00
|
|
|
NO_ZLIB_MSG := ==> no zlib, building zstd without .gz support
|
2017-02-03 14:25:07 -08:00
|
|
|
VOID = /dev/null
|
2017-03-22 13:24:52 -07:00
|
|
|
HAVE_ZLIB := $(shell printf '\#include <zlib.h>\nint main(void) { return 0; }' | $(CC) $(FLAGS) -o have_zlib$(EXT) -x c - -lz 2> $(VOID) && rm have_zlib$(EXT) && echo 1 || echo 0)
|
2017-02-08 05:32:49 -08:00
|
|
|
ifeq ($(HAVE_ZLIB), 1)
|
2017-03-13 18:11:07 -07:00
|
|
|
ZLIB_MSG := ==> building zstd with .gz compression support
|
2017-02-08 06:17:55 -08:00
|
|
|
ZLIBCPP = -DZSTD_GZCOMPRESS -DZSTD_GZDECOMPRESS
|
2017-02-02 16:49:34 -08:00
|
|
|
ZLIBLD = -lz
|
2017-03-13 18:11:07 -07:00
|
|
|
else
|
|
|
|
ZLIB_MSG := $(NO_ZLIB_MSG)
|
|
|
|
endif
|
|
|
|
# lzma detection
|
|
|
|
NO_LZMA_MSG := ==> no liblzma, building zstd without .xz/.lzma support
|
2017-03-22 13:24:52 -07:00
|
|
|
HAVE_LZMA := $(shell printf '\#include <lzma.h>\nint main(void) { return 0; }' | $(CC) $(FLAGS) -o have_lzma$(EXT) -x c - -llzma 2> $(VOID) && rm have_lzma$(EXT) && echo 1 || echo 0)
|
2017-03-13 18:11:07 -07:00
|
|
|
ifeq ($(HAVE_LZMA), 1)
|
|
|
|
LZMA_MSG := ==> building zstd with .xz/.lzma compression support
|
|
|
|
LZMACPP = -DZSTD_LZMACOMPRESS -DZSTD_LZMADECOMPRESS
|
|
|
|
LZMALD = -llzma
|
|
|
|
else
|
|
|
|
LZMA_MSG := $(NO_LZMA_MSG)
|
2017-02-02 16:49:34 -08:00
|
|
|
endif
|
2015-11-26 01:52:30 -08:00
|
|
|
|
2017-03-16 15:33:21 -07:00
|
|
|
MD2ROFF =ronn
|
|
|
|
MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="zstd $(ZSTD_VERSION)"
|
2017-03-13 18:11:07 -07:00
|
|
|
|
2016-10-28 04:16:06 -07:00
|
|
|
.PHONY: default all clean clean_decomp_o install uninstall generate_res
|
2015-01-23 16:58:16 -08:00
|
|
|
|
2017-02-02 20:54:14 -08:00
|
|
|
default: zstd-release
|
2015-01-23 16:58:16 -08:00
|
|
|
|
2016-08-18 04:18:11 -07:00
|
|
|
all: zstd
|
2015-01-23 16:58:16 -08:00
|
|
|
|
2016-10-18 16:01:03 -07:00
|
|
|
$(ZSTDDECOMP_O): CFLAGS += $(ALIGN_LOOP)
|
2016-08-17 06:59:50 -07:00
|
|
|
|
2017-03-08 18:00:35 -08:00
|
|
|
zstd : CPPFLAGS += $(ZLIBCPP)
|
|
|
|
zstd : LDFLAGS += $(ZLIBLD)
|
2017-03-13 18:11:07 -07:00
|
|
|
zstd : LZMA_MSG := $(NO_LZMA_MSG)
|
|
|
|
zstd-nogz : ZLIB_MSG := $(NO_ZLIB_MSG)
|
|
|
|
zstd-nogz : LZMA_MSG := $(NO_LZMA_MSG)
|
|
|
|
xzstd : CPPFLAGS += $(ZLIBCPP) $(LZMACPP)
|
|
|
|
xzstd : LDFLAGS += $(ZLIBLD) $(LZMALD)
|
|
|
|
zstd zstd-nogz xzstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
|
|
|
zstd zstd-nogz xzstd : $(ZSTDLIB_OBJ) zstdcli.o fileio.o bench.o datagen.o dibio.o
|
|
|
|
@echo "$(ZLIB_MSG)"
|
|
|
|
@echo "$(LZMA_MSG)"
|
2016-10-28 09:15:34 -07:00
|
|
|
ifneq (,$(filter Windows%,$(OS)))
|
2016-12-08 01:43:55 -08:00
|
|
|
windres/generate_res.bat
|
2016-10-28 09:15:34 -07:00
|
|
|
endif
|
2017-02-02 16:49:34 -08:00
|
|
|
$(CC) $(FLAGS) $^ $(RES_FILE) -o zstd$(EXT) $(LDFLAGS)
|
2015-01-23 16:58:16 -08:00
|
|
|
|
2017-02-02 20:54:14 -08:00
|
|
|
zstd-release: DEBUGFLAGS :=
|
|
|
|
zstd-release: zstd
|
2016-10-18 16:01:03 -07:00
|
|
|
|
2016-11-02 17:02:45 -07:00
|
|
|
zstd32 : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
2017-01-01 18:22:18 -08:00
|
|
|
zstd32 : $(ZSTDLIB_FILES) zstdcli.c fileio.c bench.c datagen.c dibio.c
|
2016-10-28 09:15:34 -07:00
|
|
|
ifneq (,$(filter Windows%,$(OS)))
|
2016-12-08 01:43:55 -08:00
|
|
|
windres/generate_res.bat
|
2016-10-28 09:15:34 -07:00
|
|
|
endif
|
2016-12-02 12:40:57 -08:00
|
|
|
$(CC) -m32 $(FLAGS) $^ $(RES32_FILE) -o $@$(EXT)
|
2016-08-17 06:59:50 -07:00
|
|
|
|
2015-01-23 16:58:16 -08:00
|
|
|
|
2016-11-02 17:02:45 -07:00
|
|
|
zstd-nolegacy : clean_decomp_o
|
2015-11-30 05:18:47 -08:00
|
|
|
$(MAKE) zstd ZSTD_LEGACY_SUPPORT=0
|
2015-11-30 02:53:11 -08:00
|
|
|
|
2015-11-30 16:28:32 -08:00
|
|
|
zstd-pgo : MOREFLAGS = -fprofile-generate
|
|
|
|
zstd-pgo : clean zstd
|
2016-02-17 08:04:12 -08:00
|
|
|
./zstd -b19i1 $(PROFILE_WITH)
|
|
|
|
./zstd -b16i1 $(PROFILE_WITH)
|
|
|
|
./zstd -b9i2 $(PROFILE_WITH)
|
2015-11-30 16:28:32 -08:00
|
|
|
./zstd -b $(PROFILE_WITH)
|
2016-02-17 08:04:12 -08:00
|
|
|
./zstd -b7i2 $(PROFILE_WITH)
|
|
|
|
./zstd -b5 $(PROFILE_WITH)
|
2016-08-30 13:33:20 -07:00
|
|
|
$(RM) zstd
|
2016-11-02 17:02:45 -07:00
|
|
|
$(RM) $(ZSTDDECOMP_O)
|
2015-11-30 16:28:32 -08:00
|
|
|
$(MAKE) zstd MOREFLAGS=-fprofile-use
|
|
|
|
|
2017-01-01 18:22:18 -08:00
|
|
|
zstd-frugal: $(ZSTD_FILES) zstdcli.c fileio.c
|
2016-12-02 12:40:57 -08:00
|
|
|
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT $^ -o zstd$(EXT)
|
2015-12-03 03:11:30 -08:00
|
|
|
|
2017-01-01 18:22:18 -08:00
|
|
|
zstd-small:
|
|
|
|
CFLAGS="-Os -s" $(MAKE) zstd-frugal
|
2016-04-22 08:14:25 -07:00
|
|
|
|
2017-01-01 18:22:18 -08:00
|
|
|
zstd-decompress: $(ZSTDCOMMON_FILES) $(ZSTDDECOMP_FILES) zstdcli.c fileio.c
|
|
|
|
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOCOMPRESS $^ -o $@$(EXT)
|
2016-10-05 02:56:22 -07:00
|
|
|
|
|
|
|
zstd-compress: $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) zstdcli.c fileio.c
|
2016-12-02 12:40:57 -08:00
|
|
|
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NODECOMPRESS $^ -o $@$(EXT)
|
2015-12-03 03:11:30 -08:00
|
|
|
|
2017-01-19 14:05:07 -08:00
|
|
|
zstdmt: CPPFLAGS += -DZSTD_MULTITHREAD
|
2017-02-03 14:35:42 -08:00
|
|
|
ifeq (,$(filter Windows%,$(OS)))
|
2017-01-01 16:43:56 -08:00
|
|
|
zstdmt: LDFLAGS += -lpthread
|
2017-02-03 14:35:42 -08:00
|
|
|
endif
|
2017-01-11 09:21:25 -08:00
|
|
|
zstdmt: zstd
|
2017-01-01 16:43:56 -08:00
|
|
|
|
2016-10-28 04:16:06 -07:00
|
|
|
generate_res:
|
2016-12-08 01:43:55 -08:00
|
|
|
windres/generate_res.bat
|
2016-05-28 06:30:01 -07:00
|
|
|
|
2015-01-23 16:58:16 -08:00
|
|
|
clean:
|
2017-02-22 01:31:30 -08:00
|
|
|
$(MAKE) -C $(ZSTDDIR) clean
|
2016-09-02 09:44:00 -07:00
|
|
|
@$(RM) $(ZSTDDIR)/decompress/*.o $(ZSTDDIR)/decompress/zstd_decompress.gcda
|
2016-08-30 13:33:20 -07:00
|
|
|
@$(RM) core *.o tmp* result* *.gcda dictionary *.zst \
|
2016-09-02 09:44:00 -07:00
|
|
|
zstd$(EXT) zstd32$(EXT) zstd-compress$(EXT) zstd-decompress$(EXT) \
|
2017-02-08 05:32:49 -08:00
|
|
|
*.gcda default.profraw have_zlib$(EXT)
|
2015-01-23 16:58:16 -08:00
|
|
|
@echo Cleaning completed
|
|
|
|
|
2016-10-05 02:56:22 -07:00
|
|
|
clean_decomp_o:
|
|
|
|
@$(RM) $(ZSTDDECOMP_O)
|
|
|
|
|
2017-03-16 15:33:21 -07:00
|
|
|
zstd.1: zstd.1.md
|
|
|
|
cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
|
|
|
|
|
|
|
|
man: zstd.1
|
|
|
|
|
|
|
|
clean-man:
|
|
|
|
rm zstd.1
|
|
|
|
|
|
|
|
preview-man: clean-man man
|
|
|
|
man ./zstd.1
|
2015-01-23 16:58:16 -08:00
|
|
|
|
2016-12-23 01:05:49 -08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
|
|
|
|
#-----------------------------------------------------------------------------
|
2016-12-22 10:26:01 -08:00
|
|
|
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
|
|
|
|
|
|
|
|
ifneq (,$(filter $(shell uname),SunOS))
|
2016-12-22 11:14:37 -08:00
|
|
|
INSTALL ?= ginstall
|
2016-12-22 10:26:01 -08:00
|
|
|
else
|
2016-12-22 11:14:37 -08:00
|
|
|
INSTALL ?= install
|
2016-12-22 10:26:01 -08:00
|
|
|
endif
|
2016-12-23 01:05:49 -08:00
|
|
|
|
|
|
|
PREFIX ?= /usr/local
|
2016-12-22 11:14:37 -08:00
|
|
|
DESTDIR ?=
|
2016-12-23 01:05:49 -08:00
|
|
|
BINDIR ?= $(PREFIX)/bin
|
2016-12-28 03:32:41 -08:00
|
|
|
|
|
|
|
ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly SunOS))
|
|
|
|
MANDIR ?= $(PREFIX)/man/man1
|
|
|
|
else
|
2016-12-23 01:05:49 -08:00
|
|
|
MANDIR ?= $(PREFIX)/share/man/man1
|
2017-01-01 16:43:56 -08:00
|
|
|
endif
|
2016-12-22 10:26:01 -08:00
|
|
|
|
|
|
|
INSTALL_PROGRAM ?= $(INSTALL) -m 755
|
2016-12-23 01:05:49 -08:00
|
|
|
INSTALL_SCRIPT ?= $(INSTALL) -m 755
|
|
|
|
INSTALL_MAN ?= $(INSTALL) -m 644
|
2016-12-22 10:26:01 -08:00
|
|
|
|
2015-11-30 16:56:02 -08:00
|
|
|
install: zstd
|
2015-01-23 16:58:16 -08:00
|
|
|
@echo Installing binaries
|
2016-12-22 10:26:01 -08:00
|
|
|
@$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
|
|
|
|
@$(INSTALL_PROGRAM) zstd $(DESTDIR)$(BINDIR)/zstd
|
2016-12-02 15:24:40 -08:00
|
|
|
@ln -sf zstd $(DESTDIR)$(BINDIR)/zstdcat
|
|
|
|
@ln -sf zstd $(DESTDIR)$(BINDIR)/unzstd
|
2016-12-22 10:26:01 -08:00
|
|
|
@$(INSTALL_SCRIPT) zstdless $(DESTDIR)$(BINDIR)/zstdless
|
|
|
|
@$(INSTALL_SCRIPT) zstdgrep $(DESTDIR)$(BINDIR)/zstdgrep
|
2015-01-23 16:58:16 -08:00
|
|
|
@echo Installing man pages
|
2016-12-22 10:26:01 -08:00
|
|
|
@$(INSTALL_MAN) zstd.1 $(DESTDIR)$(MANDIR)/zstd.1
|
2015-08-26 19:16:04 -07:00
|
|
|
@ln -sf zstd.1 $(DESTDIR)$(MANDIR)/zstdcat.1
|
|
|
|
@ln -sf zstd.1 $(DESTDIR)$(MANDIR)/unzstd.1
|
2015-01-23 16:58:16 -08:00
|
|
|
@echo zstd installation completed
|
|
|
|
|
|
|
|
uninstall:
|
2016-12-02 15:57:07 -08:00
|
|
|
@$(RM) $(DESTDIR)$(BINDIR)/zstdgrep
|
|
|
|
@$(RM) $(DESTDIR)$(BINDIR)/zstdless
|
2016-10-12 11:09:36 -07:00
|
|
|
@$(RM) $(DESTDIR)$(BINDIR)/zstdcat
|
|
|
|
@$(RM) $(DESTDIR)$(BINDIR)/unzstd
|
2016-12-02 15:24:40 -08:00
|
|
|
@$(RM) $(DESTDIR)$(BINDIR)/zstd
|
2016-10-12 11:09:36 -07:00
|
|
|
@$(RM) $(DESTDIR)$(MANDIR)/zstdcat.1
|
|
|
|
@$(RM) $(DESTDIR)$(MANDIR)/unzstd.1
|
|
|
|
@$(RM) $(DESTDIR)$(MANDIR)/zstd.1
|
2015-01-23 16:58:16 -08:00
|
|
|
@echo zstd programs successfully uninstalled
|
|
|
|
endif
|