1# ################################################################ 2# Copyright (c) Facebook, Inc. 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 -DZSTD_NO_INTRINSICS \ 30 -DZSTD_NO_UNUSED_FUNCTIONS \ 31 -DZSTD_LEGACY_SUPPORT=0 \ 32 -DZSTD_STATIC_LINKING_ONLY \ 33 -DFSE_STATIC_LINKING_ONLY \ 34 -DHUF_STATIC_LINKING_ONLY \ 35 -DXXH_STATIC_LINKING_ONLY \ 36 -DMEM_FORCE_MEMORY_ACCESS=0 \ 37 -D__GNUC__ \ 38 -D__linux__=1 \ 39 -DSTATIC_BMI2=0 \ 40 -DZSTD_ADDRESS_SANITIZER=0 \ 41 -DZSTD_MEMORY_SANITIZER=0 \ 42 -DZSTD_DATAFLOW_SANITIZER=0 \ 43 -DZSTD_COMPRESS_HEAPMODE=1 \ 44 -UNO_PREFETCH \ 45 -U__cplusplus \ 46 -UZSTD_DLL_EXPORT \ 47 -UZSTD_DLL_IMPORT \ 48 -U__ICCARM__ \ 49 -UZSTD_MULTITHREAD \ 50 -U_MSC_VER \ 51 -U_WIN32 \ 52 -RZSTDLIB_VISIBILITY= \ 53 -RZSTDERRORLIB_VISIBILITY= \ 54 -RZSTD_FALLTHROUGH=fallthrough \ 55 -DZSTD_HAVE_WEAK_SYMBOLS=0 \ 56 -DZSTD_TRACE=0 \ 57 -DZSTD_NO_TRACE \ 58 -DZSTD_LINUX_KERNEL 59 mv linux/lib/zstd/zstd.h linux/include/linux/zstd_lib.h 60 mv linux/lib/zstd/zstd_errors.h linux/include/linux/ 61 cp linux_zstd.h linux/include/linux/zstd.h 62 cp zstd_compress_module.c linux/lib/zstd 63 cp zstd_decompress_module.c linux/lib/zstd 64 cp decompress_sources.h linux/lib/zstd 65 cp linux.mk linux/lib/zstd/Makefile 66 67LINUX ?= $(HOME)/repos/linux 68 69.PHONY: import 70import: libzstd 71 rm -f $(LINUX)/include/linux/zstd.h 72 rm -f $(LINUX)/include/linux/zstd_errors.h 73 rm -rf $(LINUX)/lib/zstd 74 cp linux/include/linux/zstd.h $(LINUX)/include/linux 75 cp linux/include/linux/zstd_lib.h $(LINUX)/include/linux 76 cp linux/include/linux/zstd_errors.h $(LINUX)/include/linux 77 cp -r linux/lib/zstd $(LINUX)/lib 78 79import-upstream: 80 rm -rf $(LINUX)/lib/zstd 81 mkdir $(LINUX)/lib/zstd 82 cp ../../lib/zstd.h $(LINUX)/include/linux/zstd_lib.h 83 cp -r ../../lib/common $(LINUX)/lib/zstd 84 cp -r ../../lib/compress $(LINUX)/lib/zstd 85 cp -r ../../lib/decompress $(LINUX)/lib/zstd 86 mv $(LINUX)/lib/zstd/zstd_errors.h $(LINUX)/include/linux 87 rm $(LINUX)/lib/zstd/common/threading.* 88 rm $(LINUX)/lib/zstd/common/pool.* 89 rm $(LINUX)/lib/zstd/common/xxhash.* 90 rm $(LINUX)/lib/zstd/compress/zstdmt_* 91 92DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 93 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ 94 -Wstrict-prototypes -Wundef -Wpointer-arith \ 95 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ 96 -Wredundant-decls -Wmissing-prototypes -Wc++-compat \ 97 -Wimplicit-fallthrough 98 99.PHONY: test 100test: libzstd 101 $(MAKE) -C test run-test CFLAGS="-O3 $(CFLAGS) $(DEBUGFLAGS) -Werror" -j 102 103.PHONY: clean 104clean: 105 $(RM) -rf linux test/test test/static_test 106