]> git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/contrib/linux-kernel/kernelize.sh
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / zstd / contrib / linux-kernel / kernelize.sh
1 #!/bin/sh
2 set -e
3
4 # Constants
5 SED_COMMANDS="commands.tmp"
6 CLANG_FORMAT="clang-format-3.9"
7 INCLUDE='include/linux/'
8 LIB='lib/zstd/'
9 SPACES=' '
10 TAB=$'\t'
11 TMP="replacements.tmp"
12
13 function prompt() {
14 while true; do
15 read -p "$1 [Y/n]" yn
16 case $yn in
17 '' ) yes='yes'; break;;
18 [Yy]* ) yes='yes'; break;;
19 [Nn]* ) yes=''; break;;
20 * ) echo "Please answer yes or no.";;
21 esac
22 done
23 }
24
25 function check_not_present() {
26 grep "$1" $INCLUDE*.h ${LIB}*.{h,c} && exit 1 || true
27 }
28
29 function check_not_present_in_file() {
30 grep "$1" "$2" && exit 1 || true
31 }
32
33 function check_present_in_file() {
34 grep "$1" "$2" > /dev/null 2> /dev/null || exit 1
35 }
36
37 echo "Files: " $INCLUDE*.h $LIB*.{h,c}
38
39 prompt "Do you wish to replace 4 spaces with a tab?"
40 if [ ! -z "$yes" ]
41 then
42 # Check files for existing tabs
43 grep "$TAB" $INCLUDE*.h $LIB*.{h,c} && exit 1 || true
44 # Replace the first tab on every line
45 sed -i '' "s/^$SPACES/$TAB/" $INCLUDE*.h $LIB*.{h,c}
46
47 # Execute once and then execute as long as replacements are happening
48 more_work="yes"
49 while [ ! -z "$more_work" ]
50 do
51 rm -f $TMP
52 # Replaces $SPACES that directly follow a $TAB with a $TAB.
53 # $TMP will be non-empty if any replacements took place.
54 sed -i '' "s/$TAB$SPACES/$TAB$TAB/w $TMP" $INCLUDE*.h $LIB*.{h,c}
55 more_work=$(cat "$TMP")
56 done
57 rm -f $TMP
58 fi
59
60 prompt "Do you wish to replace '{ ' with a tab?"
61 if [ ! -z "$yes" ]
62 then
63 sed -i '' "s/$TAB{ /$TAB{$TAB/g" $INCLUDE*.h $LIB*.{h,c}
64 fi
65
66 rm -f $SED_COMMANDS
67 cat > $SED_COMMANDS <<EOF
68 s/current/curr/g
69 s/MEM_STATIC/ZSTD_STATIC/g
70 s/MEM_check/ZSTD_check/g
71 s/MEM_32bits/ZSTD_32bits/g
72 s/MEM_64bits/ZSTD_64bits/g
73 s/MEM_LITTLE_ENDIAN/ZSTD_LITTLE_ENDIAN/g
74 s/MEM_isLittleEndian/ZSTD_isLittleEndian/g
75 s/MEM_read/ZSTD_read/g
76 s/MEM_write/ZSTD_write/g
77 EOF
78
79 prompt "Do you wish to run these sed commands $(cat $SED_COMMANDS)?"
80 if [ ! -z "$yes" ]
81 then
82 sed -i '' -f $SED_COMMANDS $LIB*.{h,c}
83 fi
84 rm -f $SED_COMMANDS
85
86 prompt "Do you wish to clang-format $LIB*.{h,c}?"
87 if [ ! -z "$yes" ]
88 then
89 $CLANG_FORMAT -i ${LIB}*.{h,c}
90 fi
91
92 prompt "Do you wish to run some checks?"
93 if [ ! -z "$yes" ]
94 then
95 check_present_in_file ZSTD_STATIC_ASSERT ${LIB}zstd_internal.h
96 check_not_present_in_file STATIC_ASSERT ${LIB}mem.h
97 check_not_present_in_file "#define ZSTD_STATIC_ASSERT" ${LIB}compress.c
98 check_not_present MEM_STATIC
99 check_not_present FSE_COMMONDEFS_ONLY
100 check_not_present "#if 0"
101 check_not_present "#if 1"
102 check_not_present _MSC_VER
103 check_not_present __cplusplus
104 check_not_present __STDC_VERSION__
105 check_not_present __VMS
106 check_not_present __GNUC__
107 check_not_present __INTEL_COMPILER
108 check_not_present FORCE_MEMORY_ACCESS
109 check_not_present STATIC_LINKING_ONLY
110 fi