update repository
[cmdllinux.git] / kernel / config_helper / kernel_config_review.sh
blob634850499420652920c3bc1b04b43db9592f4067
1 #! /bin/bash
2 #simplified (dependency not "managed")
3 #needs review
4 #gives some automation
5 #- no "default y" lines
6 #"^[[:space:]]\+bool\|^[[:space:]]\+tristate\|^[[:space:]]\+depends[[:space:]]\+on\|^[[:space:]]\+select\|^[[:space:]]\+---help---\|^[[:space:]]\+help\|^[[:space:]]\+default\|^[[:space:]]\+int"
8 CFG=.config
9 [ "$1" = "-c" ] && cp .config .config.new && CFG=.config.new
11 grep_key_conf_elements()
13 ##find -name "Kconfig" | xargs grep -n -B 1 "tristate[[:space:]]\+['\"].*(EXPERIMENTAL).*['\"]\|bool[[:space:]]\+['\"].*(EXPERIMENTAL).*['\"]\|int[[:space:]]\+['\"].*(EXPERIMENTAL).*['\"]"
14 ##find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*development.*['\"]\|bool[[:space:]]\+['\"].*development.*['\"]\|int[[:space:]]\+['\"].*development.*['\"]"
15 TMPVAR=`find -name "Kconfig" | xargs grep -n -B 1 "tristate[[:space:]]\+['\"].*(DANGEROUS).*['\"]\|bool[[:space:]]\+['\"].*(DANGEROUS).*['\"]\|int[[:space:]]\+['\"].*(DANGEROUS).*['\"]"`
16 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
17 TMPVAR=`find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*experimental.*['\"]\|bool[[:space:]]\+['\"].*experimental.*['\"]\|int[[:space:]]\+['\"].*experimental.*['\"]"`
18 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
19 TMPVAR=`find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*obsolete.*['\"]\|bool[[:space:]]\+['\"].*obsolete.*['\"]\|int[[:space:]]\+['\"].*obsolete.*['\"]"`
20 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
21 TMPVAR=`find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*deprecated.*['\"]\|bool[[:space:]]\+['\"].*deprecated.*['\"]\|int[[:space:]]\+['\"].*deprecated.*['\"]"`
22 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
23 TMPVAR=`find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*debug.*['\"]\|bool[[:space:]]\+['\"].*debug.*['\"]\|int[[:space:]]\+['\"].*debug.*['\"]"`
24 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
25 TMPVAR=`find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*(DEVELOPMENT).*['\"]\|bool[[:space:]]\+['\"].*(DEVELOPMENT).*['\"]\|int[[:space:]]\+['\"].*(DEVELOPMENT).*['\"]"`
26 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
27 TMPVAR=`find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*for testing.*['\"]\|bool[[:space:]]\+['\"].*for testing.*['\"]\|int[[:space:]]\+['\"].*for testing.*['\"]"`
28 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
29 TMPVAR=`find -name "Kconfig" | xargs grep -i -n -B 1 "tristate[[:space:]]\+['\"].*(unsafe).*['\"]\|bool[[:space:]]\+['\"].*(unsafe).*['\"]\|int[[:space:]]\+['\"].*(unsafe).*['\"]"`
30 [ ! -z "$TMPVAR" ] && echo -ne "$TMPVAR\n--\n"
33 rework_key_conf_elements()
35 local NUM=0
36 local line line1 line2
37 grep_key_conf_elements | \
38 while read line; do
39 case "$line" in
40 --)
41 NUM=0
42 if echo "$line1" | grep -qv "/Kconfig-[0-9]*-config\|/Kconfig-[0-9]*-menuconfig"; then
43 F_NUM=2
44 while line11=`head -n $N_LINE $F_LINE | tail -n $F_NUM | head -n 1 | grep -v "^[[:space:]]*config[[:space:]]\+\|^[[:space:]]*menuconfig[[:space:]]\+"`; do
45 F_NUM=$(expr $F_NUM + 1)
46 done
47 sed -n "$(expr $N_LINE - $F_NUM + 1)p" $F_LINE 1>&2
48 else
49 sed -n "$(expr $N_LINE - 1)p" $F_LINE 1>&2
53 NUM=$(expr $NUM + 1)
54 if [ "$NUM" = 1 ]; then
55 line1="$line"
57 if [ "$NUM" = 2 ]; then
58 line2="$line"
59 N_LINE=$(echo "$line2"| cut -d : -f 2)
60 F_LINE=$(echo "$line2"| cut -d : -f 1)
61 echo $line2
64 esac
65 done
68 echo -n > /tmp/file
69 #echo "Grepping info section..."
70 (rework_key_conf_elements > /dev/null) 2>&1 | \
71 while read c config; do
72 echo "$config" >> /tmp/file
73 # echo "$config" | tee -a /tmp/file
74 done
76 cat /tmp/file | \
77 while read config; do
78 echo "$config"
79 find -type f -name "Kconfig" | xargs -r grep -n "[[:space:]]\+[!(]*$config[=)]*[[:space:]]\+\|[[:space:]]\+[!(]*$config[=)]*$"
80 done | \
81 grep -v "^\./.*/Kconfig:[0-9]\+:config[[:space:]]\+\|\./.*/Kconfig:[0-9]\+:menuconfig[[:space:]]\+" | \
82 while read line; do
83 case "$line" in
84 ./*)
85 echo "$CFG_VAR $line"
88 CFG_VAR="$line"
90 esac
91 done | \
92 while read line; do
93 CFG_VAR=$(echo "$line" | cut -d ' ' -f 1)
94 TMPVAR=$(echo "$line" | cut -d ' ' -f 2)
95 FILE=$(echo "$TMPVAR" | cut -d ':' -f 1)
96 NUM=$(echo "$TMPVAR" | cut -d ':' -f 2)
98 LINE=`sed -n "${NUM}p" "$FILE"`
99 LINE=`echo "$LINE" | sed -e 's/(/ /g' -e 's/)/ /g' -e 's/!/ /g' -e 's/=/ /'`
100 ! echo "$LINE" | grep -q "[[:space:]]\+$CFG_VAR[[:space:]]\+\|[[:space:]]\+$CFG_VAR$" && continue
102 if sed -n "${NUM}p" "$FILE" | grep -q "^[[:space:]]\+depends[[:space:]]\+on\|^[[:space:]]\+select[[:space:]]\+"; then
103 if [ "$NUM" -gt 1 ]; then
104 ANUM=$(expr $NUM - 1)
105 while sed -n "${ANUM}p" "$FILE" | grep -qv "^config[[:space:]]\+\|^menuconfig[[:space:]]\+"; do
106 [ "$ANUM" -eq 1 ] && break
107 ANUM=$(expr $ANUM - 1)
108 done
109 LINE=$(sed -n "${ANUM}p" "$FILE")
110 #echo "$CFG_VAR $LINE"
111 echo "$LINE" | sed -e 's/^config[[:space:]]\+//' -e 's/^menuconfig[[:space:]]\+//' >> /tmp/file
113 else
114 if [ "$NUM" -gt 1 ]; then
115 ANUM=$(expr $NUM - 1)
116 while sed -n "${ANUM}p" "$FILE" | grep -q '\\$'; do
117 [ "$ANUM" -eq 1 ] && break
118 ANUM=$(expr $ANUM - 1)
119 done
120 if sed -n "${ANUM}p" "$FILE" | grep -q "^[[:space:]]\+depends[[:space:]]\+on\|^[[:space:]]\+select[[:space:]]\+"; then
121 if [ "$ANUM" -gt 1 ]; then
122 ANUM=$(expr $ANUM - 1)
123 while sed -n "${ANUM}p" "$FILE" | grep -qv "^config[[:space:]]\+\|^menuconfig[[:space:]]\+"; do
124 [ "$ANUM" -eq 1 ] && break
125 ANUM=$(expr $ANUM - 1)
126 done
127 LINE=$(sed -n "${ANUM}p" "$FILE")
128 #echo "$CFG_VAR $LINE"
129 echo "$LINE" | sed -e 's/^config[[:space:]]\+//' -e 's/^menuconfig[[:space:]]\+//' >> /tmp/file
134 done
135 sort -u /tmp/file > /tmp/file.tmp
136 mv /tmp/file.tmp /tmp/file
137 cat /tmp/file | \
138 while read config; do
139 find -type f -name "Kconfig" | xargs -r grep -n "^config[[:space:]]\+${config}$\|^menuconfig[[:space:]]\+${config}$"
140 done | \
141 while read line; do
142 FILE=`echo "$line" | cut -d : -f 1`
143 NUM=`echo "$line" | cut -d : -f 2`
144 bash /bin/_find_file_section.sh -s -z -n -1 -2 "$FILE" "$NUM" "^comment\|^if\|^config\|^endif\|^choice\|^endchoice\|^endmenu\|^menuconfig\|^source\|^#"
145 done