10c16b537SWarner Losh# ################################################################ 20c16b537SWarner Losh# Copyright (c) 2015-present, Yann Collet, Facebook, Inc. 30c16b537SWarner Losh# All rights reserved. 40c16b537SWarner Losh# 50c16b537SWarner Losh# This source code is licensed under both the BSD-style license (found in the 60c16b537SWarner Losh# LICENSE file in the root directory of this source tree) and the GPLv2 (found 70c16b537SWarner Losh# in the COPYING file in the root directory of this source tree). 80c16b537SWarner Losh# ########################################################################## 90c16b537SWarner Losh# zstd : Command Line Utility, supporting gzip-like arguments 100c16b537SWarner Losh# zstd32 : Same as zstd, but forced to compile in 32-bits mode 110c16b537SWarner Losh# zstd_nolegacy : zstd without support of decompression of legacy versions 120c16b537SWarner Losh# zstd-small : minimal zstd without dictionary builder and benchmark 130c16b537SWarner Losh# zstd-compress : compressor-only version of zstd 140c16b537SWarner Losh# zstd-decompress : decompressor-only version of zstd 150c16b537SWarner Losh# ########################################################################## 160c16b537SWarner Losh 170c16b537SWarner LoshZSTDDIR = ../lib 180c16b537SWarner Losh 190c16b537SWarner Losh# Version numbers 200c16b537SWarner LoshLIBVER_SRC := $(ZSTDDIR)/zstd.h 210c16b537SWarner LoshLIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 220c16b537SWarner LoshLIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 230c16b537SWarner LoshLIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 240c16b537SWarner LoshLIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 250c16b537SWarner LoshLIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 260c16b537SWarner LoshLIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 270c16b537SWarner LoshLIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 280c16b537SWarner LoshLIBVER := $(shell echo $(LIBVER_SCRIPT)) 290c16b537SWarner Losh 300c16b537SWarner LoshZSTD_VERSION = $(LIBVER) 310c16b537SWarner Losh 32*a0483764SConrad MeyerHAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0) 33*a0483764SConrad MeyerGREP_OPTIONS ?= 34*a0483764SConrad Meyerifeq ($HAVE_COLORNEVER, 1) 35*a0483764SConrad MeyerGREP_OPTIONS += --color=never 36*a0483764SConrad Meyerendif 37*a0483764SConrad MeyerGREP = grep $(GREP_OPTIONS) 380f743729SConrad Meyer 390f743729SConrad Meyerifeq ($(shell $(CC) -v 2>&1 | $(GREP) -c "gcc version "), 1) 400c16b537SWarner LoshALIGN_LOOP = -falign-loops=32 410c16b537SWarner Loshelse 420c16b537SWarner LoshALIGN_LOOP = 430c16b537SWarner Loshendif 440c16b537SWarner Losh 450c16b537SWarner LoshCPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \ 460c16b537SWarner Losh -I$(ZSTDDIR)/dictBuilder \ 47052d3c12SConrad Meyer -DXXH_NAMESPACE=ZSTD_ 480f743729SConrad Meyerifeq ($(OS),Windows_NT) # MinGW assumed 490f743729SConrad MeyerCPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting 500f743729SConrad Meyerendif 510c16b537SWarner LoshCFLAGS ?= -O3 520c16b537SWarner LoshDEBUGFLAGS+=-Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 530c16b537SWarner Losh -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ 540c16b537SWarner Losh -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \ 550c16b537SWarner Losh -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ 56*a0483764SConrad Meyer -Wredundant-decls -Wmissing-prototypes -Wc++-compat 570c16b537SWarner LoshCFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) 580c16b537SWarner LoshFLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) 590c16b537SWarner Losh 600c16b537SWarner Losh 610c16b537SWarner LoshZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c 620c16b537SWarner LoshZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c 630c16b537SWarner LoshZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c 640c16b537SWarner LoshZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) 650c16b537SWarner LoshZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c 660c16b537SWarner LoshZSTDDECOMP_O = $(ZSTDDIR)/decompress/zstd_decompress.o 670c16b537SWarner Losh 680f743729SConrad MeyerZSTD_LEGACY_SUPPORT ?= 5 690c16b537SWarner LoshZSTDLEGACY_FILES := 700c16b537SWarner Loshifneq ($(ZSTD_LEGACY_SUPPORT), 0) 710c16b537SWarner Loshifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0) 720f743729SConrad Meyer ZSTDLEGACY_FILES += $(shell ls $(ZSTDDIR)/legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]') 730c16b537SWarner Loshendif 740c16b537SWarner Losh CPPFLAGS += -I$(ZSTDDIR)/legacy 750c16b537SWarner Loshelse 760c16b537SWarner Loshendif 770c16b537SWarner Losh 78052d3c12SConrad Meyer# Sort files in alphabetical order for reproducible builds 790c16b537SWarner LoshZSTDLIB_FILES := $(sort $(wildcard $(ZSTD_FILES)) $(wildcard $(ZSTDLEGACY_FILES)) $(wildcard $(ZDICT_FILES))) 800c16b537SWarner Losh 810c16b537SWarner Losh# Define *.exe as extension for Windows systems 820c16b537SWarner Loshifneq (,$(filter Windows%,$(OS))) 830c16b537SWarner LoshEXT =.exe 840c16b537SWarner LoshRES64_FILE = windres/zstd64.res 850c16b537SWarner LoshRES32_FILE = windres/zstd32.res 860c16b537SWarner Loshifneq (,$(filter x86_64%,$(shell $(CC) -dumpmachine))) 870c16b537SWarner Losh RES_FILE = $(RES64_FILE) 880c16b537SWarner Loshelse 890c16b537SWarner Losh RES_FILE = $(RES32_FILE) 900c16b537SWarner Loshendif 910c16b537SWarner Loshelse 920c16b537SWarner LoshEXT = 930c16b537SWarner Loshendif 940c16b537SWarner Losh 950c16b537SWarner LoshVOID = /dev/null 960c16b537SWarner Losh 970c16b537SWarner Losh# thread detection 980c16b537SWarner LoshNO_THREAD_MSG := ==> no threads, building without multithreading support 99*a0483764SConrad MeyerHAVE_PTHREAD := $(shell printf '\#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) 1000c16b537SWarner LoshHAVE_THREAD := $(shell [ "$(HAVE_PTHREAD)" -eq "1" -o -n "$(filter Windows%,$(OS))" ] && echo 1 || echo 0) 1010c16b537SWarner Loshifeq ($(HAVE_THREAD), 1) 1020c16b537SWarner LoshTHREAD_MSG := ==> building with threading support 1030c16b537SWarner LoshTHREAD_CPP := -DZSTD_MULTITHREAD 1040c16b537SWarner LoshTHREAD_LD := -pthread 1050c16b537SWarner Loshelse 1060c16b537SWarner LoshTHREAD_MSG := $(NO_THREAD_MSG) 1070c16b537SWarner Loshendif 1080c16b537SWarner Losh 1090c16b537SWarner Losh# zlib detection 1100c16b537SWarner LoshNO_ZLIB_MSG := ==> no zlib, building zstd without .gz support 111*a0483764SConrad MeyerHAVE_ZLIB := $(shell printf '\#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) 1120c16b537SWarner Loshifeq ($(HAVE_ZLIB), 1) 1130c16b537SWarner LoshZLIB_MSG := ==> building zstd with .gz compression support 1140c16b537SWarner LoshZLIBCPP = -DZSTD_GZCOMPRESS -DZSTD_GZDECOMPRESS 1150c16b537SWarner LoshZLIBLD = -lz 1160c16b537SWarner Loshelse 1170c16b537SWarner LoshZLIB_MSG := $(NO_ZLIB_MSG) 1180c16b537SWarner Loshendif 1190c16b537SWarner Losh 1200c16b537SWarner Losh# lzma detection 1210c16b537SWarner LoshNO_LZMA_MSG := ==> no liblzma, building zstd without .xz/.lzma support 122*a0483764SConrad MeyerHAVE_LZMA := $(shell printf '\#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) 1230c16b537SWarner Loshifeq ($(HAVE_LZMA), 1) 1240c16b537SWarner LoshLZMA_MSG := ==> building zstd with .xz/.lzma compression support 1250c16b537SWarner LoshLZMACPP = -DZSTD_LZMACOMPRESS -DZSTD_LZMADECOMPRESS 1260c16b537SWarner LoshLZMALD = -llzma 1270c16b537SWarner Loshelse 1280c16b537SWarner LoshLZMA_MSG := $(NO_LZMA_MSG) 1290c16b537SWarner Loshendif 1300c16b537SWarner Losh 1310c16b537SWarner Losh# lz4 detection 1320c16b537SWarner LoshNO_LZ4_MSG := ==> no liblz4, building zstd without .lz4 support 133*a0483764SConrad MeyerHAVE_LZ4 := $(shell printf '\#include <lz4frame.h>\n\#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) 1340c16b537SWarner Loshifeq ($(HAVE_LZ4), 1) 1350c16b537SWarner LoshLZ4_MSG := ==> building zstd with .lz4 compression support 1360c16b537SWarner LoshLZ4CPP = -DZSTD_LZ4COMPRESS -DZSTD_LZ4DECOMPRESS 1370c16b537SWarner LoshLZ4LD = -llz4 1380c16b537SWarner Loshelse 1390c16b537SWarner LoshLZ4_MSG := $(NO_LZ4_MSG) 1400c16b537SWarner Loshendif 1410c16b537SWarner Losh 1420f743729SConrad Meyer# explicit backtrace enable/disable for Linux & Darwin 1430f743729SConrad Meyerifeq ($(BACKTRACE), 0) 1440f743729SConrad MeyerDEBUGFLAGS += -DBACKTRACE_ENABLE=0 1450f743729SConrad Meyerendif 1460f743729SConrad Meyerifeq (,$(filter Windows%, $(OS))) 1470f743729SConrad Meyerifeq ($(BACKTRACE), 1) 1480f743729SConrad MeyerDEBUGFLAGS += -DBACKTRACE_ENABLE=1 1490f743729SConrad MeyerDEBUGFLAGS_LD += -rdynamic 1500f743729SConrad Meyerendif 1510f743729SConrad Meyerendif 1520f743729SConrad Meyer 1530f743729SConrad Meyer 1540c16b537SWarner Losh.PHONY: default 1550c16b537SWarner Loshdefault: zstd-release 1560c16b537SWarner Losh 1570c16b537SWarner Losh.PHONY: all 1580c16b537SWarner Loshall: zstd 1590c16b537SWarner Losh 1600c16b537SWarner Losh.PHONY: allVariants 1610c16b537SWarner LoshallVariants: zstd zstd-compress zstd-decompress zstd-small zstd-nolegacy 1620c16b537SWarner Losh 1630c16b537SWarner Losh$(ZSTDDECOMP_O): CFLAGS += $(ALIGN_LOOP) 1640c16b537SWarner Losh 1650c16b537SWarner Loshzstd : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP) 1660f743729SConrad Meyerzstd : LDFLAGS += $(THREAD_LD) $(ZLIBLD) $(LZMALD) $(LZ4LD) $(DEBUGFLAGS_LD) 1670c16b537SWarner Loshzstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) 168*a0483764SConrad Meyerzstd : $(ZSTDLIB_FILES) zstdcli.o util.o fileio.o benchfn.o benchzstd.o datagen.o dibio.o 1690c16b537SWarner Losh @echo "$(THREAD_MSG)" 1700c16b537SWarner Losh @echo "$(ZLIB_MSG)" 1710c16b537SWarner Losh @echo "$(LZMA_MSG)" 1720c16b537SWarner Losh @echo "$(LZ4_MSG)" 1730c16b537SWarner Loshifneq (,$(filter Windows%,$(OS))) 1740c16b537SWarner Losh windres/generate_res.bat 1750c16b537SWarner Loshendif 1760c16b537SWarner Losh $(CC) $(FLAGS) $^ $(RES_FILE) -o $@$(EXT) $(LDFLAGS) 1770c16b537SWarner Losh 1780c16b537SWarner Losh.PHONY: zstd-release 1790f743729SConrad Meyerzstd-release: DEBUGFLAGS := -DBACKTRACE_ENABLE=0 1800f743729SConrad Meyerzstd-release: DEBUGFLAGS_LD := 1810c16b537SWarner Loshzstd-release: zstd 1820c16b537SWarner Losh 18319fcbaf1SConrad Meyerzstd32 : CPPFLAGS += $(THREAD_CPP) 18419fcbaf1SConrad Meyerzstd32 : LDFLAGS += $(THREAD_LD) 1850c16b537SWarner Loshzstd32 : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) 186*a0483764SConrad Meyerzstd32 : $(ZSTDLIB_FILES) zstdcli.c util.c fileio.c benchfn.c benchzstd.c datagen.c dibio.c 1870c16b537SWarner Loshifneq (,$(filter Windows%,$(OS))) 1880c16b537SWarner Losh windres/generate_res.bat 1890c16b537SWarner Loshendif 1900c16b537SWarner Losh $(CC) -m32 $(FLAGS) $^ $(RES32_FILE) -o $@$(EXT) 1910c16b537SWarner Losh 192*a0483764SConrad Meyerzstd-nolegacy : $(ZSTD_FILES) $(ZDICT_FILES) zstdcli.o util.o fileio.c benchfn.o benchzstd.o datagen.o dibio.o 1930c16b537SWarner Losh $(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS) 1940c16b537SWarner Losh 1950c16b537SWarner Loshzstd-nomt : THREAD_CPP := 1960c16b537SWarner Loshzstd-nomt : THREAD_LD := 1970c16b537SWarner Loshzstd-nomt : THREAD_MSG := - multi-threading disabled 1980c16b537SWarner Loshzstd-nomt : zstd 1990c16b537SWarner Losh 2000c16b537SWarner Loshzstd-nogz : ZLIBCPP := 2010c16b537SWarner Loshzstd-nogz : ZLIBLD := 2020c16b537SWarner Loshzstd-nogz : ZLIB_MSG := - gzip support is disabled 2030c16b537SWarner Loshzstd-nogz : zstd 2040c16b537SWarner Losh 2050c16b537SWarner Loshzstd-noxz : LZMACPP := 2060c16b537SWarner Loshzstd-noxz : LZMALD := 2070c16b537SWarner Loshzstd-noxz : LZMA_MSG := - xz/lzma support is disabled 2080c16b537SWarner Loshzstd-noxz : zstd 2090c16b537SWarner Losh 2100c16b537SWarner Losh 211*a0483764SConrad Meyerzstd-pgo : 212*a0483764SConrad Meyer $(MAKE) clean 213*a0483764SConrad Meyer $(MAKE) zstd MOREFLAGS=-fprofile-generate 2140c16b537SWarner Losh ./zstd -b19i1 $(PROFILE_WITH) 2150c16b537SWarner Losh ./zstd -b16i1 $(PROFILE_WITH) 2160c16b537SWarner Losh ./zstd -b9i2 $(PROFILE_WITH) 2170c16b537SWarner Losh ./zstd -b $(PROFILE_WITH) 2180c16b537SWarner Losh ./zstd -b7i2 $(PROFILE_WITH) 2190c16b537SWarner Losh ./zstd -b5 $(PROFILE_WITH) 220*a0483764SConrad Meyer $(RM) zstd *.o $(ZSTDDECOMP_O) $(ZSTDDIR)/compress/*.o 2210c16b537SWarner Losh $(MAKE) zstd MOREFLAGS=-fprofile-use 2220c16b537SWarner Losh 2230c16b537SWarner Losh# minimal target, with only zstd compression and decompression. no bench. no legacy. 2240c16b537SWarner Loshzstd-small: CFLAGS = -Os -s 225*a0483764SConrad Meyerzstd-frugal zstd-small: $(ZSTD_FILES) zstdcli.c util.c fileio.c 2260c16b537SWarner Losh $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT $^ -o $@$(EXT) 2270c16b537SWarner Losh 228*a0483764SConrad Meyerzstd-decompress: $(ZSTDCOMMON_FILES) $(ZSTDDECOMP_FILES) zstdcli.c util.c fileio.c 2290c16b537SWarner Losh $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOCOMPRESS $^ -o $@$(EXT) 2300c16b537SWarner Losh 231*a0483764SConrad Meyerzstd-compress: $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) zstdcli.c util.c fileio.c 2320c16b537SWarner Losh $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NODECOMPRESS $^ -o $@$(EXT) 2330c16b537SWarner Losh 2340c16b537SWarner Loshzstdmt: zstd 2350c16b537SWarner Losh ln -sf zstd zstdmt 2360c16b537SWarner Losh 2370c16b537SWarner Losh.PHONY: generate_res 2380c16b537SWarner Loshgenerate_res: 2390c16b537SWarner Losh windres/generate_res.bat 2400c16b537SWarner Losh 2410c16b537SWarner Losh.PHONY: clean 2420c16b537SWarner Loshclean: 2430c16b537SWarner Losh $(MAKE) -C $(ZSTDDIR) clean 2440c16b537SWarner Losh @$(RM) $(ZSTDDIR)/decompress/*.o $(ZSTDDIR)/decompress/zstd_decompress.gcda 2450c16b537SWarner Losh @$(RM) core *.o tmp* result* *.gcda dictionary *.zst \ 2460c16b537SWarner Losh zstd$(EXT) zstd32$(EXT) zstd-compress$(EXT) zstd-decompress$(EXT) \ 2470c16b537SWarner Losh zstd-small$(EXT) zstd-frugal$(EXT) zstd-nolegacy$(EXT) zstd4$(EXT) \ 2480c16b537SWarner Losh *.gcda default.profraw have_zlib$(EXT) 2490c16b537SWarner Losh @echo Cleaning completed 2500c16b537SWarner Losh 2510c16b537SWarner LoshMD2ROFF = ronn 2520c16b537SWarner LoshMD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="zstd $(ZSTD_VERSION)" 2530c16b537SWarner Losh 254052d3c12SConrad Meyerzstd.1: zstd.1.md ../lib/zstd.h 255052d3c12SConrad Meyer cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 2560c16b537SWarner Losh 2570f743729SConrad Meyerzstdgrep.1: zstdgrep.1.md ../lib/zstd.h 2580f743729SConrad Meyer cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 2590f743729SConrad Meyer 2600f743729SConrad Meyerzstdless.1: zstdless.1.md ../lib/zstd.h 2610f743729SConrad Meyer cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 2620f743729SConrad Meyer 2630c16b537SWarner Losh.PHONY: man 2640f743729SConrad Meyerman: zstd.1 zstdgrep.1 zstdless.1 2650c16b537SWarner Losh 2660c16b537SWarner Losh.PHONY: clean-man 2670c16b537SWarner Loshclean-man: 2680c16b537SWarner Losh rm zstd.1 2690f743729SConrad Meyer rm zstdgrep.1 2700f743729SConrad Meyer rm zstdless.1 2710c16b537SWarner Losh 2720c16b537SWarner Losh.PHONY: preview-man 2730c16b537SWarner Loshpreview-man: clean-man man 2740c16b537SWarner Losh man ./zstd.1 2750f743729SConrad Meyer man ./zstdgrep.1 2760f743729SConrad Meyer man ./zstdless.1 2770c16b537SWarner Losh 2780c16b537SWarner Losh#----------------------------------------------------------------------------- 2790f743729SConrad Meyer# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets 2800c16b537SWarner Losh#----------------------------------------------------------------------------- 2810f743729SConrad Meyerifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku)) 2820c16b537SWarner Losh 283*a0483764SConrad MeyerHAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0) 284*a0483764SConrad MeyerEGREP_OPTIONS ?= 285*a0483764SConrad Meyerifeq ($HAVE_COLORNEVER, 1) 286*a0483764SConrad MeyerEGREP_OPTIONS += --color=never 287*a0483764SConrad Meyerendif 288*a0483764SConrad MeyerEGREP = egrep $(EGREP_OPTIONS) 2890f743729SConrad Meyer 2900f743729SConrad Meyer# Print a two column output of targets and their description. To add a target description, put a 2910f743729SConrad Meyer# comment in the Makefile with the format "## <TARGET>: <DESCRIPTION>". For example: 2920f743729SConrad Meyer# 2930f743729SConrad Meyer## list: Print all targets and their descriptions (if provided) 2940c16b537SWarner Losh.PHONY: list 2950c16b537SWarner Loshlist: 2960f743729SConrad Meyer @TARGETS=$$($(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null \ 2970f743729SConrad Meyer | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \ 2980f743729SConrad Meyer | $(EGREP) -v -e '^[^[:alnum:]]' | sort); \ 2990f743729SConrad Meyer { \ 3000f743729SConrad Meyer printf "Target Name\tDescription\n"; \ 3010f743729SConrad Meyer printf "%0.s-" {1..16}; printf "\t"; printf "%0.s-" {1..40}; printf "\n"; \ 3020f743729SConrad Meyer for target in $$TARGETS; do \ 3030f743729SConrad Meyer line=$$($(EGREP) "^##[[:space:]]+$$target:" $(lastword $(MAKEFILE_LIST))); \ 3040f743729SConrad Meyer description=$$(echo $$line | awk '{i=index($$0,":"); print substr($$0,i+1)}' | xargs); \ 3050f743729SConrad Meyer printf "$$target\t$$description\n"; \ 3060f743729SConrad Meyer done \ 3070f743729SConrad Meyer } | column -t -s $$'\t' 3080f743729SConrad Meyer 3090c16b537SWarner Losh 3100c16b537SWarner LoshDESTDIR ?= 3110c16b537SWarner Losh# directory variables : GNU conventions prefer lowercase 3120c16b537SWarner Losh# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 3130c16b537SWarner Losh# support both lower and uppercase (BSD), use uppercase in script 3140c16b537SWarner Loshprefix ?= /usr/local 3150c16b537SWarner LoshPREFIX ?= $(prefix) 3160c16b537SWarner Loshexec_prefix ?= $(PREFIX) 3170c16b537SWarner Loshbindir ?= $(exec_prefix)/bin 3180c16b537SWarner LoshBINDIR ?= $(bindir) 3190c16b537SWarner Loshdatarootdir ?= $(PREFIX)/share 3200c16b537SWarner Loshmandir ?= $(datarootdir)/man 3210c16b537SWarner Loshman1dir ?= $(mandir)/man1 3220c16b537SWarner Losh 3230c16b537SWarner Loshifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly SunOS)) 324052d3c12SConrad MeyerMANDIR ?= $(PREFIX)/man 325052d3c12SConrad MeyerMAN1DIR ?= $(MANDIR)/man1 3260c16b537SWarner Loshelse 327052d3c12SConrad MeyerMAN1DIR ?= $(man1dir) 3280c16b537SWarner Loshendif 3290c16b537SWarner Losh 3300c16b537SWarner Loshifneq (,$(filter $(shell uname),SunOS)) 3310c16b537SWarner LoshINSTALL ?= ginstall 3320c16b537SWarner Loshelse 3330c16b537SWarner LoshINSTALL ?= install 3340c16b537SWarner Loshendif 3350c16b537SWarner Losh 3360c16b537SWarner LoshINSTALL_PROGRAM ?= $(INSTALL) 3370c16b537SWarner LoshINSTALL_SCRIPT ?= $(INSTALL_PROGRAM) 3380c16b537SWarner LoshINSTALL_DATA ?= $(INSTALL) -m 644 3390c16b537SWarner LoshINSTALL_MAN ?= $(INSTALL_DATA) 3400c16b537SWarner Losh 3410c16b537SWarner Losh.PHONY: install 3420c16b537SWarner Loshinstall: zstd 3430c16b537SWarner Losh @echo Installing binaries 344052d3c12SConrad Meyer @$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MAN1DIR)/ 3450c16b537SWarner Losh @$(INSTALL_PROGRAM) zstd $(DESTDIR)$(BINDIR)/zstd 3460c16b537SWarner Losh @ln -sf zstd $(DESTDIR)$(BINDIR)/zstdcat 3470c16b537SWarner Losh @ln -sf zstd $(DESTDIR)$(BINDIR)/unzstd 3480c16b537SWarner Losh @ln -sf zstd $(DESTDIR)$(BINDIR)/zstdmt 3490c16b537SWarner Losh @$(INSTALL_SCRIPT) zstdless $(DESTDIR)$(BINDIR)/zstdless 3500c16b537SWarner Losh @$(INSTALL_SCRIPT) zstdgrep $(DESTDIR)$(BINDIR)/zstdgrep 3510c16b537SWarner Losh @echo Installing man pages 352052d3c12SConrad Meyer @$(INSTALL_MAN) zstd.1 $(DESTDIR)$(MAN1DIR)/zstd.1 353052d3c12SConrad Meyer @ln -sf zstd.1 $(DESTDIR)$(MAN1DIR)/zstdcat.1 354052d3c12SConrad Meyer @ln -sf zstd.1 $(DESTDIR)$(MAN1DIR)/unzstd.1 3550f743729SConrad Meyer @$(INSTALL_MAN) zstdgrep.1 $(DESTDIR)$(MAN1DIR)/zstdgrep.1 3560f743729SConrad Meyer @$(INSTALL_MAN) zstdless.1 $(DESTDIR)$(MAN1DIR)/zstdless.1 3570c16b537SWarner Losh @echo zstd installation completed 3580c16b537SWarner Losh 3590c16b537SWarner Losh.PHONY: uninstall 3600c16b537SWarner Loshuninstall: 3610c16b537SWarner Losh @$(RM) $(DESTDIR)$(BINDIR)/zstdgrep 3620c16b537SWarner Losh @$(RM) $(DESTDIR)$(BINDIR)/zstdless 3630c16b537SWarner Losh @$(RM) $(DESTDIR)$(BINDIR)/zstdcat 3640c16b537SWarner Losh @$(RM) $(DESTDIR)$(BINDIR)/unzstd 365*a0483764SConrad Meyer @$(RM) $(DESTDIR)$(BINDIR)/zstdmt 3660c16b537SWarner Losh @$(RM) $(DESTDIR)$(BINDIR)/zstd 3670f743729SConrad Meyer @$(RM) $(DESTDIR)$(MAN1DIR)/zstdless.1 3680f743729SConrad Meyer @$(RM) $(DESTDIR)$(MAN1DIR)/zstdgrep.1 369052d3c12SConrad Meyer @$(RM) $(DESTDIR)$(MAN1DIR)/zstdcat.1 370052d3c12SConrad Meyer @$(RM) $(DESTDIR)$(MAN1DIR)/unzstd.1 371052d3c12SConrad Meyer @$(RM) $(DESTDIR)$(MAN1DIR)/zstd.1 3720c16b537SWarner Losh @echo zstd programs successfully uninstalled 3730c16b537SWarner Losh 3740c16b537SWarner Loshendif 375