gpu_neon: revive the old tests
[pcsx_rearmed.git] / deps / libchdr / deps / zstd-1.5.6 / lib / libzstd.mk
CommitLineData
648db22b 1# ################################################################
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3# All rights reserved.
4#
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# ################################################################
10
f535537f 11# This included Makefile provides the following variables :
12# LIB_SRCDIR, LIB_BINDIR
13
14# Ensure the file is not included twice
15# Note : must be included after setting the default target
16ifndef LIBZSTD_MK_INCLUDED
17LIBZSTD_MK_INCLUDED := 1
18
648db22b 19##################################################################
20# Input Variables
21##################################################################
22
f535537f 23# By default, library's directory is same as this included makefile
24LIB_SRCDIR ?= $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
25LIB_BINDIR ?= $(LIBSRC_DIR)
648db22b 26
27# ZSTD_LIB_MINIFY is a helper variable that
28# configures a bunch of other variables to space-optimized defaults.
29ZSTD_LIB_MINIFY ?= 0
30
31# Legacy support
32ifneq ($(ZSTD_LIB_MINIFY), 0)
33 ZSTD_LEGACY_SUPPORT ?= 0
34else
35 ZSTD_LEGACY_SUPPORT ?= 5
36endif
37ZSTD_LEGACY_MULTITHREADED_API ?= 0
38
39# Build size optimizations
40ifneq ($(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
47else
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
54endif
55
56# Assembly support
57ZSTD_NO_ASM ?= 0
58
f535537f 59ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP ?= 0
60ZSTD_LIB_EXCLUDE_COMPRESSORS_GREEDY_AND_UP ?= 0
61
648db22b 62##################################################################
63# libzstd helpers
64##################################################################
65
66VOID ?= /dev/null
67
68# Make 4.3 doesn't support '\#' anymore (https://lwn.net/Articles/810071/)
69NUM_SYMBOL := \#
70
71# define silent mode as default (verbose mode with V=1 or VERBOSE=1)
f535537f 72# Note : must be defined _after_ the default target
648db22b 73$(V)$(VERBOSE).SILENT:
74
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)
79TARGET_SYSTEM ?= $(OS)
80
81# Version numbers
f535537f 82LIBVER_SRC := $(LIB_SRCDIR)/zstd.h
648db22b 83LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
84LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
85LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
86LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
87LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
88LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
89LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
90LIBVER := $(shell echo $(LIBVER_SCRIPT))
91CCVER := $(shell $(CC) --version)
92ZSTD_VERSION?= $(LIBVER)
93
94ifneq ($(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)
96ifneq ($(HAVE_CC_OZ), 0)
97 # Some compilers (clang) support an even more space-optimized setting.
98 CFLAGS += -Oz
99else
100 CFLAGS += -Os
101endif
102 CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
103 -DDYNAMIC_BMI2=0 -DNDEBUG
104else
105 CFLAGS ?= -O3
106endif
107
108DEBUGLEVEL ?= 0
109CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
110ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
111 CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
112endif
113DEBUGFLAGS= -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
118CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
119ASFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) $(CFLAGS)
120LDFLAGS += $(MOREFLAGS)
121FLAGS = $(CPPFLAGS) $(CFLAGS) $(ASFLAGS) $(LDFLAGS)
122
123ifndef ALREADY_APPENDED_NOEXECSTACK
124export ALREADY_APPENDED_NOEXECSTACK := 1
125ifeq ($(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)
126LDFLAGS += -z noexecstack
127endif
128ifeq ($(shell echo | $(CC) $(FLAGS) -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
129CFLAGS += -Wa,--noexecstack
130# CFLAGS are also added to ASFLAGS
131else 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
133CFLAGS += -Qunused-arguments -Wa,--noexecstack
134# CFLAGS are also added to ASFLAGS
135endif
136endif
137
138ifeq ($(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)
139LDFLAGS += -z cet-report=error
140endif
141
142HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
143GREP_OPTIONS ?=
144ifeq ($(HAVE_COLORNEVER), 1)
145 GREP_OPTIONS += --color=never
146endif
147GREP = grep $(GREP_OPTIONS)
148
f535537f 149ZSTD_COMMON_FILES := $(sort $(wildcard $(LIB_SRCDIR)/common/*.c))
150ZSTD_COMPRESS_FILES := $(sort $(wildcard $(LIB_SRCDIR)/compress/*.c))
151ZSTD_DECOMPRESS_FILES := $(sort $(wildcard $(LIB_SRCDIR)/decompress/*.c))
152ZSTD_DICTBUILDER_FILES := $(sort $(wildcard $(LIB_SRCDIR)/dictBuilder/*.c))
153ZSTD_DEPRECATED_FILES := $(sort $(wildcard $(LIB_SRCDIR)/deprecated/*.c))
648db22b 154ZSTD_LEGACY_FILES :=
155
f535537f 156ZSTD_DECOMPRESS_AMD64_ASM_FILES := $(sort $(wildcard $(LIB_SRCDIR)/decompress/*_amd64.S))
648db22b 157
158ifneq ($(ZSTD_NO_ASM), 0)
159 CPPFLAGS += -DZSTD_DISABLE_ASM
160else
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)
164endif
165
166ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
167 CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
168endif
169
170ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
171 CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
172endif
173
174ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT), 0)
175 CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT
176endif
177
178ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG), 0)
179 CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
180endif
181
182ifneq ($(ZSTD_NO_INLINE), 0)
183 CFLAGS += -DZSTD_NO_INLINE
184endif
185
186ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
187 CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
188endif
189
190ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
191 CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
192endif
193
f535537f 194ifneq ($(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
196else
197ifneq ($(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
199endif
200endif
201
648db22b 202ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
203ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
f535537f 204 ZSTD_LEGACY_FILES += $(shell ls $(LIB_SRCDIR)/legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
648db22b 205endif
206endif
207CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
208
209UNAME := $(shell uname)
210
211ifndef BUILD_DIR
212ifeq ($(UNAME), Darwin)
213 ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
214 HASH ?= md5
215 endif
216else ifeq ($(UNAME), FreeBSD)
217 HASH ?= gmd5sum
218else ifeq ($(UNAME), NetBSD)
219 HASH ?= md5 -n
220else ifeq ($(UNAME), OpenBSD)
221 HASH ?= md5
222endif
223HASH ?= md5sum
224
225HASH_DIR = conf_$(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ZSTD_FILES) | $(HASH) | cut -f 1 -d " " )
226HAVE_HASH :=$(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
227ifeq ($(HAVE_HASH),0)
228 $(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
229 BUILD_DIR := obj/generic_noconf
230endif
231endif # BUILD_DIR
232
f535537f 233ZSTD_SUBDIR := $(LIB_SRCDIR)/common $(LIB_SRCDIR)/compress $(LIB_SRCDIR)/decompress $(LIB_SRCDIR)/dictBuilder $(LIB_SRCDIR)/legacy $(LIB_SRCDIR)/deprecated
648db22b 234vpath %.c $(ZSTD_SUBDIR)
235vpath %.S $(ZSTD_SUBDIR)
f535537f 236
237endif # LIBZSTD_MK_INCLUDED