1 # ################################################################
2 # Copyright (c) Meta Platforms, Inc. and affiliates.
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 # ################################################################
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' \
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 \
39 -DZSTD_ADDRESS_SANITIZER=0 \
40 -DZSTD_MEMORY_SANITIZER=0 \
41 -DZSTD_DATAFLOW_SANITIZER=0 \
42 -DZSTD_COMPRESS_HEAPMODE=1 \
52 -RZSTDERRORLIB_VISIBLE= \
53 -RZSTD_FALLTHROUGH=fallthrough \
54 -DZSTD_HAVE_WEAK_SYMBOLS=0 \
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
69 LINUX ?= $(HOME)/repos/linux
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
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_*
94 DEBUGFLAGS= -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
103 $(MAKE) -C test run-test CFLAGS="-O3 $(CFLAGS) $(DEBUGFLAGS) -Werror" -j
108 $(MAKE) -C test clean