1 1.1 christos # ################################################################ 2 1.1 christos # Copyright (c) Meta Platforms, Inc. and affiliates. 3 1.1 christos # All rights reserved. 4 1.1 christos # 5 1.1 christos # This source code is licensed under both the BSD-style license (found in the 6 1.1 christos # LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 1.1 christos # in the COPYING file in the root directory of this source tree). 8 1.1 christos # You may select, at your option, one of the above-listed licenses. 9 1.1 christos # ########################################################################## 10 1.1 christos # zstd : Command Line Utility, supporting gzip-like arguments 11 1.1 christos # zstd32 : Same as zstd, but forced to compile in 32-bits mode 12 1.1 christos # zstd-nolegacy : zstd without support of decompression of legacy versions 13 1.1 christos # zstd-small : minimal zstd without dictionary builder and benchmark 14 1.1 christos # zstd-compress : compressor-only version of zstd 15 1.1 christos # zstd-decompress : decompressor-only version of zstd 16 1.1 christos # ########################################################################## 17 1.1 christos 18 1.1 christos # default target (when running `make` with no argument) 19 1.1 christos zstd-release: 20 1.1 christos 21 1.1 christos LIBZSTD_MK_DIR = ../lib 22 1.1 christos include $(LIBZSTD_MK_DIR)/libzstd.mk 23 1.1 christos 24 1.1 christos ifeq ($(shell $(CC) -v 2>&1 | $(GREP) -c "gcc version "), 1) 25 1.1 christos ALIGN_LOOP = -falign-loops=32 26 1.1 christos else 27 1.1 christos ALIGN_LOOP = 28 1.1 christos endif 29 1.1 christos 30 1.1 christos ZSTDLIB_COMMON_SRC := $(sort $(ZSTD_COMMON_FILES)) 31 1.1 christos ZSTDLIB_COMPRESS_SRC := $(sort $(ZSTD_COMPRESS_FILES)) 32 1.1 christos ZSTDLIB_DECOMPRESS_SRC := $(sort $(ZSTD_DECOMPRESS_FILES)) 33 1.1 christos ZSTDLIB_CORE_SRC := $(sort $(ZSTD_DECOMPRESS_FILES) $(ZSTD_COMMON_FILES) $(ZSTD_COMPRESS_FILES)) 34 1.1 christos ZDICT_SRC := $(sort $(ZSTD_DICTBUILDER_FILES)) 35 1.1 christos ZSTDLEGACY_SRC := $(sort $(ZSTD_LEGACY_FILES)) 36 1.1 christos 37 1.1 christos # Sort files in alphabetical order for reproducible builds 38 1.1 christos ZSTDLIB_FULL_SRC = $(sort $(ZSTDLIB_CORE_SRC) $(ZSTDLEGACY_SRC) $(ZDICT_SRC)) 39 1.1 christos ZSTDLIB_LOCAL_SRC = $(notdir $(ZSTDLIB_FULL_SRC)) 40 1.1 christos ZSTDLIB_LOCAL_OBJ0 := $(ZSTDLIB_LOCAL_SRC:.c=.o) 41 1.1 christos ZSTDLIB_LOCAL_OBJ := $(ZSTDLIB_LOCAL_OBJ0:.S=.o) 42 1.1 christos 43 1.1 christos ZSTD_CLI_SRC := $(sort $(wildcard *.c)) 44 1.1 christos ZSTD_CLI_OBJ := $(ZSTD_CLI_SRC:.c=.o) 45 1.1 christos 46 1.1 christos ZSTD_ALL_SRC = $(ZSTDLIB_LOCAL_SRC) $(ZSTD_CLI_SRC) 47 1.1 christos ZSTD_ALL_OBJ0 := $(ZSTD_ALL_SRC:.c=.o) 48 1.1 christos ZSTD_ALL_OBJ := $(ZSTD_ALL_OBJ0:.S=.o) 49 1.1 christos 50 1.1 christos # Define *.exe as extension for Windows systems 51 1.1 christos ifneq (,$(filter Windows%,$(OS))) 52 1.1 christos EXT =.exe 53 1.1 christos RES64_FILE = windres/zstd64.res 54 1.1 christos RES32_FILE = windres/zstd32.res 55 1.1 christos ifneq (,$(filter x86_64%,$(shell $(CC) -dumpmachine))) 56 1.1 christos RES_FILE = $(RES64_FILE) 57 1.1 christos else 58 1.1 christos RES_FILE = $(RES32_FILE) 59 1.1 christos endif 60 1.1 christos else 61 1.1 christos EXT = 62 1.1 christos endif 63 1.1 christos 64 1.1 christos # thread detection 65 1.1 christos NO_THREAD_MSG := ==> no threads, building without multithreading support 66 1.1 christos HAVE_PTHREAD := $(shell printf '$(NUM_SYMBOL)include <pthread.h>\nint main(void) { return 0; }' > have_pthread.c && $(CC) $(FLAGS) -o have_pthread$(EXT) have_pthread.c -pthread 2> $(VOID) && rm have_pthread$(EXT) && echo 1 || echo 0; rm have_pthread.c) 67 1.1 christos HAVE_THREAD := $(shell [ "$(HAVE_PTHREAD)" -eq "1" -o -n "$(filter Windows%,$(OS))" ] && echo 1 || echo 0) 68 1.1 christos ifeq ($(HAVE_THREAD), 1) 69 1.1 christos THREAD_MSG := ==> building with threading support 70 1.1 christos THREAD_CPP := -DZSTD_MULTITHREAD 71 1.1 christos THREAD_LD := -pthread 72 1.1 christos else 73 1.1 christos THREAD_MSG := $(NO_THREAD_MSG) 74 1.1 christos endif 75 1.1 christos 76 1.1 christos # zlib detection 77 1.1 christos NO_ZLIB_MSG := ==> no zlib, building zstd without .gz support 78 1.1 christos HAVE_ZLIB ?= $(shell printf '$(NUM_SYMBOL)include <zlib.h>\nint main(void) { return 0; }' > have_zlib.c && $(CC) $(FLAGS) -o have_zlib$(EXT) have_zlib.c -lz 2> $(VOID) && rm have_zlib$(EXT) && echo 1 || echo 0; rm have_zlib.c) 79 1.1 christos ifeq ($(HAVE_ZLIB), 1) 80 1.1 christos ZLIB_MSG := ==> building zstd with .gz compression support 81 1.1 christos ZLIBCPP = -DZSTD_GZCOMPRESS -DZSTD_GZDECOMPRESS 82 1.1 christos ZLIBLD = -lz 83 1.1 christos else 84 1.1 christos ZLIB_MSG := $(NO_ZLIB_MSG) 85 1.1 christos endif 86 1.1 christos 87 1.1 christos # lzma detection 88 1.1 christos NO_LZMA_MSG := ==> no liblzma, building zstd without .xz/.lzma support 89 1.1 christos HAVE_LZMA ?= $(shell printf '$(NUM_SYMBOL)include <lzma.h>\nint main(void) { return 0; }' > have_lzma.c && $(CC) $(FLAGS) -o have_lzma$(EXT) have_lzma.c -llzma 2> $(VOID) && rm have_lzma$(EXT) && echo 1 || echo 0; rm have_lzma.c) 90 1.1 christos ifeq ($(HAVE_LZMA), 1) 91 1.1 christos LZMA_MSG := ==> building zstd with .xz/.lzma compression support 92 1.1 christos LZMACPP = -DZSTD_LZMACOMPRESS -DZSTD_LZMADECOMPRESS 93 1.1 christos LZMALD = -llzma 94 1.1 christos else 95 1.1 christos LZMA_MSG := $(NO_LZMA_MSG) 96 1.1 christos endif 97 1.1 christos 98 1.1 christos # lz4 detection 99 1.1 christos NO_LZ4_MSG := ==> no liblz4, building zstd without .lz4 support 100 1.1 christos HAVE_LZ4 ?= $(shell printf '$(NUM_SYMBOL)include <lz4frame.h>\n$(NUM_SYMBOL)include <lz4.h>\nint main(void) { return 0; }' > have_lz4.c && $(CC) $(FLAGS) -o have_lz4$(EXT) have_lz4.c -llz4 2> $(VOID) && rm have_lz4$(EXT) && echo 1 || echo 0; rm have_lz4.c) 101 1.1 christos ifeq ($(HAVE_LZ4), 1) 102 1.1 christos LZ4_MSG := ==> building zstd with .lz4 compression support 103 1.1 christos LZ4CPP = -DZSTD_LZ4COMPRESS -DZSTD_LZ4DECOMPRESS 104 1.1 christos LZ4LD = -llz4 105 1.1 christos else 106 1.1 christos LZ4_MSG := $(NO_LZ4_MSG) 107 1.1 christos endif 108 1.1 christos 109 1.1 christos # explicit backtrace enable/disable for Linux & Darwin 110 1.1 christos ifeq ($(BACKTRACE), 0) 111 1.1 christos DEBUGFLAGS += -DBACKTRACE_ENABLE=0 112 1.1 christos endif 113 1.1 christos ifeq (,$(filter Windows%, $(OS))) 114 1.1 christos ifeq ($(BACKTRACE), 1) 115 1.1 christos DEBUGFLAGS += -DBACKTRACE_ENABLE=1 116 1.1 christos DEBUGFLAGS_LD += -rdynamic 117 1.1 christos endif 118 1.1 christos endif 119 1.1 christos 120 1.1 christos SET_CACHE_DIRECTORY = \ 121 1.1 christos +$(MAKE) --no-print-directory $@ \ 122 1.1 christos BUILD_DIR=obj/$(HASH_DIR) \ 123 1.1 christos CPPFLAGS="$(CPPFLAGS)" \ 124 1.1 christos CFLAGS="$(CFLAGS)" \ 125 1.1 christos LDFLAGS="$(LDFLAGS)" \ 126 1.1 christos LDLIBS="$(LDLIBS)" \ 127 1.1 christos ZSTD_ALL_SRC="$(ZSTD_ALL_SRC)" 128 1.1 christos 129 1.1 christos 130 1.1 christos .PHONY: all 131 1.1 christos all: zstd zstd-compress zstd-decompress zstd-small 132 1.1 christos 133 1.1 christos .PHONY: allVariants 134 1.1 christos allVariants: all zstd-frugal zstd-nolegacy zstd-dictBuilder 135 1.1 christos 136 1.1 christos .PHONY: zstd # must always be run 137 1.1 christos zstd : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP) 138 1.1 christos zstd : LDFLAGS += $(THREAD_LD) $(DEBUGFLAGS_LD) 139 1.1 christos zstd : LDLIBS += $(ZLIBLD) $(LZMALD) $(LZ4LD) 140 1.1 christos zstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) 141 1.1 christos ifneq (,$(filter Windows%,$(OS))) 142 1.1 christos zstd : $(RES_FILE) 143 1.1 christos endif 144 1.1 christos 145 1.1 christos ifndef BUILD_DIR 146 1.1 christos # generate BUILD_DIR from flags 147 1.1 christos 148 1.1 christos zstd: 149 1.1 christos $(SET_CACHE_DIRECTORY) 150 1.1 christos 151 1.1 christos else 152 1.1 christos # BUILD_DIR is defined 153 1.1 christos 154 1.1 christos ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ)) 155 1.1 christos $(BUILD_DIR)/zstd : $(ZSTD_OBJ) 156 1.1 christos @echo "$(THREAD_MSG)" 157 1.1 christos @echo "$(ZLIB_MSG)" 158 1.1 christos @echo "$(LZMA_MSG)" 159 1.1 christos @echo "$(LZ4_MSG)" 160 1.1 christos @echo LINK $@ 161 1.1 christos $(CC) $(FLAGS) $^ $(LDLIBS) -o $@$(EXT) 162 1.1 christos 163 1.1 christos ifeq ($(HAVE_HASH),1) 164 1.1 christos SRCBIN_HASH = $(shell cat $(BUILD_DIR)/zstd$(EXT) 2> $(VOID) | $(HASH) | cut -f 1 -d " ") 165 1.1 christos DSTBIN_HASH = $(shell cat zstd$(EXT) 2> $(VOID) | $(HASH) | cut -f 1 -d " ") 166 1.1 christos BIN_ISDIFFERENT = $(if $(filter $(SRCBIN_HASH),$(DSTBIN_HASH)),0,1) 167 1.1 christos else 168 1.1 christos BIN_ISDIFFERENT = 1 169 1.1 christos endif 170 1.1 christos 171 1.1 christos zstd : $(BUILD_DIR)/zstd 172 1.1 christos if [ $(BIN_ISDIFFERENT) -eq 1 ]; then \ 173 1.1 christos cp -f $<$(EXT) $@$(EXT); \ 174 1.1 christos echo zstd build completed; \ 175 1.1 christos else \ 176 1.1 christos echo zstd already built; \ 177 1.1 christos fi 178 1.1 christos 179 1.1 christos endif # BUILD_DIR 180 1.1 christos 181 1.1 christos 182 1.1 christos CLEAN += zstd 183 1.1 christos .PHONY: zstd-release 184 1.1 christos zstd-release: DEBUGFLAGS := -DBACKTRACE_ENABLE=0 185 1.1 christos zstd-release: DEBUGFLAGS_LD := 186 1.1 christos zstd-release: zstd 187 1.1 christos 188 1.1 christos CLEAN += zstd32 189 1.1 christos zstd32 : CPPFLAGS += $(THREAD_CPP) 190 1.1 christos zstd32 : LDFLAGS += $(THREAD_LD) 191 1.1 christos zstd32 : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) 192 1.1 christos ifneq (,$(filter Windows%,$(OS))) 193 1.1 christos zstd32 : $(RES32_FILE) 194 1.1 christos endif 195 1.1 christos zstd32 : $(ZSTDLIB_FULL_SRC) $(ZSTD_CLI_SRC) 196 1.1 christos $(CC) -m32 $(FLAGS) $^ -o $@$(EXT) 197 1.1 christos 198 1.1 christos ## zstd-nolegacy: same scope as zstd, with removed support of legacy formats 199 1.1 christos CLEAN += zstd-nolegacy 200 1.1 christos zstd-nolegacy : LDFLAGS += $(THREAD_LD) $(ZLIBLD) $(LZMALD) $(LZ4LD) $(DEBUGFLAGS_LD) 201 1.1 christos zstd-nolegacy : CPPFLAGS += -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 202 1.1 christos zstd-nolegacy : $(ZSTDLIB_CORE_SRC) $(ZDICT_SRC) $(ZSTD_CLI_OBJ) 203 1.1 christos $(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS) 204 1.1 christos 205 1.1 christos .PHONY: zstd-nomt 206 1.1 christos zstd-nomt : THREAD_CPP := 207 1.1 christos zstd-nomt : THREAD_LD := 208 1.1 christos zstd-nomt : THREAD_MSG := - multi-threading disabled 209 1.1 christos zstd-nomt : zstd 210 1.1 christos 211 1.1 christos .PHONY: zstd-nogz 212 1.1 christos zstd-nogz : ZLIBCPP := 213 1.1 christos zstd-nogz : ZLIBLD := 214 1.1 christos zstd-nogz : ZLIB_MSG := - gzip support is disabled 215 1.1 christos zstd-nogz : zstd 216 1.1 christos 217 1.1 christos .PHONY: zstd-noxz 218 1.1 christos zstd-noxz : LZMACPP := 219 1.1 christos zstd-noxz : LZMALD := 220 1.1 christos zstd-noxz : LZMA_MSG := - xz/lzma support is disabled 221 1.1 christos zstd-noxz : zstd 222 1.1 christos 223 1.1 christos ## zstd-dll: zstd executable linked to dynamic library libzstd (must have same version) 224 1.1 christos .PHONY: zstd-dll 225 1.1 christos zstd-dll : LDFLAGS+= -L$(LIB_BINDIR) 226 1.1 christos zstd-dll : LDLIBS += -lzstd 227 1.1 christos zstd-dll : ZSTDLIB_LOCAL_SRC = xxhash.c pool.c threading.c 228 1.1 christos zstd-dll : zstd 229 1.1 christos 230 1.1 christos 231 1.1 christos ## zstd-pgo: zstd executable optimized with PGO. 232 1.1 christos .PHONY: zstd-pgo 233 1.1 christos zstd-pgo : LLVM_PROFDATA?=llvm-profdata 234 1.1 christos zstd-pgo : PROF_GENERATE_FLAGS=-fprofile-generate $(if $(findstring gcc,$(CC)),-fprofile-dir=.) 235 1.1 christos zstd-pgo : PROF_USE_FLAGS=-fprofile-use $(if $(findstring gcc,$(CC)),-fprofile-dir=. -Werror=missing-profile -Wno-error=coverage-mismatch) 236 1.1 christos zstd-pgo : 237 1.1 christos $(MAKE) clean HASH_DIR=$(HASH_DIR) 238 1.1 christos $(MAKE) zstd HASH_DIR=$(HASH_DIR) MOREFLAGS="$(PROF_GENERATE_FLAGS)" 239 1.1 christos ./zstd -b19i1 $(PROFILE_WITH) 240 1.1 christos ./zstd -b16i1 $(PROFILE_WITH) 241 1.1 christos ./zstd -b9i2 $(PROFILE_WITH) 242 1.1 christos ./zstd -b $(PROFILE_WITH) 243 1.1 christos ./zstd -b7i2 $(PROFILE_WITH) 244 1.1 christos ./zstd -b5 $(PROFILE_WITH) 245 1.1 christos ifndef BUILD_DIR 246 1.1 christos $(RM) zstd obj/$(HASH_DIR)/zstd obj/$(HASH_DIR)/*.o 247 1.1 christos else 248 1.1 christos $(RM) zstd $(BUILD_DIR)/zstd $(BUILD_DIR)/*.o 249 1.1 christos endif 250 1.1 christos case $(CC) in *clang*) if ! [ -e default.profdata ]; then $(LLVM_PROFDATA) merge -output=default.profdata default*.profraw; fi ;; esac 251 1.1 christos $(MAKE) zstd HASH_DIR=$(HASH_DIR) MOREFLAGS="$(PROF_USE_FLAGS)" 252 1.1 christos 253 1.1 christos ## zstd-small: minimal target, supporting only zstd compression and decompression. no bench. no legacy. no other format. 254 1.1 christos CLEAN += zstd-small zstd-frugal 255 1.1 christos zstd-small: CFLAGS = -Os -Wl,-s 256 1.1 christos zstd-frugal zstd-small: $(ZSTDLIB_CORE_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c 257 1.1 christos $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOTRACE -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 $^ -o $@$(EXT) 258 1.1 christos 259 1.1 christos CLEAN += zstd-decompress 260 1.1 christos zstd-decompress: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_DECOMPRESS_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c 261 1.1 christos $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOCOMPRESS -DZSTD_NOTRACE -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 $^ -o $@$(EXT) 262 1.1 christos 263 1.1 christos CLEAN += zstd-compress 264 1.1 christos zstd-compress: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_COMPRESS_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c 265 1.1 christos $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NODECOMPRESS -DZSTD_NOTRACE -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 $^ -o $@$(EXT) 266 1.1 christos 267 1.1 christos ## zstd-dictBuilder: executable supporting dictionary creation and compression (only) 268 1.1 christos CLEAN += zstd-dictBuilder 269 1.1 christos zstd-dictBuilder: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_COMPRESS_SRC) $(ZDICT_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c dibio.c 270 1.1 christos $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODECOMPRESS -DZSTD_NOTRACE $^ -o $@$(EXT) 271 1.1 christos 272 1.1 christos CLEAN += zstdmt 273 1.1 christos zstdmt: zstd 274 1.1 christos ln -sf zstd zstdmt 275 1.1 christos 276 1.1 christos .PHONY: generate_res 277 1.1 christos generate_res: $(RES64_FILE) $(RES32_FILE) 278 1.1 christos 279 1.1 christos ifneq (,$(filter Windows%,$(OS))) 280 1.1 christos RC ?= windres 281 1.1 christos # https://stackoverflow.com/questions/708238/how-do-i-add-an-icon-to-a-mingw-gcc-compiled-executable 282 1.1 christos $(RES64_FILE): windres/zstd.rc 283 1.1 christos $(RC) -o $@ -I ../lib -I windres -i $< -O coff -F pe-x86-64 284 1.1 christos $(RES32_FILE): windres/zstd.rc 285 1.1 christos $(RC) -o $@ -I ../lib -I windres -i $< -O coff -F pe-i386 286 1.1 christos endif 287 1.1 christos 288 1.1 christos .PHONY: clean 289 1.1 christos clean: 290 1.1 christos $(RM) $(CLEAN) core *.o tmp* result* dictionary *.zst \ 291 1.1 christos *.gcda default*.profraw default.profdata have_zlib 292 1.1 christos $(RM) -r obj/* 293 1.1 christos @echo Cleaning completed 294 1.1 christos 295 1.1 christos MD2ROFF = ronn 296 1.1 christos MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="zstd $(ZSTD_VERSION)" 297 1.1 christos 298 1.1 christos zstd.1: zstd.1.md ../lib/zstd.h 299 1.1 christos cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 300 1.1 christos 301 1.1 christos zstdgrep.1: zstdgrep.1.md ../lib/zstd.h 302 1.1 christos cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 303 1.1 christos 304 1.1 christos zstdless.1: zstdless.1.md ../lib/zstd.h 305 1.1 christos cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 306 1.1 christos 307 1.1 christos .PHONY: man 308 1.1 christos man: zstd.1 zstdgrep.1 zstdless.1 309 1.1 christos 310 1.1 christos .PHONY: clean-man 311 1.1 christos clean-man: 312 1.1 christos $(RM) zstd.1 313 1.1 christos $(RM) zstdgrep.1 314 1.1 christos $(RM) zstdless.1 315 1.1 christos 316 1.1 christos .PHONY: preview-man 317 1.1 christos preview-man: clean-man man 318 1.1 christos man ./zstd.1 319 1.1 christos man ./zstdgrep.1 320 1.1 christos man ./zstdless.1 321 1.1 christos 322 1.1 christos 323 1.1 christos # Generate .h dependencies automatically 324 1.1 christos 325 1.1 christos DEPFLAGS = -MT $@ -MMD -MP -MF 326 1.1 christos 327 1.1 christos $(BUILD_DIR)/%.o : %.c $(BUILD_DIR)/%.d | $(BUILD_DIR) 328 1.1 christos @echo CC $@ 329 1.1 christos $(COMPILE.c) $(DEPFLAGS) $(BUILD_DIR)/$*.d $(OUTPUT_OPTION) $< 330 1.1 christos 331 1.1 christos $(BUILD_DIR)/%.o : %.S | $(BUILD_DIR) 332 1.1 christos @echo AS $@ 333 1.1 christos $(COMPILE.S) $(OUTPUT_OPTION) $< 334 1.1 christos 335 1.1 christos MKDIR ?= mkdir 336 1.1 christos $(BUILD_DIR): ; $(MKDIR) -p $@ 337 1.1 christos 338 1.1 christos DEPFILES := $(ZSTD_OBJ:.o=.d) 339 1.1 christos $(DEPFILES): 340 1.1 christos 341 1.1 christos include $(wildcard $(DEPFILES)) 342 1.1 christos 343 1.1 christos 344 1.1 christos 345 1.1 christos #----------------------------------------------------------------------------- 346 1.1 christos # make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets 347 1.1 christos #----------------------------------------------------------------------------- 348 1.1 christos ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT CYGWIN_NT)) 349 1.1 christos 350 1.1 christos HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0) 351 1.1 christos EGREP_OPTIONS ?= 352 1.1 christos ifeq ($(HAVE_COLORNEVER), 1) 353 1.1 christos EGREP_OPTIONS += --color=never 354 1.1 christos endif 355 1.1 christos EGREP = egrep $(EGREP_OPTIONS) 356 1.1 christos AWK = awk 357 1.1 christos 358 1.1 christos # Print a two column output of targets and their description. To add a target description, put a 359 1.1 christos # comment in the Makefile with the format "## <TARGET>: <DESCRIPTION>". For example: 360 1.1 christos # 361 1.1 christos ## list: Print all targets and their descriptions (if provided) 362 1.1 christos .PHONY: list 363 1.1 christos list: 364 1.1 christos TARGETS=$$($(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null \ 365 1.1 christos | $(AWK) -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \ 366 1.1 christos | $(EGREP) -v -e '^[^[:alnum:]]' | sort); \ 367 1.1 christos { \ 368 1.1 christos printf "Target Name\tDescription\n"; \ 369 1.1 christos printf "%0.s-" {1..16}; printf "\t"; printf "%0.s-" {1..40}; printf "\n"; \ 370 1.1 christos for target in $$TARGETS; do \ 371 1.1 christos line=$$($(EGREP) "^##[[:space:]]+$$target:" $(lastword $(MAKEFILE_LIST))); \ 372 1.1 christos description=$$(echo $$line | $(AWK) '{i=index($$0,":"); print substr($$0,i+1)}' | xargs); \ 373 1.1 christos printf "$$target\t$$description\n"; \ 374 1.1 christos done \ 375 1.1 christos } | column -t -s $$'\t' 376 1.1 christos 377 1.1 christos 378 1.1 christos DESTDIR ?= 379 1.1 christos # directory variables : GNU conventions prefer lowercase 380 1.1 christos # see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 381 1.1 christos # support both lower and uppercase (BSD), use uppercase in script 382 1.1 christos prefix ?= /usr/local 383 1.1 christos PREFIX ?= $(prefix) 384 1.1 christos exec_prefix ?= $(PREFIX) 385 1.1 christos bindir ?= $(exec_prefix)/bin 386 1.1 christos BINDIR ?= $(bindir) 387 1.1 christos datarootdir ?= $(PREFIX)/share 388 1.1 christos mandir ?= $(datarootdir)/man 389 1.1 christos man1dir ?= $(mandir)/man1 390 1.1 christos 391 1.1 christos ifneq (,$(filter $(UNAME),OpenBSD FreeBSD NetBSD DragonFly SunOS)) 392 1.1 christos MANDIR ?= $(PREFIX)/man 393 1.1 christos MAN1DIR ?= $(MANDIR)/man1 394 1.1 christos else 395 1.1 christos MAN1DIR ?= $(man1dir) 396 1.1 christos endif 397 1.1 christos 398 1.1 christos ifneq (,$(filter $(UNAME),SunOS)) 399 1.1 christos INSTALL ?= ginstall 400 1.1 christos else 401 1.1 christos INSTALL ?= install 402 1.1 christos endif 403 1.1 christos 404 1.1 christos INSTALL_PROGRAM ?= $(INSTALL) 405 1.1 christos INSTALL_SCRIPT ?= $(INSTALL_PROGRAM) 406 1.1 christos INSTALL_DATA ?= $(INSTALL) -m 644 407 1.1 christos INSTALL_MAN ?= $(INSTALL_DATA) 408 1.1 christos 409 1.1 christos .PHONY: install 410 1.1 christos install: 411 1.1 christos # generate zstd only if not already present 412 1.1 christos [ -e zstd ] || $(MAKE) zstd-release 413 1.1 christos [ -e $(DESTDIR)$(BINDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ 414 1.1 christos [ -e $(DESTDIR)$(MAN1DIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(MAN1DIR)/ 415 1.1 christos @echo Installing binaries 416 1.1 christos $(INSTALL_PROGRAM) zstd$(EXT) $(DESTDIR)$(BINDIR)/zstd$(EXT) 417 1.1 christos ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/zstdcat$(EXT) 418 1.1 christos ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/unzstd$(EXT) 419 1.1 christos ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/zstdmt$(EXT) 420 1.1 christos $(INSTALL_SCRIPT) zstdless $(DESTDIR)$(BINDIR)/zstdless 421 1.1 christos $(INSTALL_SCRIPT) zstdgrep $(DESTDIR)$(BINDIR)/zstdgrep 422 1.1 christos @echo Installing man pages 423 1.1 christos $(INSTALL_MAN) zstd.1 $(DESTDIR)$(MAN1DIR)/zstd.1 424 1.1 christos ln -sf zstd.1 $(DESTDIR)$(MAN1DIR)/zstdcat.1 425 1.1 christos ln -sf zstd.1 $(DESTDIR)$(MAN1DIR)/unzstd.1 426 1.1 christos $(INSTALL_MAN) zstdgrep.1 $(DESTDIR)$(MAN1DIR)/zstdgrep.1 427 1.1 christos $(INSTALL_MAN) zstdless.1 $(DESTDIR)$(MAN1DIR)/zstdless.1 428 1.1 christos @echo zstd installation completed 429 1.1 christos 430 1.1 christos .PHONY: uninstall 431 1.1 christos uninstall: 432 1.1 christos $(RM) $(DESTDIR)$(BINDIR)/zstdgrep 433 1.1 christos $(RM) $(DESTDIR)$(BINDIR)/zstdless 434 1.1 christos $(RM) $(DESTDIR)$(BINDIR)/zstdcat 435 1.1 christos $(RM) $(DESTDIR)$(BINDIR)/unzstd 436 1.1 christos $(RM) $(DESTDIR)$(BINDIR)/zstdmt 437 1.1 christos $(RM) $(DESTDIR)$(BINDIR)/zstd 438 1.1 christos $(RM) $(DESTDIR)$(MAN1DIR)/zstdless.1 439 1.1 christos $(RM) $(DESTDIR)$(MAN1DIR)/zstdgrep.1 440 1.1 christos $(RM) $(DESTDIR)$(MAN1DIR)/zstdcat.1 441 1.1 christos $(RM) $(DESTDIR)$(MAN1DIR)/unzstd.1 442 1.1 christos $(RM) $(DESTDIR)$(MAN1DIR)/zstd.1 443 1.1 christos @echo zstd programs successfully uninstalled 444 1.1 christos 445 1.1 christos endif 446