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 11.PHONY: libzstd 12libzstd: 13 rm -rf linux 14 mkdir -p linux 15 mkdir -p linux/include/linux 16 mkdir -p linux/lib/zstd 17 ../freestanding_lib/freestanding.py \ 18 --source-lib ../../lib \ 19 --output-lib linux/lib/zstd \ 20 --xxhash '<linux/xxhash.h>' \ 21 --xxh64-state 'struct xxh64_state' \ 22 --xxh64-prefix 'xxh64' \ 23 --rewrite-include '<limits\.h>=<linux/limits.h>' \ 24 --rewrite-include '<stddef\.h>=<linux/types.h>' \ 25 --rewrite-include '"\.\./zstd.h"=<linux/zstd.h>' \ 26 --rewrite-include '"(\.\./)?zstd_errors.h"=<linux/zstd_errors.h>' \ 27 --sed 's,/\*\*\*,/* *,g' \ 28 --sed 's,/\*\*,/*,g' \ 29 --spdx \ 30 -DZSTD_NO_INTRINSICS \ 31 -DZSTD_NO_UNUSED_FUNCTIONS \ 32 -DZSTD_LEGACY_SUPPORT=0 \ 33 -DZSTD_STATIC_LINKING_ONLY \ 34 -DFSE_STATIC_LINKING_ONLY \ 35 -DXXH_STATIC_LINKING_ONLY \ 36 -D__GNUC__ \ 37 -D__linux__=1 \ 38 -DSTATIC_BMI2=0 \ 39 -DZSTD_ADDRESS_SANITIZER=0 \ 40 -DZSTD_MEMORY_SANITIZER=0 \ 41 -DZSTD_DATAFLOW_SANITIZER=0 \ 42 -DZSTD_COMPRESS_HEAPMODE=1 \ 43 -UNO_PREFETCH \ 44 -U__cplusplus \ 45 -UZSTD_DLL_EXPORT \ 46 -UZSTD_DLL_IMPORT \ 47 -U__ICCARM__ \ 48 -UZSTD_MULTITHREAD \ 49 -U_MSC_VER \ 50 -U_WIN32 \ 51 -RZSTDLIB_VISIBLE= \ 52 -RZSTDERRORLIB_VISIBLE= \ 53 -RZSTD_FALLTHROUGH=fallthrough \ 54 -DZSTD_HAVE_WEAK_SYMBOLS=0 \ 55 -DZSTD_TRACE=0 \ 56 -DZSTD_NO_TRACE \ 57 -DZSTD_DISABLE_ASM \ 58 -DZSTD_LINUX_KERNEL 59 rm linux/lib/zstd/decompress/huf_decompress_amd64.S 60 mv linux/lib/zstd/zstd.h linux/include/linux/zstd_lib.h 61 mv linux/lib/zstd/zstd_errors.h linux/include/linux/ 62 cp linux_zstd.h linux/include/linux/zstd.h 63 cp zstd_common_module.c linux/lib/zstd 64 cp zstd_compress_module.c linux/lib/zstd 65 cp zstd_decompress_module.c linux/lib/zstd 66 cp decompress_sources.h linux/lib/zstd 67 cp linux.mk linux/lib/zstd/Makefile 68 69LINUX ?= $(HOME)/repos/linux 70 71.PHONY: import 72import: libzstd 73 rm -f $(LINUX)/include/linux/zstd.h 74 rm -f $(LINUX)/include/linux/zstd_errors.h 75 rm -rf $(LINUX)/lib/zstd 76 cp linux/include/linux/zstd.h $(LINUX)/include/linux 77 cp linux/include/linux/zstd_lib.h $(LINUX)/include/linux 78 cp linux/include/linux/zstd_errors.h $(LINUX)/include/linux 79 cp -r linux/lib/zstd $(LINUX)/lib 80 81import-upstream: 82 rm -rf $(LINUX)/lib/zstd 83 mkdir $(LINUX)/lib/zstd 84 cp ../../lib/zstd.h $(LINUX)/include/linux/zstd_lib.h 85 cp -r ../../lib/common $(LINUX)/lib/zstd 86 cp -r ../../lib/compress $(LINUX)/lib/zstd 87 cp -r ../../lib/decompress $(LINUX)/lib/zstd 88 mv $(LINUX)/lib/zstd/zstd_errors.h $(LINUX)/include/linux 89 rm $(LINUX)/lib/zstd/common/threading.* 90 rm $(LINUX)/lib/zstd/common/pool.* 91 rm $(LINUX)/lib/zstd/common/xxhash.* 92 rm $(LINUX)/lib/zstd/compress/zstdmt_* 93 94DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 95 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ 96 -Wstrict-prototypes -Wundef -Wpointer-arith \ 97 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ 98 -Wredundant-decls -Wmissing-prototypes -Wc++-compat \ 99 -Wimplicit-fallthrough 100 101.PHONY: test 102test: libzstd 103 $(MAKE) -C test run-test CFLAGS="-O3 $(CFLAGS) $(DEBUGFLAGS) -Werror" -j 104 105.PHONY: clean 106clean: 107 $(RM) -rf linux 108 $(MAKE) -C test clean 109