]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/source-maintenance.sh
Merged from parent (trunk r11623, v3.2.0.10+).
[thirdparty/squid.git] / scripts / source-maintenance.sh
1 #!/bin/sh
2 #
3 # This script contains the code run to perform automatic source maintenance
4 #
5
6 ## Source Code Format Enforcement
7 #
8 # A checker to recursively reformat all source files: .h .c .cc .cci
9 # using a custom astyle formatter and to use MD5 to validate that
10 # the formatter has not altered the code syntax.
11 #
12 # If code alteration takes place the process is halted for manual intervention.
13 #
14
15 # On squid-cache.org we have to use the python scripted md5sum
16 HOST=`hostname`
17 if test "$HOST" = "squid-cache.org" ; then
18 MD5="md5"
19 else
20 MD5="md5sum"
21 fi
22
23 ROOT=`bzr root`
24
25 ASVER=`astyle --version 2>&1 | grep -o -E "[0-9.]+"`
26 if test "${ASVER}" != "1.23" ; then
27 echo "Astyle version problem. You have ${ASVER} instead of 1.23";
28 else
29 echo "Found astyle ${ASVER}. Formatting..."
30 fi
31
32 srcformat ()
33 {
34 PWD=`pwd`
35 #echo "FORMAT: ${PWD}..."
36
37 for FILENAME in `ls -1`; do
38
39 case ${FILENAME} in
40
41 *.h|*.c|*.cc|*.cci)
42
43 #
44 # Code Style formatting maintenance
45 #
46 if test "${ASVER}" = "1.23"; then
47 ${ROOT}/scripts/formater.pl ${FILENAME}
48 if test -e $FILENAME -a -e "$FILENAME.astylebak"; then
49 md51=`cat $FILENAME| tr -d "\n \t\r" | $MD5`;
50 md52=`cat $FILENAME.astylebak| tr -d "\n \t\r" | $MD5`;
51
52 if test "$md51" != "$md52" ; then
53 echo "ERROR: File $PWD/$FILENAME not formating well";
54 mv $FILENAME $FILENAME.astylebad
55 mv $FILENAME.astylebak $FILENAME
56 else
57 rm -f $FILENAME.astylebak
58 fi
59 fi
60 fi
61
62 #
63 # REQUIRE config.h/squid.h as first #include
64 #
65 case ${FILENAME} in
66 *.c|*.cc)
67 FI=`grep "#include" ${FILENAME} | head -1`;
68 if test "${FI}" != "#include \"config.h\"" -a "${FI}" != "#include \"squid.h\"" ; then
69 echo "ERROR: ${PWD}/${FILENAME} does not include config.h or squid.h first!"
70 fi
71 ;;
72 *.h|*.cci)
73 FI=`grep "#include \"config.h\"" ${FILENAME}`;
74 if test "x${FI}" != "x" ; then
75 echo "ERROR: ${PWD}/${FILENAME} duplicate include of config.h"
76 fi
77 ;;
78 esac
79
80 #
81 # Scan for incorrect use of #ifdef/#ifndef
82 #
83 grep -R -E "ifn?def .*_SQUID_" ./* | grep -v -E "_H$" | while read f; do echo "PROBLEM?: ${f}"; done
84
85 #
86 # DEBUG Section list maintenance
87 #
88 grep " DEBUG: section" <${FILENAME} | sed -e 's/ \* DEBUG: //' >>${ROOT}/doc/debug-sections.tmp
89
90 #
91 # File permissions maintenance.
92 #
93 chmod 644 ${FILENAME}
94 ;;
95
96 *.pl|*.sh)
97 #
98 # File permissions maintenance.
99 #
100 chmod 755 ${FILENAME}
101 ;;
102
103 Makefile.am)
104
105 perl -i -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
106 mv ${FILENAME}.styled ${FILENAME}
107 ;;
108
109 esac
110
111 if test "$FILENAME" = "libltdl" ; then
112 :
113 elif test -d $FILENAME ; then
114 cd $FILENAME
115 srcformat ${ROOT} || exit 1
116 cd ..
117 fi
118
119 done
120 }
121
122 # Build XPROF types file from current sources
123 echo "#ifndef _PROFILER_XPROF_TYPE_H_" >${ROOT}/lib/profiler/list
124 echo "#define _PROFILER_XPROF_TYPE_H_" >>${ROOT}/lib/profiler/list
125 echo "/* AUTO-GENERATED FILE */" >>${ROOT}/lib/profiler/list
126 echo "#if USE_XPROF_STATS" >>${ROOT}/lib/profiler/list
127 echo "typedef enum {" >>${ROOT}/lib/profiler/list
128 echo "XPROF_PROF_UNACCOUNTED," >>${ROOT}/lib/profiler/list
129 grep -R -h "PROF_start.*" ./* | grep -v probename | sed -e 's/ //g; s/PROF_start(/XPROF_/; s/);/,/' | sort -u >>${ROOT}/lib/profiler/list
130 echo " XPROF_LAST } xprof_type;" >>${ROOT}/lib/profiler/list
131 echo "#endif" >>${ROOT}/lib/profiler/list
132 echo "#endif" >>${ROOT}/lib/profiler/list
133 mv ${ROOT}/lib/profiler/list ${ROOT}/lib/profiler/xprof_type.h
134
135 # Build icons install include from current icons available
136 (
137 echo -n "ICONS="
138 for f in `ls -1 ${ROOT}/icons/silk/*`
139 do
140 echo " \\"
141 echo -n " ${f}"
142 done
143 echo " "
144 )| sed s%${ROOT}/icons/%%g >${ROOT}/icons/list
145
146 # Build templates install include from current templates available
147 (
148 echo -n "ERROR_TEMPLATES="
149 for f in `ls -1 ${ROOT}/errors/templates/ERR_*`
150 do
151 echo " \\"
152 echo -n " ${f}"
153 done
154 echo " "
155 )| sed s%${ROOT}/errors/%%g >${ROOT}/errors/template.list
156
157 # Build errors translation install include from current .PO available
158 (
159 echo -n "TRANSLATE_LANGUAGES="
160 for f in `ls -1 ${ROOT}/errors/*.po`
161 do
162 echo " \\"
163 echo -n " ${f}"
164 done
165 echo " "
166 )| sed s%${ROOT}/errors/%%g | sed s%\.po%\.lang%g >${ROOT}/errors/language.list
167
168 # Build manuals translation install include from current .PO available
169 (
170 echo -n "TRANSLATE_LANGUAGES="
171 for f in `ls -1 ${ROOT}/doc/manuals/*.po`
172 do
173 echo " \\"
174 echo -n " ${f}"
175 done
176 echo " "
177 )| sed s%${ROOT}/doc/manuals/%%g | sed s%\.po%\.lang%g >${ROOT}/doc/manuals/language.list
178
179 # Run formating
180 echo "" >${ROOT}/doc/debug-sections.tmp
181 srcformat || exit 1
182 sort -u <${ROOT}/doc/debug-sections.tmp | sort -n >${ROOT}/doc/debug-sections.txt
183 rm ${ROOT}/doc/debug-sections.tmp