Bug 1890793: Assert CallArgs::newTarget is not gray. r=spidermonkey-reviewers,sfink...
[gecko.git] / third_party / zstd / lib / libzstd.mk
blob14b3b11d684e2d33847f51fbd7cd50ba8ff92100
1 # ################################################################
2 # Copyright (c) Meta Platforms, Inc. and affiliates.
3 # All rights reserved.
5 # This source code is licensed under both the BSD-style license (found in the
6 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 # in the COPYING file in the root directory of this source tree).
8 # You may select, at your option, one of the above-listed licenses.
9 # ################################################################
11 # This included Makefile provides the following variables :
12 # LIB_SRCDIR, LIB_BINDIR
14 # Ensure the file is not included twice
15 # Note : must be included after setting the default target
16 ifndef LIBZSTD_MK_INCLUDED
17 LIBZSTD_MK_INCLUDED := 1
19 ##################################################################
20 # Input Variables
21 ##################################################################
23 # By default, library's directory is same as this included makefile
24 LIB_SRCDIR ?= $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
25 LIB_BINDIR ?= $(LIBSRC_DIR)
27 # ZSTD_LIB_MINIFY is a helper variable that
28 # configures a bunch of other variables to space-optimized defaults.
29 ZSTD_LIB_MINIFY ?= 0
31 # Legacy support
32 ifneq ($(ZSTD_LIB_MINIFY), 0)
33 ZSTD_LEGACY_SUPPORT ?= 0
34 else
35 ZSTD_LEGACY_SUPPORT ?= 5
36 endif
37 ZSTD_LEGACY_MULTITHREADED_API ?= 0
39 # Build size optimizations
40 ifneq ($(ZSTD_LIB_MINIFY), 0)
41 HUF_FORCE_DECOMPRESS_X1 ?= 1
42 HUF_FORCE_DECOMPRESS_X2 ?= 0
43 ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ?= 1
44 ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG ?= 0
45 ZSTD_NO_INLINE ?= 1
46 ZSTD_STRIP_ERROR_STRINGS ?= 1
47 else
48 HUF_FORCE_DECOMPRESS_X1 ?= 0
49 HUF_FORCE_DECOMPRESS_X2 ?= 0
50 ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ?= 0
51 ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG ?= 0
52 ZSTD_NO_INLINE ?= 0
53 ZSTD_STRIP_ERROR_STRINGS ?= 0
54 endif
56 # Assembly support
57 ZSTD_NO_ASM ?= 0
59 ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP ?= 0
60 ZSTD_LIB_EXCLUDE_COMPRESSORS_GREEDY_AND_UP ?= 0
62 ##################################################################
63 # libzstd helpers
64 ##################################################################
66 VOID ?= /dev/null
68 # Make 4.3 doesn't support '\#' anymore (https://lwn.net/Articles/810071/)
69 NUM_SYMBOL := \#
71 # define silent mode as default (verbose mode with V=1 or VERBOSE=1)
72 # Note : must be defined _after_ the default target
73 $(V)$(VERBOSE).SILENT:
75 # When cross-compiling from linux to windows,
76 # one might need to specify TARGET_SYSTEM as "Windows."
77 # Building from Fedora fails without it.
78 # (but Ubuntu and Debian don't need to set anything)
79 TARGET_SYSTEM ?= $(OS)
81 # Version numbers
82 LIBVER_SRC := $(LIB_SRCDIR)/zstd.h
83 LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
84 LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
85 LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
86 LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
87 LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
88 LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
89 LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
90 LIBVER := $(shell echo $(LIBVER_SCRIPT))
91 CCVER := $(shell $(CC) --version)
92 ZSTD_VERSION?= $(LIBVER)
94 ifneq ($(ZSTD_LIB_MINIFY), 0)
95 HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
96 ifneq ($(HAVE_CC_OZ), 0)
97 # Some compilers (clang) support an even more space-optimized setting.
98 CFLAGS += -Oz
99 else
100 CFLAGS += -Os
101 endif
102 CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
103 -DDYNAMIC_BMI2=0 -DNDEBUG
104 else
105 CFLAGS ?= -O3
106 endif
108 DEBUGLEVEL ?= 0
109 CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
110 ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
111 CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
112 endif
113 DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
114 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
115 -Wstrict-prototypes -Wundef -Wpointer-arith \
116 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
117 -Wredundant-decls -Wmissing-prototypes -Wc++-compat
118 CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
119 ASFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) $(CFLAGS)
120 LDFLAGS += $(MOREFLAGS)
121 FLAGS = $(CPPFLAGS) $(CFLAGS) $(ASFLAGS) $(LDFLAGS)
123 ifndef ALREADY_APPENDED_NOEXECSTACK
124 export ALREADY_APPENDED_NOEXECSTACK := 1
125 ifeq ($(shell echo "int main(int argc, char* argv[]) { (void)argc; (void)argv; return 0; }" | $(CC) $(FLAGS) -z noexecstack -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
126 LDFLAGS += -z noexecstack
127 endif
128 ifeq ($(shell echo | $(CC) $(FLAGS) -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
129 CFLAGS += -Wa,--noexecstack
130 # CFLAGS are also added to ASFLAGS
131 else ifeq ($(shell echo | $(CC) $(FLAGS) -Qunused-arguments -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
132 # See e.g.: https://github.com/android/ndk/issues/171
133 CFLAGS += -Qunused-arguments -Wa,--noexecstack
134 # CFLAGS are also added to ASFLAGS
135 endif
136 endif
138 ifeq ($(shell echo "int main(int argc, char* argv[]) { (void)argc; (void)argv; return 0; }" | $(CC) $(FLAGS) -z cet-report=error -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
139 LDFLAGS += -z cet-report=error
140 endif
142 HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
143 GREP_OPTIONS ?=
144 ifeq ($(HAVE_COLORNEVER), 1)
145 GREP_OPTIONS += --color=never
146 endif
147 GREP = grep $(GREP_OPTIONS)
149 ZSTD_COMMON_FILES := $(sort $(wildcard $(LIB_SRCDIR)/common/*.c))
150 ZSTD_COMPRESS_FILES := $(sort $(wildcard $(LIB_SRCDIR)/compress/*.c))
151 ZSTD_DECOMPRESS_FILES := $(sort $(wildcard $(LIB_SRCDIR)/decompress/*.c))
152 ZSTD_DICTBUILDER_FILES := $(sort $(wildcard $(LIB_SRCDIR)/dictBuilder/*.c))
153 ZSTD_DEPRECATED_FILES := $(sort $(wildcard $(LIB_SRCDIR)/deprecated/*.c))
154 ZSTD_LEGACY_FILES :=
156 ZSTD_DECOMPRESS_AMD64_ASM_FILES := $(sort $(wildcard $(LIB_SRCDIR)/decompress/*_amd64.S))
158 ifneq ($(ZSTD_NO_ASM), 0)
159 CPPFLAGS += -DZSTD_DISABLE_ASM
160 else
161 # Unconditionally add the ASM files they are disabled by
162 # macros in the .S file.
163 ZSTD_DECOMPRESS_FILES += $(ZSTD_DECOMPRESS_AMD64_ASM_FILES)
164 endif
166 ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
167 CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
168 endif
170 ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
171 CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
172 endif
174 ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT), 0)
175 CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT
176 endif
178 ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG), 0)
179 CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
180 endif
182 ifneq ($(ZSTD_NO_INLINE), 0)
183 CFLAGS += -DZSTD_NO_INLINE
184 endif
186 ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
187 CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
188 endif
190 ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
191 CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
192 endif
194 ifneq ($(ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP), 0)
195 CFLAGS += -DZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR
196 else
197 ifneq ($(ZSTD_LIB_EXCLUDE_COMPRESSORS_GREEDY_AND_UP), 0)
198 CFLAGS += -DZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR -DZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR
199 endif
200 endif
202 ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
203 ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
204 ZSTD_LEGACY_FILES += $(shell ls $(LIB_SRCDIR)/legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
205 endif
206 endif
207 CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
209 UNAME := $(shell uname)
211 ifndef BUILD_DIR
212 ifeq ($(UNAME), Darwin)
213 ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
214 HASH ?= md5
215 endif
216 else ifeq ($(UNAME), NetBSD)
217 HASH ?= md5 -n
218 else ifeq ($(UNAME), OpenBSD)
219 HASH ?= md5
220 endif
221 HASH ?= md5sum
223 HASH_DIR = conf_$(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ZSTD_FILES) | $(HASH) | cut -f 1 -d " " )
224 HAVE_HASH :=$(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
225 ifeq ($(HAVE_HASH),0)
226 $(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
227 BUILD_DIR := obj/generic_noconf
228 endif
229 endif # BUILD_DIR
231 ZSTD_SUBDIR := $(LIB_SRCDIR)/common $(LIB_SRCDIR)/compress $(LIB_SRCDIR)/decompress $(LIB_SRCDIR)/dictBuilder $(LIB_SRCDIR)/legacy $(LIB_SRCDIR)/deprecated
232 vpath %.c $(ZSTD_SUBDIR)
233 vpath %.S $(ZSTD_SUBDIR)
235 endif # LIBZSTD_MK_INCLUDED