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